diff --git a/sendNotify.js b/sendNotify.js index b23e2e12..47079790 100644 --- a/sendNotify.js +++ b/sendNotify.js @@ -50,6 +50,7 @@ let QYWX_KEY = ''; // =======================================企业微信应用消息通知设置区域=========================================== //此处填你企业微信应用消息的 值(详见文档 https://work.weixin.qq.com/api/doc/90000/90135/90236),依次填上corpid的值,corpsecret的值,touser的值,agentid的值,素材库图片id(见https://github.com/lxk0301/jd_scripts/issues/519) 注意用,号隔开,例如:wwcff56746d9adwers,B-791548lnzXBE6_BWfxdf3kSTMJr9vFEPKAbh6WERQ,mingcheng,1000001,2COXgjH2UIfERF2zxrtUOKgQ9XklUqMdGSWLBoW_lSDAdafat +//增加一个选择推送消息类型,用图文消息直接填写素材库图片id的值,用卡片消息就填写0(就是数字零) //注:此处设置github action用户填写到Settings-Secrets里面(Name输入QYWX_AM) let QYWX_AM = ''; @@ -423,31 +424,48 @@ function qywxBotNotify(text, desp) { function qywxamNotify(text, desp) { return new Promise(resolve => { if (QYWX_AM) { - var QYWX_AM_AY = QYWX_AM.split(','); - const options_accesstoken = { - url: `https://qyapi.weixin.qq.com/cgi-bin/gettoken`, - json: { - corpid:`${QYWX_AM_AY[0]}`, - corpsecret:`${QYWX_AM_AY[1]}`, - }, - headers: { - 'Content-Type': 'application/json', - }, - }; - $.post(options_accesstoken, (err, resp, data) => { - html=desp.replace(/\n/g,"
") + var QYWX_AM_AY = QYWX_AM.split(','); + const options_accesstoken = { + url: `https://qyapi.weixin.qq.com/cgi-bin/gettoken`, + json: { + corpid:`${QYWX_AM_AY[0]}`, + corpsecret:`${QYWX_AM_AY[1]}`, + }, + headers: { + 'Content-Type': 'application/json', + }, + }; + $.post(options_accesstoken, (err, resp, data) => { + html=desp.replace(/\n/g,"
") var json = JSON.parse(data); accesstoken = json.access_token; - const options = { - url: `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${accesstoken}`, - json: { - touser:`${QYWX_AM_AY[2]}`, - agentid:`${QYWX_AM_AY[3]}`, - msgtype: 'mpnews', - mpnews: { + const options_textcard = { + url: `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${accesstoken}`, + json: { + touser:`${QYWX_AM_AY[2]}`, + agentid:`${QYWX_AM_AY[3]}`, + msgtype: 'textcard', + textcard: { + title: `${text}`, + description: `${desp}`, + url: '127.0.0.1', + }, + safe:'0', + }, + headers: { + 'Content-Type': 'application/json', + }, + }; + const options_mpnews = { + url: `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${accesstoken}`, + json: { + touser:`${QYWX_AM_AY[2]}`, + agentid:`${QYWX_AM_AY[3]}`, + msgtype: 'mpnews', + mpnews: { articles: [ { - title: `${text}`, + title: `${text}`, thumb_media_id: `${QYWX_AM_AY[4]}`, author : `智能助手` , content_source_url: ``, @@ -455,14 +473,14 @@ function qywxamNotify(text, desp) { digest: `${desp}` } ] - }, - safe:'0', - }, - headers: { - 'Content-Type': 'application/json', - }, - }; - $.post(options, (err, resp, data) => { + }, + safe:'0', + }, + headers: { + 'Content-Type': 'application/json', + }, + }; + $.post((QYWX_AM_AY[4]==0)?options_textcard:options_mpnews, (err, resp, data) => { try { if (err) { console.log('企业微信应用消息发送通知消息失败!!\n');