Passed
Pull Request — master (#1404)
by
unknown
02:19
created

Client::clearQuota()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 0
cp 0
crap 2
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\OpenPlatform\Base;
13
14
use EasyWeChat\Kernel\BaseClient;
15
16
/**
17
 * Class Client.
18
 *
19
 * @author mingyoung <[email protected]>
20
 */
21
class Client extends BaseClient
22
{
23
    /**
24
     * Get authorization info.
25
     *
26
     * @param string|null $authCode
27
     *
28
     * @return mixed
29
     */
30
    public function handleAuthorize(string $authCode = null)
31
    {
32
        $params = [
33
            'component_appid' => $this->app['config']['app_id'],
34
            'authorization_code' => $authCode ?? $this->app['request']->get('auth_code'),
35
        ];
36
37
        return $this->httpPostJson('cgi-bin/component/api_query_auth', $params);
38
    }
39
40
    /**
41
     * Get authorizer info.
42
     *
43
     * @param string $appId
44
     *
45
     * @return mixed
46
     */
47
    public function getAuthorizer(string $appId)
48
    {
49
        $params = [
50
            'component_appid' => $this->app['config']['app_id'],
51
            'authorizer_appid' => $appId,
52
        ];
53
54
        return $this->httpPostJson('cgi-bin/component/api_get_authorizer_info', $params);
55
    }
56
57
    /**
58
     * Get options.
59
     *
60
     * @param string $appId
61
     * @param string $name
62
     *
63
     * @return mixed
64
     */
65
    public function getAuthorizerOption(string $appId, string $name)
66
    {
67
        $params = [
68
            'component_appid' => $this->app['config']['app_id'],
69
            'authorizer_appid' => $appId,
70
            'option_name' => $name,
71
        ];
72
73
        return $this->httpPostJson('cgi-bin/component/api_get_authorizer_option', $params);
74
    }
75
76
    /**
77
     * Set authorizer option.
78
     *
79
     * @param string $appId
80
     * @param string $name
81
     * @param string $value
82
     *
83
     * @return mixed
84
     */
85
    public function setAuthorizerOption(string $appId, string $name, string $value)
86
    {
87
        $params = [
88
            'component_appid' => $this->app['config']['app_id'],
89
            'authorizer_appid' => $appId,
90
            'option_name' => $name,
91
            'option_value' => $value,
92
        ];
93
94
        return $this->httpPostJson('cgi-bin/component/api_set_authorizer_option', $params);
95
    }
96
97
    /**
98
     * Get authorizer list.
99
     *
100
     * @param int $offset
101
     * @param int $count
102
     *
103
     * @return mixed
104
     */
105
    public function getAuthorizers($offset = 0, $count = 500)
106
    {
107
        $params = [
108
            'component_appid' => $this->app['config']['app_id'],
109
            'offset' => $offset,
110
            'count' => $count,
111
        ];
112
113
        return $this->httpPostJson('cgi-bin/component/api_get_authorizer_list', $params);
114
    }
115
116
    /**
117
     * Create pre-authorization code.
118
     *
119
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
120
     */
121
    public function createPreAuthorizationCode()
122
    {
123
        $params = [
124
            'component_appid' => $this->app['config']['app_id'],
125
        ];
126
127
        return $this->httpPostJson('cgi-bin/component/api_create_preauthcode', $params);
128
    }
129
    
130
    /**
131
     * OpenPlatform Clear quota.
132
     *
133
     * @link https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318587
134
     *
135
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
136
     */
137
    public function clearQuota()
138
    {
139
        $params = [
140
            'component_appid' => $this->app['config']['app_id'],
141
        ];
142
        
143
        return $this->httpPostJson('cgi-bin/component/clear_quota', $params);
144
    }
145
}
146