-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendHelper.js
More file actions
48 lines (40 loc) · 1.26 KB
/
sendHelper.js
File metadata and controls
48 lines (40 loc) · 1.26 KB
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
//发送消息
var request = require("request");
//post请求
var postData={
type:config.sendType.txt,
msg:'',
to_wxid:'',
robot_wxid:config.robot_wxid
};
var sendHelper = {
myPost:function(type,to_wxid,txt){
return new Promise((resolve, reject)=>{
postData.type = type;
postData.to_wxid = to_wxid;
postData.msg = encodeURIComponent(txt);
request({
url: config.sendUrl,//请求路径
method: "POST",//请求方式,默认为get
headers: {//设置请求头
"content-type": "application/json",
},
body: JSON.stringify(postData)//post参数字符串
}, function(error, response, body) {
// console.log(body);
if (!error && response.statusCode == 200) {
resolve(true);
}else{
resolve(false);
}
});
})
},
sendTxt:function(to_wxid,txt){
return sendHelper.myPost(config.sendType.txt,to_wxid,txt);
},
sendImg:function(to_wxid,img){
return sendHelper.myPost(config.sendType.image,to_wxid,img);
},
};
module.exports = sendHelper;