-
Notifications
You must be signed in to change notification settings - Fork 321
Expand file tree
/
Copy pathapi_menu.js
More file actions
169 lines (159 loc) · 4.11 KB
/
api_menu.js
File metadata and controls
169 lines (159 loc) · 4.11 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
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
'use strict';
var util = require('./util');
var wrapper = util.wrapper;
var postJSON = util.postJSON;
/**
* 创建自定义菜单
* 详细请看:http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html
*
* Menu:
* ```
* {
* "button":[
* {
* "type":"click",
* "name":"今日歌曲",
* "key":"V1001_TODAY_MUSIC"
* },
* {
* "name":"菜单",
* "sub_button":[
* {
* "type":"view",
* "name":"搜索",
* "url":"http://www.soso.com/"
* },
* {
* "type":"click",
* "name":"赞一下我们",
* "key":"V1001_GOOD"
* }]
* }]
* }
* ]
* }
* ```
* Examples:
* ```
* api.createMenu(menu, callback);
* ```
* Callback:
*
* - `err`, 调用失败时得到的异常
* - `result`, 调用正常时得到的对象
*
* Result:
* ```
* {"errcode":0,"errmsg":"ok"}
* ```
* @param {Object} menu 菜单对象
* @param {Function} callback 回调函数
*/
exports.createMenu = function (menu, callback) {
this.preRequest(this._createMenu, arguments);
};
/*!
* 创建自定义菜单的未封装版本
*/
exports._createMenu = function (menu, callback) {
var url = this.endpoint + '/cgi-bin/menu/create?access_token=' + this.token.accessToken;
this.request(url, postJSON(menu), wrapper(callback));
};
/**
* 获取菜单
* 详细请看:<http://mp.weixin.qq.com/wiki/5/f287d1a5b78a35a8884326312ac3e4ed.html>
*
* Examples:
* ```
* api.getMenu(callback);
* ```
* Callback:
*
* - `err`, 调用失败时得到的异常
* - `result`, 调用正常时得到的对象
*
* Result: (注意:如果有个性化菜单被设置,返回的结果会具有更多信息,请参考微信文档)
* ```
* // 结果示例
* {
* "menu": {
* "button":[
* {"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC","sub_button":[]},
* {"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER","sub_button":[]},
* {"name":"菜单","sub_button":[
* {"type":"view","name":"搜索","url":"http://www.soso.com/","sub_button":[]},
* {"type":"view","name":"视频","url":"http://v.qq.com/","sub_button":[]},
* {"type":"click","name":"赞一下我们","key":"V1001_GOOD","sub_button":[]}]
* }
* ]
* }
* }
* ```
* @param {Function} callback 回调函数
*/
exports.getMenu = function (callback) {
this.preRequest(this._getMenu, arguments);
};
/*!
* 获取自定义菜单的未封装版本
*/
exports._getMenu = function (callback) {
var url = this.endpoint + '/cgi-bin/menu/get?access_token=' + this.token.accessToken;
this.request(url, {dataType: 'json'}, wrapper(callback));
};
/**
* 删除自定义菜单
* 详细请看:<http://mp.weixin.qq.com/wiki/16/8ed41ba931e4845844ad6d1eeb8060c8.html>
* Examples:
* ```
* api.removeMenu(callback);
* ```
* Callback:
*
* - `err`, 调用失败时得到的异常
* - `result`, 调用正常时得到的对象
*
* Result:
* ```
* {"errcode":0,"errmsg":"ok"}
* ```
* @param {Function} callback 回调函数
*/
exports.removeMenu = function (callback) {
this.preRequest(this._removeMenu, arguments);
};
/*!
* 删除自定义菜单的未封装版本
*/
exports._removeMenu = function (callback) {
var url = this.endpoint + '/cgi-bin/menu/delete?access_token=' + this.token.accessToken;
this.request(url, {dataType: 'json'}, wrapper(callback));
};
/**
* 获取自定义菜单配置
* 详细请看:<http://mp.weixin.qq.com/wiki/17/4dc4b0514fdad7a5fbbd477aa9aab5ed.html>
* Examples:
* ```
* api.getMenuConfig(callback);
* ```
* Callback:
*
* - `err`, 调用失败时得到的异常
* - `result`, 调用正常时得到的对象
*
* Result:
* ```
* {"errcode":0,"errmsg":"ok"}
* ```
* @param {Function} callback 回调函数
*/
exports.getMenuConfig = function (callback) {
this.preRequest(this._getMenuConfig, arguments);
};
/*!
* 获取自定义菜单配置的未封装版本
*/
exports._getMenuConfig = function (callback) {
var url = this.endpoint + '/cgi-bin/get_current_selfmenu_info?access_token=' + this.token.accessToken;
this.request(url, {dataType: 'json'}, wrapper(callback));
};