-
Notifications
You must be signed in to change notification settings - Fork 567
/
sendmsg.js
186 lines (170 loc) · 6.4 KB
/
sendmsg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
const axios = require("axios");
const {qywx,tgpushkey,qmsgkey,sckey,pushplustoken,vocechat}=config.Push
const {corpsecret,corpid,agentid,mediaid} = qywx
const {tgbotoken,chatid} = tgpushkey
const {api,uid,key} = vocechat ||{}
async function sendmsg(text, isMarkdown=false) {
console.log(text)
if(sckey) await server(text);
if(qmsgkey) await qmsg(text);
if(pushplustoken) await pushplus(text);
if(corpsecret) await wx(text);
if(tgbotoken) await tgpush(text)
if(vocechat&&api)await vocechatP(text, true)
}
function server(msg) {
return new Promise(async (resolve) => {
try {
let url = `https://sctapi.ftqq.com/${sckey}.send`
let data = `title=${encodeURI("签到盒每日任务已完成")}&desp=${encodeURI(msg.replace(/\n/g,"\n\n"))}`
let res = await axios.post(url, data)
if (res.data.code == 0) {
console.log("server酱:发送成功");
} else {
console.log("server酱:发送失败");
console.log(res.data.info);
}
} catch (err) {
console.log("server酱:发送接口调用失败");
// console.log(err.response.data.message);
}
resolve();
});
}
function vocechatP(msg, isMarkdown=false) {
return new Promise(async (resolve) => {
try {
let url = `${api}/api/bot/send_to_user/${uid}`;
let headers = {
'x-api-key': key,
'Content-Type': isMarkdown ? 'text/markdown' : 'text/plain',
};
let res = await axios.post(url, msg.replace(/\n/g,`
`).replace(/【|】/g,"**"), { headers });
if (res.data) {
console.log("Vocechat: 发送成功");
} else {
console.log("Vocechat: 发送失败");
console.log(res.data);
}
} catch (err) {
console.log("Vocechat: 发送接口调用失败");
console.log(err);
}
resolve();
});
}
function pushplus(msg) {
return new Promise(async (resolve) => {
try {
let url = "http://www.pushplus.plus/send"
let data = {
"token": pushplustoken,
"title": "签到盒每日任务已完成-",
"content": msg.replace(/\n/g,"<br>"),
"temple": "html"
}
let res = await axios.post(url, data, {
headers: {
"Content-Type": "application/json"
}
})
if (res.data.code == 200) {
console.log("pushplus:发送成功");
} else {
console.log("pushplus:发送失败");
console.log(res.data.msg);
}
} catch (err) {
console.log("pushplus酱:发送接口调用失败");
console.log(err);
}
resolve();
});
}
function qmsg(msg) {
return new Promise(async (resolve) => {
try {
url = `https://qmsg.zendee.cn/send/${qmsgkey}`;
res = await axios.post(url, `msg=${encodeURI(msg)}`);
if (res.data.success) {
console.log("qmsg酱:发送成功");
} else {
console.log("qmsg酱:发送失败 "+res.data.resson);
}
} catch (err) {
console.log("qmsg酱:发送接口调用失败");
console.log(err);
}
resolve();
});
}
function tgpush(msg) {
return new Promise(async (resolve) => {
try {
// let url = "https://api.telegram.org/bot${tgbotoken}/sendMessage";
// let data=`parse_mode=Markdown&text=${msg.replace(/\n/g,"%0A").replace(/【|】/g,"*")}&chat_id=${chatid}`
let url=`https://tg-bot.0x23.cf/bot${tgbotoken}/sendMessage?parse_mode=Markdown&text=${encodeURI(msg.replace(/【|】/g,"*"))}&chat_id=${chatid}`
// let res = await axios.post(url,data);
let res = await axios.get(url);
if (res.data.ok) {
console.log("Tg:发送成功");
} else {
console.log("Tg:发送失败!");
console.log(res.data);
} } catch (err) {
// console.log(err);
}
resolve();
});
}
function wx(msg) {
return new Promise(async (resolve) => {
try {
let url = `https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${corpid}&corpsecret=${corpsecret}`
let res = await axios.get(url)
access_token = res.data.access_token
let turl = `https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${access_token}`
let text = {
"touser": "@all",
"msgtype": "text",
"agentid": agentid?agentid:1000002,
"text": {
"content": msg
},
"safe": 0
}
let mpnews = {
"touser": "@all",
"msgtype": "mpnews",
"agentid": agentid?agentid:1000002,
"mpnews": {
"articles":[
{
"title": "签到盒每日任务已完成",
"thumb_media_id": mediaid?mediaid:"",
"author": "wenmoux",
"content_source_url": "",
"content": msg.replace(/\n/g,"<br>"),
"digest": msg
}
]
},
"safe": 0}
let data =mediaid?mpnews:text
let tres = await axios.post(turl,data)
if (tres.data.errcode == 0) {
console.log("企业微信:发送成功");
} else {
console.log("企业微信:发送失败");
console.log(tres.data.errmsg);
}
} catch (err) {
console.log("企业微信:发送接口调用失败");
console.log(err);
}
resolve();
});
}
module.exports = sendmsg