UNPKG

4.21 kBJavaScriptView Raw
1'use strict';
2
3var util = require('./util');
4var wrapper = util.wrapper;
5var postJSON = util.postJSON;
6
7/**
8 * 创建自定义菜单
9 * 详细请看:http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html
10 *
11 * Menu:
12 * ```
13 * {
14 * "button":[
15 * {
16 * "type":"click",
17 * "name":"今日歌曲",
18 * "key":"V1001_TODAY_MUSIC"
19 * },
20 * {
21 * "name":"菜单",
22 * "sub_button":[
23 * {
24 * "type":"view",
25 * "name":"搜索",
26 * "url":"http://www.soso.com/"
27 * },
28 * {
29 * "type":"click",
30 * "name":"赞一下我们",
31 * "key":"V1001_GOOD"
32 * }]
33 * }]
34 * }
35 * ]
36 * }
37 * ```
38 * Examples:
39 * ```
40 * api.createMenu(menu, callback);
41 * ```
42 * Callback:
43 *
44 * - `err`, 调用失败时得到的异常
45 * - `result`, 调用正常时得到的对象
46 *
47 * Result:
48 * ```
49 * {"errcode":0,"errmsg":"ok"}
50 * ```
51 * @param {Object} menu 菜单对象
52 * @param {Function} callback 回调函数
53 */
54exports.createMenu = function (menu, callback) {
55 this.preRequest(this._createMenu, arguments);
56};
57
58/*!
59 * 创建自定义菜单的未封装版本
60 */
61exports._createMenu = function (menu, callback) {
62 var url = this.endpoint + '/cgi-bin/menu/create?access_token=' + this.token.accessToken;
63 this.request(url, postJSON(menu), wrapper(callback));
64};
65
66/**
67 * 获取菜单
68 * 详细请看:<http://mp.weixin.qq.com/wiki/5/f287d1a5b78a35a8884326312ac3e4ed.html>
69 *
70 * Examples:
71 * ```
72 * api.getMenu(callback);
73 * ```
74 * Callback:
75 *
76 * - `err`, 调用失败时得到的异常
77 * - `result`, 调用正常时得到的对象
78 *
79 * Result: (注意:如果有个性化菜单被设置,返回的结果会具有更多信息,请参考微信文档)
80 * ```
81 * // 结果示例
82 * {
83 * "menu": {
84 * "button":[
85 * {"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC","sub_button":[]},
86 * {"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER","sub_button":[]},
87 * {"name":"菜单","sub_button":[
88 * {"type":"view","name":"搜索","url":"http://www.soso.com/","sub_button":[]},
89 * {"type":"view","name":"视频","url":"http://v.qq.com/","sub_button":[]},
90 * {"type":"click","name":"赞一下我们","key":"V1001_GOOD","sub_button":[]}]
91 * }
92 * ]
93 * }
94 * }
95 * ```
96 * @param {Function} callback 回调函数
97 */
98exports.getMenu = function (callback) {
99 this.preRequest(this._getMenu, arguments);
100};
101
102/*!
103 * 获取自定义菜单的未封装版本
104 */
105exports._getMenu = function (callback) {
106 var url = this.endpoint + '/cgi-bin/menu/get?access_token=' + this.token.accessToken;
107 this.request(url, {dataType: 'json'}, wrapper(callback));
108};
109
110/**
111 * 删除自定义菜单
112 * 详细请看:<http://mp.weixin.qq.com/wiki/16/8ed41ba931e4845844ad6d1eeb8060c8.html>
113 * Examples:
114 * ```
115 * api.removeMenu(callback);
116 * ```
117 * Callback:
118 *
119 * - `err`, 调用失败时得到的异常
120 * - `result`, 调用正常时得到的对象
121 *
122 * Result:
123 * ```
124 * {"errcode":0,"errmsg":"ok"}
125 * ```
126 * @param {Function} callback 回调函数
127 */
128exports.removeMenu = function (callback) {
129 this.preRequest(this._removeMenu, arguments);
130};
131
132/*!
133 * 删除自定义菜单的未封装版本
134 */
135exports._removeMenu = function (callback) {
136 var url = this.endpoint + '/cgi-bin/menu/delete?access_token=' + this.token.accessToken;
137 this.request(url, {dataType: 'json'}, wrapper(callback));
138};
139
140
141/**
142 * 获取自定义菜单配置
143 * 详细请看:<http://mp.weixin.qq.com/wiki/17/4dc4b0514fdad7a5fbbd477aa9aab5ed.html>
144 * Examples:
145 * ```
146 * api.getMenuConfig(callback);
147 * ```
148 * Callback:
149 *
150 * - `err`, 调用失败时得到的异常
151 * - `result`, 调用正常时得到的对象
152 *
153 * Result:
154 * ```
155 * {"errcode":0,"errmsg":"ok"}
156 * ```
157 * @param {Function} callback 回调函数
158 */
159exports.getMenuConfig = function (callback) {
160 this.preRequest(this._getMenuConfig, arguments);
161};
162
163/*!
164 * 获取自定义菜单配置的未封装版本
165 */
166exports._getMenuConfig = function (callback) {
167 var url = this.endpoint + '/cgi-bin/get_current_selfmenu_info?access_token=' + this.token.accessToken;
168 this.request(url, {dataType: 'json'}, wrapper(callback));
169};