KfaccountApi::getrecord()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 1
eloc 10
nc 1
nop 4
1
<?php
2
namespace Wechat\API;
3
4
/**
5
 * 微信客服相关接口.
6
 *
7
 * @author Huang.
8
 */
9
class KfaccountApi extends BaseApi
10
{
11
    /**
12
     * 客服账号管理-添加客服账号.
13
     *
14
     * @author Huang
15
     *
16
     * @param string $kf_account 客服账号
17
     *
18
     * @param string $nickname   客服昵称
19
     *
20
     * @param string $password   客服密码
21
     *
22
     * @return array 客服信息.
23
     */
24 View Code Duplication
    public function add($kf_account, $nickname, $password)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        $kf_array = [
27
            'kf_account' => $kf_account,
28
            'nickname'   => $nickname,
29
            'password'   => MD5($password),
30
        ];
31
32
        $this->apitype = 'customservice';
33
34
        $this->module = 'kfaccount';
35
36
        $res = $this->_post('add', $kf_array);
37
38
        return $res;
39
    }
40
41
    /**
42
     * 客服账号管理-修改客服账号.
43
     *
44
     * @author Huang
45
     *
46
     * @param string $kf_account 客服账号
47
     *
48
     * @param string $nickname   客服昵称
49
     *
50
     * @param string $password   客服密码
51
     *
52
     * @return array 客服信息.
53
     */
54 View Code Duplication
    public function update($kf_account, $nickname, $password)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $kf_array = [
57
            'kf_account' => $kf_account,
58
            'nickname'   => $nickname,
59
            'password'   => MD5($password),
60
        ];
61
62
        $this->apitype = 'customservice';
63
64
        $this->module = 'kfaccount';
65
66
        $res = $this->_post('update', $kf_array);
67
68
        return $res;
69
    }
70
71
    /**
72
     * 客服账号管理-删除客服账号.
73
     *
74
     * @author Huang
75
     *
76
     * @param string $kf_account 客服账号
77
     *
78
     * @return array 客服信息.
79
     */
80
    public function del($kf_account)
81
    {
82
        $kf_array = [
83
            'kf_account' => $kf_account,
84
        ];
85
86
        $this->apitype = 'customservice';
87
        $this->module  = 'kfaccount';
88
89
        $res = $this->_get('del', $kf_array);
90
91
        return $res;
92
    }
93
94
    /**
95
     * 客服账号管理-获取客服基本信息.
96
     *
97
     * @author Huang
98
     *
99
     * @return array 客服信息.
100
     */
101
    public function getkflist()
102
    {
103
        $kf_array = [];
104
105
        $this->module = 'customservice';
106
107
        $res = $this->_get('getkflist', $kf_array);
108
109
        return $res;
110
    }
111
112
    /**
113
     * 客服账号管理-获取在线客服接待信息.
114
     *
115
     * @author Huang
116
     *
117
     * @return array 客服信息.
118
     */
119
    public function getonlinekflist()
120
    {
121
        $kf_array = [];
122
123
        $this->module = 'customservice';
124
125
        $res = $this->_get('getonlinekflist', $kf_array);
126
127
        return $res;
128
    }
129
130
    /**
131
     * 客服账号管理-设置客服账号的头像.
132
     *
133
     * @author Huang
134
     *
135
     * @param string $kf_account 客服账号
136
     *
137
     * @return array 客服信息.
138
     */
139
    public function uploadheadimg($file, $kf_account)
140
    {
141
        if (!$file || !$kf_account) {
142
            $this->setError('参数缺失');
143
144
            return false;
145
        }
146
147
        if (!file_exists($file)) {
148
            $this->setError('文件路径不正确');
149
150
            return false;
151
        }
152
153
        $data          = [];
154
        $data['media'] = '@' . realpath($file);
155
156
        $this->setPostQueryStr('kf_account', $kf_account);
157
158
        $this->apitype = 'customservice';
159
        $this->module  = 'kfaccount';
160
161
        $res = $this->_post('uploadheadimg', $data, false);
162
163
        return $res;
164
    }
165
166
    /**
167
     * 获取客服聊天记录.
168
     *
169
     * @author Huang
170
     *
171
     * @param int $endtime   查询结束时间,UNIX时间戳,每次查询不能跨日查询
172
     *
173
     * @param int $pageindex 查询第几页,从1开始
174
     *
175
     * @param int $pagesize  每页大小,每页最多拉取50条
176
     *
177
     * @param int $starttime 查询开始时间,UNIX时间戳
178
     *
179
     * @return array 客服信息.
180
     */
181
    public function getrecord($endtime, $pageindex, $pagesize, $starttime)
182
    {
183
        $recond_array = [
184
            'endtime'   => $endtime,
185
            'pageindex' => $pageindex,
186
            'pagesize'  => $pagesize,
187
            'starttime' => $starttime,
188
        ];
189
190
        $this->apitype = 'customservice';
191
192
        $this->module = 'msgrecord';
193
194
        $res = $this->_post('getrecord', $recond_array);
195
196
        return $res;
197
    }
198
199
200
    /**
201
     * ------------------------------------------发送客服消息------------------------------------------
202
     */
203
204
    /**
205
     * 图文消息- 自定义
206
     *
207
     * @param  array  $articles   图文消息
208
     * @param  string $openid     接收消息用户对应该公众号的openid
209
     * @param  string $kf_account 客服账号
210
     *
211
     * @return int     msg_id     发送出去的消息ID
212
     */
213
    public function customNews($articles = [], $openid, $kf_account = '')
214
    {
215
        $queryStr                     = [];
216
        $queryStr['touser']           = $openid;
217
        $queryStr['msgtype']          = 'news';
218
        $queryStr['news']['articles'] = $articles;
219
220
        $queryStr['customservice']['kf_account'] = $kf_account;
221
222
        $this->module = 'message';
223
224
        $res = $this->_post('custom/send', $queryStr);
225
226
        return $res;
227
    }
228
229
    /**
230
     * 图文消息 - 微信
231
     *
232
     * @param  boolean $media_id   用于设定是否向全部用户发送,选择true该消息群发给所有用户,选择false可根据group_id发送给指定群组的用户
233
     * @param  string  $openid     接收消息用户对应该公众号的openid
234
     * @param  string  $type       接受用户 是 openid  还是 wxname
0 ignored issues
show
Bug introduced by
There is no parameter named $type. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
235
     * @param string   $kf_account 客服账号
236
     *
237
     * @return int     msg_id     发送出去的消息ID
238
     */
239 View Code Duplication
    public function customMpnews($media_id = '', $openid = '', $kf_account = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
240
    {
241
        $queryStr                       = [];
242
        $queryStr['towxname']           = $openid;
243
        $queryStr['msgtype']            = 'mpnews';
244
        $queryStr['mpnews']['media_id'] = $media_id;
245
246
        $queryStr['customservice']['kf_account'] = $kf_account;
247
248
        $this->module = 'message';
249
250
        $res = $this->_post('custom/send', $queryStr);
251
252
        return $res;
253
    }
254
255
    /**
256
     * 文本消息
257
     *
258
     * @param  string $content    文字
259
     * @param  string $openid     接收消息用户对应该公众号的openid
260
     * @param string  $kf_account 客服账号
261
     *
262
     * @return int     msg_id     发送出去的消息ID
263
     */
264 View Code Duplication
    public function customText($content = '', $openid, $kf_account = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
265
    {
266
        $queryStr                    = [];
267
        $queryStr['touser']          = $openid;
268
        $queryStr['msgtype']         = 'text';
269
        $queryStr['text']['content'] = $content;
270
271
        $queryStr['customservice']['kf_account'] = $kf_account;
272
273
        $this->module = 'message';
274
275
        $res = $this->_post('custom/send', $queryStr);
276
277
        return $res;
278
    }
279
280
    /**
281
     * 语音(注意此处media_id需通过基础支持中的上传下载多媒体文件来得到)
282
     *
283
     * @param  string $media_id   用于群发的消息的media_id
284
     * @param  string $openid     接收消息用户对应该公众号的openid
285
     * @param string  $kf_account 客服账号
286
     *
287
     * @return int     msg_id     发送出去的消息ID
288
     */
289 View Code Duplication
    public function customVoice($media_id = '', $openid, $kf_account = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
290
    {
291
        $queryStr                      = [];
292
        $queryStr['touser']            = $openid;
293
        $queryStr['msgtype']           = 'voice';
294
        $queryStr['voice']['media_id'] = $media_id;
295
296
        $queryStr['customservice']['kf_account'] = $kf_account;
297
298
        $this->module = 'message';
299
300
        $res = $this->_post('custom/send', $queryStr);
301
302
        return $res;
303
    }
304
305
    /**
306
     * 图片(注意此处media_id需通过基础支持中的上传下载多媒体文件来得到)
307
     *
308
     * @param  string $media_id   用于群发的消息的media_id
309
     * @param  string $openid     接收消息用户对应该公众号的openid
310
     * @param string  $kf_account 客服账号
311
     *
312
     * @return int     msg_id     发送出去的消息ID
313
     */
314 View Code Duplication
    public function customImage($media_id = '', $openid, $kf_account = '')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
315
    {
316
        $queryStr                      = [];
317
        $queryStr['touser']            = $openid;
318
        $queryStr['msgtype']           = 'image';
319
        $queryStr['image']['media_id'] = $media_id;
320
321
        $queryStr['customservice']['kf_account'] = $kf_account;
322
323
        $this->module = 'message';
324
325
        $res = $this->_post('custom/send', $queryStr);
326
327
        return $res;
328
    }
329
330
    /**
331
     * 视频(请注意,此处视频的media_id需通过POST请求到下述接口特别地得到)
332
     *
333
     * @param  string $media_id    用于群发的消息的media_id
334
     * @param  string $openid      接收消息用户对应该公众号的openid
335
     * @param  string $title       标题
336
     * @param  string $description 描述
337
     * @param string  $kf_account  客服账号
338
     *
339
     * @return int     msg_id     发送出去的消息ID
340
     */
341
    public function customMpvideo($media_id = '', $title = '', $description = '', $openid, $kf_account = '')
342
    {
343
        $queryStr                           = [];
344
        $queryStr['touser']                 = $openid;
345
        $queryStr['msgtype']                = 'mpvideo';
346
        $queryStr['mpvideo']['media_id']    = $media_id;
347
        $queryStr['mpvideo']['title']       = $title;
348
        $queryStr['mpvideo']['description'] = $description;
349
350
        $queryStr['customservice']['kf_account'] = $kf_account;
351
352
        $this->module = 'message';
353
354
        $res = $this->_post('custom/send', $queryStr);
355
356
        return $res;
357
    }
358
359
    /**
360
     * 卡券(注意图文消息的card_id需要通过上述方法来得到)
361
     *
362
     * @param  string $card_id    card_id
363
     * @param  array  $card_ext   签名
364
     * @param  string $openid     接收消息用户对应该公众号的openid
365
     * @param string  $kf_account 客服账号
366
     *
367
     * @return int     msg_id     发送出去的消息ID
368
     */
369
    public function customWxcard($card_id = '', $card_ext = [], $openid, $kf_account = '')
370
    {
371
        $queryStr                       = [];
372
        $queryStr['touser']             = $openid;
373
        $queryStr['msgtype']            = 'wxcard';
374
        $queryStr['wxcard']['card_id']  = $card_id;
375
        $queryStr['wxcard']['card_ext'] = $card_ext;
376
377
        $queryStr['customservice']['kf_account'] = $kf_account;
378
379
        $this->module = 'message';
380
381
        $res = $this->_post('custom/send', $queryStr);
382
383
        return $res;
384
    }
385
386
    /**
387
     * 发送音乐消息
388
     *
389
     * @param  string $musicurl       音乐链接
390
     * @param  string $openid         接收消息用户对应该公众号的openid
391
     * @param  string $thumb_media_id 缩略图的媒体ID
392
     * @param  string $hqmusicurl     高品质音乐链接,wifi环境优先使用该链接播放音乐
393
     * @param  string $title          标题
394
     * @param  string $description    描述
395
     * @param string  $kf_account     客服账号
396
     *
397
     * @return string msg_id
398
     */
399
    public function customMusic($musicurl = '', $openid = '', $thumb_media_id = '', $hqmusicurl = '', $title = '', $description = '', $kf_account = '')
400
    {
401
        $queryStr                            = [];
402
        $queryStr['touser']                  = $openid;
403
        $queryStr['msgtype']                 = 'music';
404
        $queryStr['music']['title']          = $title;
405
        $queryStr['music']['description']    = $description;
406
        $queryStr['music']['musicurl']       = $musicurl;
407
        $queryStr['music']['hqmusicurl']     = $hqmusicurl;
408
        $queryStr['music']['thumb_media_id'] = $thumb_media_id;
409
410
        $queryStr['customservice']['kf_account'] = $kf_account;
411
412
        $this->module = 'message';
413
414
        $res = $this->_post('custom/send', $queryStr);
415
416
        return $res;
417
    }
418
}
419