Completed
Push — master ( 058da3...8d02ae )
by Carlos
05:22 queued 02:18
created

ShakeAround::group()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
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
/**
13
 * ShakeAround.php.
14
 *
15
 * @author    allen05ren <[email protected]>
16
 * @copyright 2016 overtrue <[email protected]>
17
 *
18
 * @see       https://github.com/overtrue
19
 * @see       http://overtrue.me
20
 */
21
22
namespace EasyWeChat\ShakeAround;
23
24
use EasyWeChat\Core\AbstractAPI;
25
26
/**
27
 * Class ShakeAround.
28
 */
29
class ShakeAround extends AbstractAPI
30
{
31
    const API_ACCOUNT_REGISTER = 'https://api.weixin.qq.com/shakearound/account/register';
32
    const API_ACCOUNT_AUDIT_STATUS = 'https://api.weixin.qq.com/shakearound/account/auditstatus';
33
    const API_GET_SHAKE_INFO = 'https://api.weixin.qq.com/shakearound/user/getshakeinfo';
34
35
    /**
36
     * Device instance.
37
     *
38
     * @var \EasyWeChat\ShakeAround\Device
39
     */
40
    protected $device = null;
41
42
    /**
43
     * Group instance.
44
     *
45
     * @var \EasyWeChat\ShakeAround\Group
46
     */
47
    protected $group = null;
48
49
    /**
50
     * Page instance.
51
     *
52
     * @var \EasyWeChat\ShakeAround\Page
53
     */
54
    protected $page = null;
55
56
    /**
57
     * Material instance.
58
     *
59
     * @var \EasyWeChat\ShakeAround\Material
60
     */
61
    protected $material = null;
62
63
    /**
64
     * Relation instance.
65
     *
66
     * @var \EasyWeChat\ShakeAround\Relation
67
     */
68
    protected $relation = null;
69
70
    /**
71
     * Stats instance.
72
     *
73
     * @var \EasyWeChat\ShakeAround\Stats
74
     */
75
    protected $stats = null;
76
77
    /**
78
     * Register shake around.
79
     *
80
     * @param string $name
81
     * @param string $tel
82
     * @param string $email
83
     * @param string $industryId
84
     * @param array  $certUrls
85
     * @param string $reason
86
     *
87
     * @return \EasyWeChat\Support\Collection
88
     */
89 1
    public function register($name, $tel, $email, $industryId, array $certUrls, $reason = '')
90
    {
91
        $params = [
92 1
            'name' => $name,
93 1
            'phone_number' => strval($tel),
94 1
            'email' => $email,
95 1
            'industry_id' => $industryId,
96 1
            'qualification_cert_urls' => $certUrls,
97 1
        ];
98
99 1
        if ($reason !== '') {
100 1
            $params['apply_reason'] = $reason;
101 1
        }
102
103 1
        return $this->parseJSON('json', [self::API_ACCOUNT_REGISTER, $params]);
104
    }
105
106
    /**
107
     * Get audit status.
108
     *
109
     * @return \EasyWeChat\Support\Collection
110
     */
111 1
    public function getStatus()
112
    {
113 1
        return $this->parseJSON('get', [self::API_ACCOUNT_AUDIT_STATUS]);
114
    }
115
116
    /**
117
     * Get shake info.
118
     *
119
     * @param string $ticket
120
     * @param int    $needPoi
121
     *
122
     * @return \EasyWeChat\Support\Collection
123
     */
124 1
    public function getShakeInfo($ticket, $needPoi = null)
125
    {
126
        $params = [
127 1
            'ticket' => $ticket,
128 1
        ];
129
130 1
        if ($needPoi !== null) {
131 1
            $params['need_poi'] = intval($needPoi);
132 1
        }
133
134 1
        return $this->parseJSON('json', [self::API_GET_SHAKE_INFO, $params]);
135
    }
136
137
    /**
138
     * Return the device instance.
139
     *
140
     * @return \EasyWeChat\ShakeAround\Device
141
     */
142 1
    public function device()
143
    {
144 1
        if (is_null($this->device)) {
145 1
            $this->device = new Device($this->accessToken);
146 1
        }
147
148 1
        return $this->device;
149
    }
150
151
    /**
152
     * Return the group instance.
153
     *
154
     * @return \EasyWeChat\ShakeAround\Group
155
     */
156 1
    public function group()
157
    {
158 1
        if (is_null($this->group)) {
159 1
            $this->group = new Group($this->accessToken);
160 1
        }
161
162 1
        return $this->group;
163
    }
164
165
    /**
166
     * Return the page instance.
167
     *
168
     * @return \EasyWeChat\ShakeAround\Page
169
     */
170 1
    public function page()
171
    {
172 1
        if (is_null($this->page)) {
173 1
            $this->page = new Page($this->accessToken);
174 1
        }
175
176 1
        return $this->page;
177
    }
178
179
    /**
180
     * Return the material instance.
181
     *
182
     * @return \EasyWeChat\ShakeAround\Material
183
     */
184 1
    public function material()
185
    {
186 1
        if (is_null($this->material)) {
187 1
            $this->material = new Material($this->accessToken);
188 1
        }
189
190 1
        return $this->material;
191
    }
192
193
    /**
194
     * Return the relation instance.
195
     *
196
     * @return \EasyWeChat\ShakeAround\Relation
197
     */
198 1
    public function relation()
199
    {
200 1
        if (is_null($this->relation)) {
201 1
            $this->relation = new Relation($this->accessToken);
202 1
        }
203
204 1
        return $this->relation;
205
    }
206
207
    /**
208
     * Return the stats instance.
209
     *
210
     * @return \EasyWeChat\ShakeAround\Stats
211
     */
212 1
    public function stats()
213
    {
214 1
        if (is_null($this->stats)) {
215 1
            $this->stats = new Stats($this->accessToken);
216 1
        }
217
218 1
        return $this->stats;
219
    }
220
}
221