update企业微信应用消息 (QYWX_AM)
- 增加纯文本消息通知选项 - 修改错误的doc
This commit is contained in:
@ -47,9 +47,13 @@ let DD_BOT_SECRET = '';
|
||||
let QYWX_KEY = '';
|
||||
|
||||
// =======================================企业微信应用消息通知设置区域===========================================
|
||||
//此处填你企业微信应用消息的 值(详见文档 https://work.weixin.qq.com/api/doc/90000/90135/90236),依次填上corpid的值,corpsecret的值,touser的值,agentid的值,素材库图片id(见https://github.com/LXK9301/jd_scripts/issues/519) 注意用,号隔开,例如:wwcff56746d9adwers,B-791548lnzXBE6_BWfxdf3kSTMJr9vFEPKAbh6WERQ,mingcheng,1000001,2COXgjH2UIfERF2zxrtUOKgQ9XklUqMdGSWLBoW_lSDAdafat
|
||||
//corpid的值,corpsecret的值,touser的值,agentid的值,素材库图片id的获取,可查看此教程(http://note.youdao.com/s/HMiudGkb)
|
||||
//增加一个选择推送消息类型,用图文消息直接填写素材库图片id的值,用卡片消息就填写0(就是数字零)
|
||||
//此处填你企业微信应用消息的值(详见文档 https://work.weixin.qq.com/api/doc/90000/90135/90236)
|
||||
//依次填入 corpid,corpsecret,touser,agentid,消息类型
|
||||
//注意用,号隔开(英文输入法的逗号),例如:wwcff56746d9adwers,B-791548lnzXBE6_BWfxdf3kSTMJr9vFEPKAbh6WERQ,mingcheng,1000001,2COXgjH2UIfERF2zxrtUOKgQ9XklUqMdGSWLBoW_lSDAdafat
|
||||
//可选推送消息类型:
|
||||
// - 卡片消息: 0 (数字零)
|
||||
// - 文字消息: 1 (数字一)
|
||||
// - 图文消息: 素材库图片id, 可查看此教程(http://note.youdao.com/s/HMiudGkb)
|
||||
//(环境变量名 QYWX_AM)
|
||||
let QYWX_AM = '';
|
||||
|
||||
@ -476,49 +480,62 @@ function qywxamNotify(text, desp) {
|
||||
html=desp.replace(/\n/g,"<br/>")
|
||||
var json = JSON.parse(data);
|
||||
accesstoken = json.access_token;
|
||||
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',
|
||||
btntxt: '更多'
|
||||
},
|
||||
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}`,
|
||||
let options;
|
||||
|
||||
switch (QYWX_AM_AY[4]) {
|
||||
case '0':
|
||||
options = {
|
||||
msgtype: 'textcard',
|
||||
textcard: {
|
||||
title: `${text}`,
|
||||
description: `${desp}`,
|
||||
url: '127.0.0.1',
|
||||
btntxt: '更多'
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case '1':
|
||||
options = {
|
||||
msgtype: 'text',
|
||||
text: {
|
||||
content: `${text}\n\n${desp}`
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
options = {
|
||||
msgtype: 'mpnews',
|
||||
mpnews: {
|
||||
articles: [
|
||||
{
|
||||
title: `${text}`,
|
||||
thumb_media_id: `${QYWX_AM_AY[4]}`,
|
||||
author : `智能助手` ,
|
||||
content_source_url: ``,
|
||||
content : `${html}`,
|
||||
digest: `${desp}`
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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]}`,
|
||||
safe:'0',
|
||||
...options
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
};
|
||||
$.post((QYWX_AM_AY[4]==0)?options_textcard:options_mpnews, (err, resp, data) => {
|
||||
}
|
||||
|
||||
$.post(options, (err, resp, data) => {
|
||||
try {
|
||||
if (err) {
|
||||
console.log('企业微信应用消息发送通知消息失败!!\n');
|
||||
|
Reference in New Issue
Block a user