Created
April 8, 2021 08:35
-
-
Save banyudu/f9668dbf6840b10ad7d25461b978c302 to your computer and use it in GitHub Desktop.
企业微信发送图片
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios').default | |
const textToImage = require('text-to-image'); | |
const crypto = require('crypto') | |
const text = process.argv[2] || 'Hello World!' | |
const md5= (str) => crypto.createHash('md5').update(str).digest('hex'); | |
const botUrl = process.env.TEST_BOT_URL | |
const test = async () => { | |
const dataUrl = await textToImage.generate(text) | |
const byteString = dataUrl.substr(dataUrl.indexOf(',') + 1) | |
const buffer = Buffer.from(byteString, 'base64') | |
const md5Str = md5(buffer) | |
const res = await axios.post(botUrl, { | |
msgtype: 'image', | |
image: { | |
base64: byteString, | |
md5: md5Str | |
} | |
}, { | |
responseType: 'blob' | |
}) | |
console.log('res is: ', res.data) | |
} | |
test().catch(err => { | |
console.error(err) | |
process.exit(1) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment