| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /**
- * 企业微信机器人推送(Markdown 文字 + 图片)
- * 运行环境:青龙 Node.js
- */
- const axios = require('axios');
- const crypto = require('crypto');
- // ======= 配置区 =======
- const WEBHOOK_URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=795d0b1e-20e9-40ab-979c-a5752cd2de67'; // 机器人Webhook
- const TEXT_CONTENT = '## 温馨提示:\n\n 预算创建时,🔴 **预算模板**需勾选,⚙️ **取费标准**需勾选。📝 请确保所有选项正确设置。\n\n请参考下方图片 👇 可点击放大';
- const IMAGE_URL = 'https://p.sda1.dev/27/ddc36bcbf0ebe6c136ca363be580ac93/PixPin_2025-09-16_12-04-46.png'; // 图片URL
- // =====================
- // 发送Markdown格式的消息
- async function sendMarkdown(text) {
- try {
- const payload = {
- msgtype: 'markdown',
- markdown: {
- content: text,
- }
- };
- const res = await axios.post(WEBHOOK_URL, payload);
- console.log('Markdown文字推送结果:', res.data);
- } catch (err) {
- console.error('Markdown文字推送失败:', err);
- }
- }
- // 发送图片消息(支持网络URL)
- async function sendImage(imageUrl) {
- try {
- const res = await axios.get(imageUrl, { responseType: 'arraybuffer' });
- const imgData = Buffer.from(res.data);
- const base64Img = imgData.toString('base64');
- const md5 = crypto.createHash('md5').update(imgData).digest('hex');
- const payload = {
- msgtype: 'image',
- image: {
- base64: base64Img,
- md5: md5
- }
- };
- const response = await axios.post(WEBHOOK_URL, payload);
- console.log('图片推送结果:', response.data);
- } catch (err) {
- console.error('图片推送失败:', err);
- }
- }
- // 主函数
- (async () => {
- await sendMarkdown(TEXT_CONTENT); // 发送Markdown格式的文字
- await sendImage(IMAGE_URL); // 发送图片
- })();
|