企业微信应用通知,可根据用户ID顺序进行一对一推送(兼容之前设置的用户ID)

This commit is contained in:
lxk0301
2021-02-20 14:10:57 +08:00
parent 0e09bbc4ba
commit 95098699cb
2 changed files with 95 additions and 75 deletions

View File

@ -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) | | `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_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) | | `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为纯文本消息 | | `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 ) | | `IGOT_PUSH_KEY` | iGot推送 | 非必须 | iGot聚合推送支持多方式推送确保消息可达。 [参考文档](https://wahao.github.io/Bark-MP-helper ) |
| `PUSH_PLUS_TOKEN` | pushplus推送 | 非必须 | 微信扫码登录后一对一推送或一对多推送下面的token(您的Token) [官方网站](http://pushplus.hxtrip.com/) | | `PUSH_PLUS_TOKEN` | pushplus推送 | 非必须 | 微信扫码登录后一对一推送或一对多推送下面的token(您的Token) [官方网站](http://pushplus.hxtrip.com/) |

View File

@ -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) { function qywxamNotify(text, desp) {
return new Promise(resolve => { return new Promise(resolve => {
if (QYWX_AM) { if (QYWX_AM) {
var QYWX_AM_AY = QYWX_AM.split(','); const QYWX_AM_AY = QYWX_AM.split(',');
const options_accesstoken = { const options_accesstoken = {
url: `https://qyapi.weixin.qq.com/cgi-bin/gettoken`, url: `https://qyapi.weixin.qq.com/cgi-bin/gettoken`,
json: { json: {
corpid:`${QYWX_AM_AY[0]}`, corpid: `${QYWX_AM_AY[0]}`,
corpsecret:`${QYWX_AM_AY[1]}`, corpsecret: `${QYWX_AM_AY[1]}`,
}, },
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
}; };
$.post(options_accesstoken, (err, resp, data) => { $.post(options_accesstoken, (err, resp, data) => {
html=desp.replace(/\n/g,"<br/>") html = desp.replace(/\n/g, "<br/>")
var json = JSON.parse(data); var json = JSON.parse(data);
accesstoken = json.access_token; accesstoken = json.access_token;
let options; let options;
switch (QYWX_AM_AY[4]) { switch (QYWX_AM_AY[4]) {
case '0': case '0':
options = { options = {
msgtype: 'textcard', msgtype: 'textcard',
textcard: { textcard: {
title: `${text}`, title: `${text}`,
description: `${desp}`, description: `${desp}`,
url: '127.0.0.1', url: '127.0.0.1',
btntxt: '更多' btntxt: '更多'
}
} }
} break;
break;
case '1': case '1':
options = { options = {
msgtype: 'text', msgtype: 'text',
text: { text: {
content: `${text}\n\n${desp}` content: `${text}\n\n${desp}`
}
} }
} break;
break;
default: default:
options = { options = {
msgtype: 'mpnews', msgtype: 'mpnews',
mpnews: { mpnews: {
articles: [ articles: [
{ {
title: `${text}`, title: `${text}`,
thumb_media_id: `${QYWX_AM_AY[4]}`, thumb_media_id: `${QYWX_AM_AY[4]}`,
author : `智能助手` , author: `智能助手`,
content_source_url: ``, content_source_url: ``,
content : `${html}`, content: `${html}`,
digest: `${desp}` 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 { } else {
console.log('您未提供企业微信应用消息推送所需的QYWX_AM取消企业微信应用消息推送消息通知\n'); console.log('您未提供企业微信应用消息推送所需的QYWX_AM取消企业微信应用消息推送消息通知\n');