1
1
'use strict' ;
2
2
3
- var util = require ( './util' ) ;
4
- var wrapper = util . wrapper ;
5
- var postJSON = util . postJSON ;
6
3
var path = require ( 'path' ) ;
7
4
var fs = require ( 'fs' ) ;
8
5
var formstream = require ( 'formstream' ) ;
9
6
7
+ var util = require ( './util' ) ;
8
+ var wrapper = util . wrapper ;
9
+ var postJSON = util . postJSON ;
10
+ var make = util . make ;
11
+
10
12
/**
11
13
* 获取客服聊天记录
12
14
* 详细请看:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1464937269_mUtmK&token=&lang=zh_CN
@@ -53,19 +55,12 @@ var formstream = require('formstream');
53
55
* @param {Object } opts 查询条件
54
56
* @param {Function } callback 回调函数
55
57
*/
56
- exports . getRecords = function ( opts , callback ) {
57
- this . preRequest ( this . _getRecords , arguments ) ;
58
- } ;
59
-
60
- /*!
61
- * 获取客服聊天记录的未封装版本
62
- */
63
- exports . _getRecords = function ( opts , callback ) {
58
+ make ( exports , 'getRecords' , function ( opts , callback ) {
64
59
// https://api.weixin.qq.com/customservice/msgrecord/getmsglist?access_token=ACCESS_TOKEN
65
60
opts . msgid = opts . msgid || 1 ;
66
61
var url = this . endpoint + '/customservice/msgrecord/getmsglist?access_token=' + this . token . accessToken ;
67
62
this . request ( url , postJSON ( opts ) , wrapper ( callback ) ) ;
68
- } ;
63
+ } ) ;
69
64
70
65
/**
71
66
* 获取客服基本信息
@@ -104,18 +99,11 @@ exports._getRecords = function (opts, callback) {
104
99
* ```
105
100
* @param {Function } callback 回调函数
106
101
*/
107
- exports . getCustomServiceList = function ( callback ) {
108
- this . preRequest ( this . _getCustomServiceList , arguments ) ;
109
- } ;
110
-
111
- /*!
112
- * 获取客服基本信息的未封装版本
113
- */
114
- exports . _getCustomServiceList = function ( callback ) {
102
+ make ( exports , 'getCustomServiceList' , function ( callback ) {
115
103
// https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token= ACCESS_TOKEN
116
104
var url = this . endpoint + '/cgi-bin/customservice/getkflist?access_token=' + this . token . accessToken ;
117
105
this . request ( url , { dataType : 'json' } , wrapper ( callback ) ) ;
118
- } ;
106
+ } ) ;
119
107
120
108
/**
121
109
* 获取在线客服接待信息
@@ -154,17 +142,16 @@ exports._getCustomServiceList = function (callback) {
154
142
* ```
155
143
* @param {Function } callback 回调函数
156
144
*/
157
- exports . getOnlineCustomServiceList = function ( callback ) {
158
- this . preRequest ( this . _getOnlineCustomServiceList , arguments ) ;
159
- } ;
160
-
161
- /*!
162
- * 获取在线客服接待信息的未封装版本
163
- */
164
- exports . _getOnlineCustomServiceList = function ( callback ) {
145
+ make ( exports , 'getOnlineCustomServiceList' , function ( callback ) {
165
146
// https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token= ACCESS_TOKEN
166
147
var url = this . endpoint + '/cgi-bin/customservice/getonlinekflist?access_token=' + this . token . accessToken ;
167
148
this . request ( url , { dataType : 'json' } , wrapper ( callback ) ) ;
149
+ } ) ;
150
+
151
+ var md5 = function ( input ) {
152
+ var crypto = require ( 'crypto' ) ;
153
+ var hash = crypto . createHash ( 'md5' ) ;
154
+ return hash . update ( input ) . digest ( 'hex' ) ;
168
155
} ;
169
156
170
157
/**
@@ -193,20 +180,7 @@ exports._getOnlineCustomServiceList = function (callback) {
193
180
* @param {String } password 密码,可以直接传递明文,wechat模块自动进行md5加密
194
181
* @param {Function } callback 回调函数
195
182
*/
196
- exports . addKfAccount = function ( account , nick , password , callback ) {
197
- this . preRequest ( this . _addKfAccount , arguments ) ;
198
- } ;
199
-
200
- var md5 = function ( input ) {
201
- var crypto = require ( 'crypto' ) ;
202
- var hash = crypto . createHash ( 'md5' ) ;
203
- return hash . update ( input ) . digest ( 'hex' ) ;
204
- } ;
205
-
206
- /*!
207
- * 添加客服账号的未封装版本
208
- */
209
- exports . _addKfAccount = function ( account , nick , password , callback ) {
183
+ make ( exports , 'addKfAccount' , function ( account , nick , password , callback ) {
210
184
// https://api.weixin.qq.com/customservice/kfaccount/add?access_token=ACCESS_TOKEN
211
185
var url = this . endpoint + '/customservice/kfaccount/add?access_token=' + this . token . accessToken ;
212
186
var data = {
@@ -216,7 +190,7 @@ exports._addKfAccount = function (account, nick, password, callback) {
216
190
} ;
217
191
218
192
this . request ( url , postJSON ( data ) , wrapper ( callback ) ) ;
219
- } ;
193
+ } ) ;
220
194
221
195
/**
222
196
* 设置客服账号
@@ -244,14 +218,7 @@ exports._addKfAccount = function (account, nick, password, callback) {
244
218
* @param {String } password 密码,可以直接传递明文,wechat模块自动进行md5加密
245
219
* @param {Function } callback 回调函数
246
220
*/
247
- exports . updateKfAccount = function ( account , nick , password , callback ) {
248
- this . preRequest ( this . _updateKfAccount , arguments ) ;
249
- } ;
250
-
251
- /*!
252
- * 设置客服账号的未封装版本
253
- */
254
- exports . _updateKfAccount = function ( account , nick , password , callback ) {
221
+ make ( exports , 'updateKfAccount' , function ( account , nick , password , callback ) {
255
222
// https://api.weixin.qq.com/customservice/kfaccount/add?access_token=ACCESS_TOKEN
256
223
var url = this . endpoint + '/customservice/kfaccount/update?access_token=' + this . token . accessToken ;
257
224
var data = {
@@ -261,7 +228,7 @@ exports._updateKfAccount = function (account, nick, password, callback) {
261
228
} ;
262
229
263
230
this . request ( url , postJSON ( data ) , wrapper ( callback ) ) ;
264
- } ;
231
+ } ) ;
265
232
266
233
/**
267
234
* 删除客服账号
@@ -287,18 +254,11 @@ exports._updateKfAccount = function (account, nick, password, callback) {
287
254
* @param {String } account 账号名字,格式为:前缀@公共号名字
288
255
* @param {Function } callback 回调函数
289
256
*/
290
- exports . deleteKfAccount = function ( account , callback ) {
291
- this . preRequest ( this . _deleteKfAccount , arguments ) ;
292
- } ;
293
-
294
- /*!
295
- * 删除客服账号的未封装版本
296
- */
297
- exports . _deleteKfAccount = function ( account , callback ) {
257
+ make ( exports , 'deleteKfAccount' , function ( account , callback ) {
298
258
// https://api.weixin.qq.com/customservice/kfaccount/del?access_token=ACCESS_TOKEN
299
259
var url = this . endpoint + '/customservice/kfaccount/del?access_token=' + this . token . accessToken + '&kf_account=' + account ;
300
260
this . request ( url , { dataType : 'json' } , wrapper ( callback ) ) ;
301
- } ;
261
+ } ) ;
302
262
303
263
/**
304
264
* 设置客服头像
@@ -325,14 +285,7 @@ exports._deleteKfAccount = function (account, callback) {
325
285
* @param {String } filepath 头像路径
326
286
* @param {Function } callback 回调函数
327
287
*/
328
- exports . setKfAccountAvatar = function ( account , filepath , callback ) {
329
- this . preRequest ( this . _setKfAccountAvatar , arguments ) ;
330
- } ;
331
-
332
- /*!
333
- * 上传多媒体文件的未封装版本
334
- */
335
- exports . _setKfAccountAvatar = function ( account , filepath , callback ) {
288
+ make ( exports , 'setKfAccountAvatar' , function ( account , filepath , callback ) {
336
289
// http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=ACCESS_TOKEN&kf_account=KFACCOUNT
337
290
var that = this ;
338
291
fs . stat ( filepath , function ( err , stat ) {
@@ -351,4 +304,4 @@ exports._setKfAccountAvatar = function (account, filepath, callback) {
351
304
} ;
352
305
that . request ( url , opts , wrapper ( callback ) ) ;
353
306
} ) ;
354
- } ;
307
+ } ) ;
0 commit comments