企业微信应用通知,可根据用户ID顺序进行一对一推送(兼容之前设置的用户ID)
This commit is contained in:
@ -24,7 +24,7 @@
|
||||
| `TG_USER_ID` | telegram推送 | 非必须 | tg推送(需设备可连接外网),`TG_BOT_TOKEN`和`TG_USER_ID`两者必需,填写[@getuseridbot](https://t.me/getuseridbot)中获取到的纯数字ID, [具体教程](./backUp/TG_PUSH.md) |
|
||||
| `DD_BOT_TOKEN` | 钉钉推送 | 非必须 | 钉钉推送(`DD_BOT_TOKEN`和`DD_BOT_SECRET`两者必需)[官方文档](https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq) ,只需`https://oapi.dingtalk.com/robot/send?access_token=XXX` 等于`=`符号后面的XXX即可 |
|
||||
| `DD_BOT_SECRET` | 钉钉推送 | 非必须 | (`DD_BOT_TOKEN`和`DD_BOT_SECRET`两者必需) ,密钥,机器人安全设置页面,加签一栏下面显示的SEC开头的`SECXXXXXXXXXX`等字符 , 注:钉钉机器人安全设置只需勾选`加签`即可,其他选项不要勾选,再不懂看 [这个图](icon/DD_bot.png) |
|
||||
| `QYWX_KEY` | 企业微信推送 | 非必须 | 密钥,企业微信推送 webhook 后面的 key [详见官方说明文档](https://work.weixin.qq.com/api/doc/90000/90136/91770) |
|
||||
| `QYWX_KEY` | 企业微信机器人推送 | 非必须 | 密钥,企业微信推送 webhook 后面的 key [详见官方说明文档](https://work.weixin.qq.com/api/doc/90000/90136/91770) |
|
||||
| `QYWX_AM` | 企业微信应用消息推送 | 非必须 | corpid,corpsecret,touser,agentid,素材库图片id [参考文档](http://note.youdao.com/s/HMiudGkb)<br>素材库图片填0为图文消息, 填1为纯文本消息 |
|
||||
| `IGOT_PUSH_KEY` | iGot推送 | 非必须 | iGot聚合推送,支持多方式推送,确保消息可达。 [参考文档](https://wahao.github.io/Bark-MP-helper ) |
|
||||
| `PUSH_PLUS_TOKEN` | pushplus推送 | 非必须 | 微信扫码登录后一对一推送或一对多推送下面的token(您的Token) [官方网站](http://pushplus.hxtrip.com/) |
|
||||
|
168
sendNotify.js
168
sendNotify.js
@ -463,98 +463,118 @@ function qywxBotNotify(text, desp) {
|
||||
});
|
||||
}
|
||||
|
||||
function ChangeUserId(desp) {
|
||||
const QYWX_AM_AY = QYWX_AM.split(',');
|
||||
if (QYWX_AM_AY[2]) {
|
||||
const userIdTmp = QYWX_AM_AY[2].split("|");
|
||||
let userId = "";
|
||||
for (let i = 0; i < userIdTmp.length; i++) {
|
||||
const count = "账号" + (i + 1);
|
||||
const count2 = "签到号 " + (i + 1);
|
||||
if (desp.match(count) || desp.match(count2)) {
|
||||
userId = userIdTmp[i];
|
||||
}
|
||||
}
|
||||
if (!userId) userId = QYWX_AM_AY[2];
|
||||
return userId;
|
||||
} else {
|
||||
return "@all";
|
||||
}
|
||||
}
|
||||
|
||||
function qywxamNotify(text, desp) {
|
||||
return new Promise(resolve => {
|
||||
if (QYWX_AM) {
|
||||
var QYWX_AM_AY = QYWX_AM.split(',');
|
||||
const 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]}`,
|
||||
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,"<br/>")
|
||||
var json = JSON.parse(data);
|
||||
accesstoken = json.access_token;
|
||||
let options;
|
||||
$.post(options_accesstoken, (err, resp, data) => {
|
||||
html = desp.replace(/\n/g, "<br/>")
|
||||
var json = JSON.parse(data);
|
||||
accesstoken = json.access_token;
|
||||
let options;
|
||||
|
||||
switch (QYWX_AM_AY[4]) {
|
||||
case '0':
|
||||
options = {
|
||||
msgtype: 'textcard',
|
||||
textcard: {
|
||||
title: `${text}`,
|
||||
description: `${desp}`,
|
||||
url: '127.0.0.1',
|
||||
btntxt: '更多'
|
||||
switch (QYWX_AM_AY[4]) {
|
||||
case '0':
|
||||
options = {
|
||||
msgtype: 'textcard',
|
||||
textcard: {
|
||||
title: `${text}`,
|
||||
description: `${desp}`,
|
||||
url: '127.0.0.1',
|
||||
btntxt: '更多'
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case '1':
|
||||
options = {
|
||||
msgtype: 'text',
|
||||
text: {
|
||||
content: `${text}\n\n${desp}`
|
||||
case '1':
|
||||
options = {
|
||||
msgtype: 'text',
|
||||
text: {
|
||||
content: `${text}\n\n${desp}`
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
options = {
|
||||
msgtype: 'mpnews',
|
||||
mpnews: {
|
||||
articles: [
|
||||
{
|
||||
title: `${text}`,
|
||||
thumb_media_id: `${QYWX_AM_AY[4]}`,
|
||||
author : `智能助手` ,
|
||||
content_source_url: ``,
|
||||
content : `${html}`,
|
||||
digest: `${desp}`
|
||||
}
|
||||
]
|
||||
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(options, (err, resp, data) => {
|
||||
try {
|
||||
if (err) {
|
||||
console.log('企业微信应用消息发送通知消息失败!!\n');
|
||||
console.log(err);
|
||||
} else {
|
||||
data = JSON.parse(data);
|
||||
if (data.errcode === 0) {
|
||||
console.log('企业微信应用消息发送通知消息完成。\n');
|
||||
} else {
|
||||
console.log(`${data.errmsg}\n`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
$.logErr(e, resp);
|
||||
} finally {
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
;
|
||||
|
||||
options = {
|
||||
url: `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${accesstoken}`,
|
||||
json: {
|
||||
touser: `${ChangeUserId(desp)}`,
|
||||
agentid: `${QYWX_AM_AY[3]}`,
|
||||
safe: '0',
|
||||
...options
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
}
|
||||
|
||||
$.post(options, (err, resp, data) => {
|
||||
try {
|
||||
if (err) {
|
||||
console.log('成员ID:' + ChangeUserId(desp) + '企业微信应用消息发送通知消息失败!!\n');
|
||||
console.log(err);
|
||||
} else {
|
||||
data = JSON.parse(data);
|
||||
if (data.errcode === 0) {
|
||||
console.log('成员ID:' + ChangeUserId(desp) + '企业微信应用消息发送通知消息完成。\n');
|
||||
} else {
|
||||
console.log(`${data.errmsg}\n`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
$.logErr(e, resp);
|
||||
} finally {
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log('您未提供企业微信应用消息推送所需的QYWX_AM,取消企业微信应用消息推送消息通知\n');
|
||||
|
Reference in New Issue
Block a user