Client::createId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
ccs 3
cts 3
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\Device;
13
14
use EasyWeChat\Kernel\BaseClient;
15
16
/**
17
 * Class Client.
18
 *
19
 * @see http://iot.weixin.qq.com/wiki/new/index.html
20
 *
21
 * @author soone <[email protected]>
22
 */
23
class Client extends BaseClient
24
{
25
    /**
26
     * @param string $deviceId
27
     * @param string $openid
28
     * @param string $content
29
     *
30
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
31
     *
32
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
33
     * @throws \GuzzleHttp\Exception\GuzzleException
34
     */
35 1
    public function message(string $deviceId, string $openid, string $content)
36
    {
37
        $params = [
38 1
            'device_type' => $this->app['config']['device_type'],
39 1
            'device_id' => $deviceId,
40 1
            'open_id' => $openid,
41 1
            'content' => base64_encode($content),
42
        ];
43
44 1
        return $this->httpPostJson('device/transmsg', $params);
45
    }
46
47
    /**
48
     * Get device qrcode.
49
     *
50
     * @param array $deviceIds
51
     *
52
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
53
     *
54
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
55
     * @throws \GuzzleHttp\Exception\GuzzleException
56
     */
57 1
    public function qrCode(array $deviceIds)
58
    {
59
        $params = [
60 1
            'device_num' => count($deviceIds),
61 1
            'device_id_list' => $deviceIds,
62
        ];
63
64 1
        return $this->httpPostJson('device/create_qrcode', $params);
65
    }
66
67
    /**
68
     * @param array  $devices
69
     * @param string $productId
70
     * @param int    $opType
71
     *
72
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
73
     *
74
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
75
     * @throws \GuzzleHttp\Exception\GuzzleException
76
     */
77 1
    public function authorize(array $devices, string $productId, int $opType = 0)
78
    {
79
        $params = [
80 1
            'device_num' => count($devices),
81 1
            'device_list' => $devices,
82 1
            'op_type' => $opType,
83 1
            'product_id' => $productId,
84
        ];
85
86 1
        return $this->httpPostJson('device/authorize_device', $params);
87
    }
88
89
    /**
90
     * 获取 device id 和二维码
91
     *
92
     * @param string $productId
93
     *
94
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
95
     *
96
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
97
     */
98 1
    public function createId(string $productId)
99
    {
100
        $params = [
101 1
            'product_id' => $productId,
102
        ];
103
104 1
        return $this->httpGet('device/getqrcode', $params);
105
    }
106
107
    /**
108
     * @param string $openid
109
     * @param string $deviceId
110
     * @param string $ticket
111
     *
112
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
113
     *
114
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
115
     * @throws \GuzzleHttp\Exception\GuzzleException
116
     */
117 1
    public function bind(string $openid, string $deviceId, string $ticket)
118
    {
119
        $params = [
120 1
            'ticket' => $ticket,
121 1
            'device_id' => $deviceId,
122 1
            'openid' => $openid,
123
        ];
124
125 1
        return $this->httpPostJson('device/bind', $params);
126
    }
127
128
    /**
129
     * @param string $openid
130
     * @param string $deviceId
131
     * @param string $ticket
132
     *
133
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
134
     *
135
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
136
     * @throws \GuzzleHttp\Exception\GuzzleException
137
     */
138 1
    public function unbind(string $openid, string $deviceId, string $ticket)
139
    {
140
        $params = [
141 1
            'ticket' => $ticket,
142 1
            'device_id' => $deviceId,
143 1
            'openid' => $openid,
144
        ];
145
146 1
        return $this->httpPostJson('device/unbind', $params);
147
    }
148
149
    /**
150
     * @param string $openid
151
     * @param string $deviceId
152
     *
153
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
154
     *
155
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
156
     * @throws \GuzzleHttp\Exception\GuzzleException
157
     */
158 1
    public function forceBind(string $openid, string $deviceId)
159
    {
160
        $params = [
161 1
            'device_id' => $deviceId,
162 1
            'openid' => $openid,
163
        ];
164
165 1
        return $this->httpPostJson('device/compel_bind', $params);
166
    }
167
168
    /**
169
     * @param string $openid
170
     * @param string $deviceId
171
     *
172
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
173
     *
174
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
175
     * @throws \GuzzleHttp\Exception\GuzzleException
176
     */
177 1
    public function forceUnbind(string $openid, string $deviceId)
178
    {
179
        $params = [
180 1
            'device_id' => $deviceId,
181 1
            'openid' => $openid,
182
        ];
183
184 1
        return $this->httpPostJson('device/compel_unbind', $params);
185
    }
186
187
    /**
188
     * @param string $deviceId
189
     *
190
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
191
     *
192
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
193
     */
194 1
    public function status(string $deviceId)
195
    {
196
        $params = [
197 1
            'device_id' => $deviceId,
198
        ];
199
200 1
        return $this->httpGet('device/get_stat', $params);
201
    }
202
203
    /**
204
     * @param string $ticket
205
     *
206
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
207
     *
208
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
209
     */
210 1
    public function verify(string $ticket)
211
    {
212
        $params = [
213 1
            'ticket' => $ticket,
214
        ];
215
216 1
        return $this->httpPost('device/verify_qrcode', $params);
217
    }
218
219
    /**
220
     * @param string $deviceId
221
     *
222
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
223
     *
224
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
225
     */
226 1
    public function openid(string $deviceId)
227
    {
228
        $params = [
229 1
            'device_type' => $this->app['config']['device_type'],
230 1
            'device_id' => $deviceId,
231
        ];
232
233 1
        return $this->httpGet('device/get_openid', $params);
234
    }
235
236
    /**
237
     * @param string $openid
238
     *
239
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
240
     *
241
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
242
     */
243 1
    public function listByOpenid(string $openid)
244
    {
245
        $params = [
246 1
            'openid' => $openid,
247
        ];
248
249 1
        return $this->httpGet('device/get_bind_device', $params);
250
    }
251
}
252