Skip to content

Instantly share code, notes, and snippets.

@banyudu
Created April 8, 2021 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banyudu/f9668dbf6840b10ad7d25461b978c302 to your computer and use it in GitHub Desktop.
Save banyudu/f9668dbf6840b10ad7d25461b978c302 to your computer and use it in GitHub Desktop.
企业微信发送图片
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