Completed
Pull Request — master (#546)
by
unknown
05:32
created

ShakeAround::stats()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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