-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.node.js
47 lines (44 loc) · 937 Bytes
/
app.node.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
const crypto = require("crypto");
const fetch = require("node-fetch");
function sendMsg(
secret,
dingHook,
msg,
title,
type = "text",
ats = [],
atAll = false
) {
const now = Date.now();
const sign = crypto
.createHmac("sha256", secret)
.update(now + "\n" + secret)
.digest()
.toString("base64");
return fetch(`${dingHook}×tamp=${now}&sign=${sign}`, {
headers: { "Content-Type": "application/json" },
method: "post",
body: JSON.stringify({
msgtype: type,
markdown: {
title,
text: msg,
},
text: {
content: msg,
},
at: {
atUserIds: ats,
isAtAll: atAll,
},
}),
}).then((data) => data.json());
}
sendMsg(
"SECc0xxxxx",
"https://oapi.dingtalk.com/robot/send?access_token=5ec176061631e79c6328ab44xxxxx",
"# 内容",
"标题",
"markdown"
).then(console.log);
// { errcode: 0, errmsg: 'ok' }