-
Notifications
You must be signed in to change notification settings - Fork 0
/
postMenu.js
106 lines (80 loc) · 1.68 KB
/
postMenu.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
var https = require("https");
var fs = require("fs");
var needle = require("needle");
var ACCESS_TOKEN = "cnwr7SYmcWB8NHop80NjsgbvewJQaweqvN8ooms26JdfSMFU8iVia7WChZ_7nfOVLloSUo7FIj4sZSGQYJH5JVu77tNy5zX7azkYt69UHqo";
var filePath = "custMenu.json";
var jsonStr = fs.readFileSync(filePath,"utf-8");
/*
var menu = {
"button":[
{
"name":"video",
"sub_button":[
{
"type":"view",
"name":"QQ",
"url":"http://3g.v.qq.com"
},
{
"type":"view",
"name":"Youku",
"url":"http://www.youku.com"
}
]
},
{
"name":"Dev",
"sub_button":[
{
"type":"view",
"name":"Transform",
"url":"http://115.159.31.94:8000/transform.html"
},
{
"type":"view",
"name":"QQ",
"url":"http://www.qq.com"
},
{
"type":"view",
"name":"sina",
"url":"http://www.sina.com.cn"
}
]
}
]
};
var param = JSON.stringify(menu);
var options = {};
var url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + ACCESS_TOKEN;
needle.post(url,param,options,function(err,res){
console.log("Set Menu!");
console.log(res.body);
});
*/
var headers = {
"Content-Type":"application/json",
"Content-Length":jsonStr.length
};
var options = {
host:"api.weixin.qq.com",
path:"/cgi-bin/menu/create?access_token=" + ACCESS_TOKEN,
method:"POST",
headers:headers
};
var req = https.request(options,function(res){
res.setEncoding("utf-8");
var responseString = "";
res.on("data",function(chunk){
responseString += chunk;
});
res.on("end",function(){
var resultObject = JSON.parse(responseString);
console.log("-----resBody-----",resultObject);
});
res.on("error",function(e){
console.log("-----resError-----",e);
});
});
req.write(jsonStr);
req.end();