1 | ;
|
2 |
|
3 | var util = require('./util');
|
4 | var wrapper = util.wrapper;
|
5 | var postJSON = util.postJSON;
|
6 | /**
|
7 | * 创建标签
|
8 | * 详情请见:<http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN>
|
9 | * Examples:
|
10 | * ```
|
11 | * api.createTag(callback);
|
12 | * ```
|
13 | * Callback:
|
14 | *
|
15 | * - `err`, 调用失败时得到的异常
|
16 | * - `result`, 调用正常时得到的对象
|
17 | *
|
18 | * Result:
|
19 | * ```
|
20 | * {
|
21 | * "tag": [
|
22 | * "id": 134, // 标签id
|
23 | * "name": "广东"
|
24 | * ]
|
25 | * }
|
26 | * ```
|
27 | * @param {String} name tag name
|
28 | * @param {Function} callback 回调函数
|
29 | */
|
30 | exports.createTag = function (name, callback) {
|
31 | this.preRequest(this._createTag, arguments);
|
32 | };
|
33 |
|
34 | /*!
|
35 | * 创建标签的未封装版本
|
36 | */
|
37 | exports._createTag = function (name, callback) {
|
38 | // https://api.weixin.qq.com/cgi-bin/tags/create?access_token=ACCESS_TOKEN
|
39 | var url = this.endpoint + '/cgi-bin/tags/create?access_token=' + this.token.accessToken;
|
40 | var data = {
|
41 | 'tag': {
|
42 | 'name': name
|
43 | }
|
44 | };
|
45 | this.request(url, postJSON(data), wrapper(callback));
|
46 | };
|
47 |
|
48 | /**
|
49 | * 获取公众号已创建的标签
|
50 | * 详情请见:<http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN>
|
51 | * Examples:
|
52 | * ```
|
53 | * api.getTags(callback);
|
54 | * ```
|
55 | * Callback:
|
56 | *
|
57 | * - `err`, 调用失败时得到的异常
|
58 | * - `result`, 调用正常时得到的对象
|
59 | *
|
60 | * Result:
|
61 | * ```
|
62 | * {
|
63 | * "tags":[{
|
64 | * 'id':1,
|
65 | * 'name': '黑名单',
|
66 | * 'count': 0 // 此标签下粉丝数
|
67 | * },{
|
68 | * 'id':2,
|
69 | * 'name': '星标组',
|
70 | * 'count':0
|
71 | * }]
|
72 | * }
|
73 | * ```
|
74 | * @param {String} openid Open ID
|
75 | * @param {Function} callback 回调函数
|
76 | */
|
77 | exports.getTags = function (callback) {
|
78 | this.preRequest(this._getTags, arguments);
|
79 | };
|
80 |
|
81 | /*!
|
82 | * 获取公众号已创建的标签的未封装版本
|
83 | */
|
84 | exports._getTags = function (callback) {
|
85 | // https://api.weixin.qq.com/cgi-bin/tags/get?access_token=ACCESS_TOKEN
|
86 | var url = this.endpoint + '/cgi-bin/tags/get?access_token=' + this.token.accessToken;
|
87 | this.request(url, {dataType: 'json'}, wrapper(callback));
|
88 | };
|
89 |
|
90 | /**
|
91 | * 编辑标签
|
92 | * 详情请见:<http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN>
|
93 | * Examples:
|
94 | * ```
|
95 | * api.editTag(id, name, callback);
|
96 | * ```
|
97 | * Callback:
|
98 | *
|
99 | * - `err`, 调用失败时得到的异常
|
100 | * - `result`, 调用正常时得到的对象
|
101 | *
|
102 | * Result:
|
103 | * ```
|
104 | * {"errcode": 0, "errmsg": "ok"}}
|
105 | * ```
|
106 | * @param {Number} id 标签ID
|
107 | * @param {String} name 标签新名字
|
108 | * @param {Function} callback 回调函数
|
109 | */
|
110 | exports.editTag = function (id, name, callback) {
|
111 | this.preRequest(this._editTag, arguments);
|
112 | };
|
113 |
|
114 | /*!
|
115 | * 编辑标签的未封装版本
|
116 | */
|
117 | exports._editTag = function (id, name, callback) {
|
118 | // https://api.weixin.qq.com/cgi-bin/tags/update?access_token=ACCESS_TOKEN
|
119 | // POST数据格式:json
|
120 | // POST数据例子:{"tag":{"id":134, "name":"test"}}
|
121 | var url = this.endpoint + '/cgi-bin/tags/update?access_token=' + this.token.accessToken;
|
122 | var data = {
|
123 | 'tag': {
|
124 | 'id': id,
|
125 | 'name': name
|
126 | }
|
127 | };
|
128 | this.request(url, postJSON(data), wrapper(callback));
|
129 | };
|
130 |
|
131 | /**
|
132 | * 删除标签
|
133 | * 详情请见:<http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN>
|
134 | * Examples:
|
135 | * ```
|
136 | * api.deleteTag(id, callback);
|
137 | * ```
|
138 | * Callback:
|
139 | *
|
140 | * - `err`, 调用失败时得到的异常
|
141 | * - `result`, 调用正常时得到的对象
|
142 | *
|
143 | * Result:
|
144 | * ```
|
145 | * {"errcode": 0, "errmsg": "ok"}
|
146 | * ```
|
147 | * @param {Number} id 标签ID
|
148 | * @param {Function} callback 回调函数
|
149 | */
|
150 | exports.deleteTag = function (id, callback) {
|
151 | this.preRequest(this._deleteTag, arguments);
|
152 | };
|
153 |
|
154 | /*!
|
155 | * 删除标签的未封装版本
|
156 | */
|
157 | exports._deleteTag = function (id, callback) {
|
158 | // http请求方式: POST(请使用https协议)
|
159 | // https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=ACCESS_TOKEN
|
160 | // POST数据格式:json
|
161 | // POST数据例子:{"tag":{"id":108}}
|
162 | var url = this.endpoint + '/cgi-bin/tags/delete?access_token=' + this.token.accessToken;
|
163 | var data = {
|
164 | 'tag': {'id': id}
|
165 | };
|
166 | this.request(url, postJSON(data), wrapper(callback));
|
167 | };
|
168 |
|
169 | /**
|
170 | * 获取标签下粉丝列表
|
171 | * 详情请见:<http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN>
|
172 | * Examples:
|
173 | * ```
|
174 | * api.getTagUsers(tagid, openid, callback);
|
175 | * ```
|
176 | * Callback:
|
177 | *
|
178 | * - `err`, 调用失败时得到的异常
|
179 | * - `result`, 调用正常时得到的对象
|
180 | *
|
181 | * Result:
|
182 | * ```
|
183 | * {
|
184 | * "count": 2,
|
185 | * "data":{
|
186 | * "openid":[
|
187 | * ...
|
188 | * ]
|
189 | * },
|
190 | * "next_openid": "..."
|
191 | * }
|
192 | * ```
|
193 | * @param {Number} tagId 标签ID
|
194 | * @param {String} openid 分页起始openid
|
195 | * @param {Function} callback 回调函数
|
196 | */
|
197 | exports.getTagUsers = function (tagId, openid, callback) {
|
198 | this.preRequest(this._getTagUsers, arguments);
|
199 | };
|
200 |
|
201 | /*!
|
202 | * 获取标签下粉丝列表的未封装版本
|
203 | */
|
204 | exports._getTagUsers = function (tagId, openid, callback) {
|
205 | // http请求方式: POST(请使用https协议)
|
206 | // https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=ACCESS_TOKEN
|
207 | // POST数据格式:json
|
208 | // POST数据例子:{"tagid":108, "next_openid":"oDF3iYx0ro3_7jD4HFRDfrjdCM58"}
|
209 | var url = this.endpoint + '/cgi-bin/user/tag/get?access_token=' + this.token.accessToken;
|
210 | var data = {
|
211 | 'tagid': tagId,
|
212 | 'next_openid': openid
|
213 | };
|
214 | this.request(url, postJSON(data), wrapper(callback));
|
215 | };
|
216 |
|
217 | /**
|
218 | * 批量为用户打标签
|
219 | * 详情请见:<http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN>
|
220 | * Examples:
|
221 | * ```
|
222 | * api.memberBatchtagging(tagId, openList, callback);
|
223 | * ```
|
224 | * Callback:
|
225 | *
|
226 | * - `err`, 调用失败时得到的异常
|
227 | * - `result`, 调用正常时得到的对象
|
228 | *
|
229 | * Result:
|
230 | * ```
|
231 | * {"errcode": 0, "errmsg": "ok"}
|
232 | * ```
|
233 | * @param {Number} tagId 标签ID
|
234 | * @param {Array} openList 用户openids
|
235 | * @param {Function} callback 回调函数
|
236 | */
|
237 | exports.membersBatchtagging = function (tagId, openList, callback) {
|
238 | this.preRequest(this._membersBatchtagging, arguments);
|
239 | };
|
240 |
|
241 | /*!
|
242 | * 批量为用户打标签的未封装版本
|
243 | */
|
244 | exports._membersBatchtagging = function (tagId, openList, callback) {
|
245 | // https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=ACCESS_TOKEN
|
246 | var url = this.endpoint + '/cgi-bin/tags/members/batchtagging?access_token=' + this.token.accessToken;
|
247 | var data = {
|
248 | 'openid_list':openList,
|
249 | 'tagid': tagId
|
250 | };
|
251 | this.request(url, postJSON(data), wrapper(callback));
|
252 | };
|
253 |
|
254 | /**
|
255 | * 批量为用户取消标签
|
256 | * 详情请见:<http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN>
|
257 | * Examples:
|
258 | * ```
|
259 | * api.memberBatchuntagging(tagId, openList, callback);
|
260 | * ```
|
261 | * Callback:
|
262 | *
|
263 | * - `err`, 调用失败时得到的异常
|
264 | * - `result`, 调用正常时得到的对象
|
265 | *
|
266 | * Result:
|
267 | * ```
|
268 | * {"errcode": 0, "errmsg": "ok"}
|
269 | * ```
|
270 | * @param {Number} tagId 标签ID
|
271 | * @param {Array} openList 用户openids
|
272 | * @param {Function} callback 回调函数
|
273 | */
|
274 | exports.membersBatchuntagging = function (tagId, openList, callback) {
|
275 | this.preRequest(this._membersBatchuntagging, arguments);
|
276 | };
|
277 |
|
278 | /*!
|
279 | * 批量为用户取消标签的未封装版本
|
280 | */
|
281 | exports._membersBatchuntagging = function (tagId, openList, callback) {
|
282 | // https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=ACCESS_TOKEN
|
283 | var url = this.endpoint + '/cgi-bin/tags/members/batchuntagging?access_token=' + this.token.accessToken;
|
284 | var data = {
|
285 | 'openid_list':openList,
|
286 | 'tagid': tagId
|
287 | };
|
288 | this.request(url, postJSON(data), wrapper(callback));
|
289 | };
|
290 |
|
291 | /**
|
292 | * 获取用户身上的标签列表
|
293 | * 详情请见:<http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140837&token=&lang=zh_CN>
|
294 | * Examples:
|
295 | * ```
|
296 | * api.getUserTags(openid, callback);
|
297 | * ```
|
298 | * Callback:
|
299 | *
|
300 | * - `err`, 调用失败时得到的异常
|
301 | * - `result`, 调用正常时得到的对象
|
302 | *
|
303 | * Result:
|
304 | * ```
|
305 | * {"tagid_list": [134, 2]}
|
306 | * ```
|
307 | * @param {openid} 用户openid
|
308 | * @param {Function} callback 回调函数
|
309 | */
|
310 | exports.getUserTags = function (openid, callback) {
|
311 | this.preRequest(this._getUserTags, arguments);
|
312 | };
|
313 |
|
314 | /*!
|
315 | * 获取用户身上的标签列表的未封装版本
|
316 | */
|
317 | exports._getUserTags = function (openid, callback) {
|
318 | // https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=ACCESS_TOKEN
|
319 | var url = this.endpoint + '/cgi-bin/tags/getidlist?access_token=' + this.token.accessToken;
|
320 | var data = {
|
321 | 'openid':openid
|
322 | };
|
323 | this.request(url, postJSON(data), wrapper(callback));
|
324 | };
|
325 |
|