Client::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyWeChat\OfficialAccount\CustomerService;
13
14
use EasyWeChat\Kernel\BaseClient;
15
16
/**
17
 * Class Client.
18
 *
19
 * @author overtrue <[email protected]>
20
 */
21
class Client extends BaseClient
22
{
23
    /**
24
     * List all staffs.
25
     *
26
     * @return mixed
27
     *
28
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
29
     */
30 1
    public function list()
31
    {
32 1
        return $this->httpGet('cgi-bin/customservice/getkflist');
33
    }
34
35
    /**
36
     * List all online staffs.
37
     *
38
     * @return mixed
39
     *
40
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
41
     */
42 1
    public function online()
43
    {
44 1
        return $this->httpGet('cgi-bin/customservice/getonlinekflist');
45
    }
46
47
    /**
48
     * Create a staff.
49
     *
50
     * @param string $account
51
     * @param string $nickname
52
     *
53
     * @return mixed
54
     *
55
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
56
     * @throws \GuzzleHttp\Exception\GuzzleException
57
     */
58 1
    public function create(string $account, string $nickname)
59
    {
60
        $params = [
61 1
            'kf_account' => $account,
62 1
            'nickname' => $nickname,
63
        ];
64
65 1
        return $this->httpPostJson('customservice/kfaccount/add', $params);
66
    }
67
68
    /**
69
     * Update a staff.
70
     *
71
     * @param string $account
72
     * @param string $nickname
73
     *
74
     * @return mixed
75
     *
76
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
77
     * @throws \GuzzleHttp\Exception\GuzzleException
78
     */
79 1
    public function update(string $account, string $nickname)
80
    {
81
        $params = [
82 1
            'kf_account' => $account,
83 1
            'nickname' => $nickname,
84
        ];
85
86 1
        return $this->httpPostJson('customservice/kfaccount/update', $params);
87
    }
88
89
    /**
90
     * Delete a staff.
91
     *
92
     * @param string $account
93
     *
94
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
95
     *
96
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
97
     * @throws \GuzzleHttp\Exception\GuzzleException
98
     */
99 1
    public function delete(string $account)
100
    {
101 1
        return $this->httpPostJson('customservice/kfaccount/del', [], ['kf_account' => $account]);
102
    }
103
104
    /**
105
     * Invite a staff.
106
     *
107
     * @param string $account
108
     * @param string $wechatId
109
     *
110
     * @return mixed
111
     *
112
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
113
     * @throws \GuzzleHttp\Exception\GuzzleException
114
     */
115 1
    public function invite(string $account, string $wechatId)
116
    {
117
        $params = [
118 1
            'kf_account' => $account,
119 1
            'invite_wx' => $wechatId,
120
        ];
121
122 1
        return $this->httpPostJson('customservice/kfaccount/inviteworker', $params);
123
    }
124
125
    /**
126
     * Set staff avatar.
127
     *
128
     * @param string $account
129
     * @param string $path
130
     *
131
     * @return mixed
132
     *
133
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
134
     * @throws \GuzzleHttp\Exception\GuzzleException
135
     */
136 1
    public function setAvatar(string $account, string $path)
137
    {
138 1
        return $this->httpUpload('customservice/kfaccount/uploadheadimg', ['media' => $path], [], ['kf_account' => $account]);
139
    }
140
141
    /**
142
     * Get message builder.
143
     *
144
     * @param \EasyWeChat\Kernel\Messages\Message|string $message
145
     *
146
     * @return \EasyWeChat\OfficialAccount\CustomerService\Messenger
147
     */
148 1
    public function message($message)
149
    {
150 1
        $messageBuilder = new Messenger($this);
151
152 1
        return $messageBuilder->message($message);
153
    }
154
155
    /**
156
     * Send a message.
157
     *
158
     * @param array $message
159
     *
160
     * @return mixed
161
     *
162
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
163
     * @throws \GuzzleHttp\Exception\GuzzleException
164
     */
165 1
    public function send(array $message)
166
    {
167 1
        return $this->httpPostJson('cgi-bin/message/custom/send', $message);
168
    }
169
170
    /**
171
     * Show typing status.
172
     *
173
     * @param string $openid
174
     *
175
     * @return mixed
176
     *
177
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
178
     * @throws \GuzzleHttp\Exception\GuzzleException
179
     */
180 1
    public function showTypingStatusToUser(string $openid)
181
    {
182 1
        return $this->httpPostJson('cgi-bin/message/custom/typing', [
183 1
            'touser' => $openid,
184 1
            'command' => 'Typing',
185
        ]);
186
    }
187
188
    /**
189
     * Hide typing status.
190
     *
191
     * @param string $openid
192
     *
193
     * @return mixed
194
     *
195
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
196
     * @throws \GuzzleHttp\Exception\GuzzleException
197
     */
198 1
    public function hideTypingStatusToUser(string $openid)
199
    {
200 1
        return $this->httpPostJson('cgi-bin/message/custom/typing', [
201 1
            'touser' => $openid,
202 1
            'command' => 'CancelTyping',
203
        ]);
204
    }
205
206
    /**
207
     * Get messages history.
208
     *
209
     * @param int $startTime
210
     * @param int $endTime
211
     * @param int $msgId
212
     * @param int $number
213
     *
214
     * @return mixed
215
     *
216
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
217
     * @throws \GuzzleHttp\Exception\GuzzleException
218
     */
219 1
    public function messages($startTime, $endTime, int $msgId = 1, int $number = 10000)
220
    {
221
        $params = [
222 1
            'starttime' => is_numeric($startTime) ? $startTime : strtotime($startTime),
0 ignored issues
show
introduced by
The condition is_numeric($startTime) is always true.
Loading history...
223 1
            'endtime' => is_numeric($endTime) ? $endTime : strtotime($endTime),
0 ignored issues
show
introduced by
The condition is_numeric($endTime) is always true.
Loading history...
224 1
            'msgid' => $msgId,
225 1
            'number' => $number,
226
        ];
227
228 1
        return $this->httpPostJson('customservice/msgrecord/getmsglist', $params);
229
    }
230
}
231