Passed
Push — master ( e38f5c...931b65 )
by Carlos
06:23 queued 02:38
created

BaseApi::getAuthorizationInfo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 9.6666
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
 * BaseApi.php.
14
 *
15
 * Part of Overtrue\WeChat.
16
 *
17
 * For the full copyright and license information, please view the LICENSE
18
 * file that was distributed with this source code.
19
 *
20
 * @author    mingyoung <[email protected]>
21
 * @author    lixiao <[email protected]>
22
 * @copyright 2016
23
 *
24
 * @see      https://github.com/overtrue
25
 * @see      http://overtrue.me
26
 */
27
28
namespace EasyWeChat\OpenPlatform\Api;
29
30
class BaseApi extends AbstractComponent
31
{
32
    /**
33
     * Get auth info api.
34
     */
35
    const GET_AUTH_INFO = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth';
36
37
    /**
38
     * Authorization token api.
39
     */
40
    const GET_AUTHORIZER_TOKEN = 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token';
41
42
    /**
43
     * Get authorizer info api.
44
     */
45
    const GET_AUTHORIZER_INFO = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info';
46
47
    /**
48
     * Get authorizer options api.
49
     */
50
    const GET_AUTHORIZER_OPTION = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option';
51
52
    /**
53
     * Set authorizer options api.
54
     */
55
    const SET_AUTHORIZER_OPTION = 'https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option';
56
57
    /**
58
     * Get authorization info.
59
     *
60
     * @param $authCode
61
     *
62
     * @return \EasyWeChat\Support\Collection
63
     */
64 1
    public function getAuthorizationInfo($authCode = null)
65
    {
66
        $params = [
67 1
            'component_appid' => $this->getAppId(),
68 1
            'authorization_code' => $authCode ?: $this->request->get('auth_code'),
69 1
        ];
70
71 1
        return $this->parseJSON('json', [self::GET_AUTH_INFO, $params]);
72
    }
73
74
    /**
75
     * Get authorization token.
76
     *
77
     * @param $authorizerAppId
78
     * @param $authorizerRefreshToken
79
     *
80
     * @return \EasyWeChat\Support\Collection
81
     */
82 1 View Code Duplication
    public function getAuthorizationToken($authorizerAppId, $authorizerRefreshToken)
83
    {
84
        $params = [
85 1
            'component_appid' => $this->getAppId(),
86 1
            'authorizer_appid' => $authorizerAppId,
87 1
            'authorizer_refresh_token' => $authorizerRefreshToken,
88 1
        ];
89
90 1
        return $this->parseJSON('json', [self::GET_AUTHORIZER_TOKEN, $params]);
91
    }
92
93
    /**
94
     * Get authorizer info.
95
     *
96
     * @param string $authorizerAppId
97
     *
98
     * @return \EasyWeChat\Support\Collection
99
     */
100 1
    public function getAuthorizerInfo($authorizerAppId)
101
    {
102
        $params = [
103 1
            'component_appid' => $this->getAppId(),
104 1
            'authorizer_appid' => $authorizerAppId,
105 1
        ];
106
107 1
        return $this->parseJSON('json', [self::GET_AUTHORIZER_INFO, $params]);
108
    }
109
110
    /**
111
     * Get options.
112
     *
113
     * @param $authorizerAppId
114
     * @param $optionName
115
     *
116
     * @return \EasyWeChat\Support\Collection
117
     */
118 1 View Code Duplication
    public function getAuthorizerOption($authorizerAppId, $optionName)
119
    {
120
        $params = [
121 1
            'component_appid' => $this->getAppId(),
122 1
            'authorizer_appid' => $authorizerAppId,
123 1
            'option_name' => $optionName,
124 1
        ];
125
126 1
        return $this->parseJSON('json', [self::GET_AUTHORIZER_OPTION, $params]);
127
    }
128
129
    /**
130
     * Set authorizer option.
131
     *
132
     * @param $authorizerAppId
133
     * @param $optionName
134
     * @param $optionValue
135
     *
136
     * @return \EasyWeChat\Support\Collection
137
     */
138 1 View Code Duplication
    public function setAuthorizerOption($authorizerAppId, $optionName, $optionValue)
139
    {
140
        $params = [
141 1
            'component_appid' => $this->getAppId(),
142 1
            'authorizer_appid' => $authorizerAppId,
143 1
            'option_name' => $optionName,
144 1
            'option_value' => $optionValue,
145 1
        ];
146
147 1
        return $this->parseJSON('json', [self::SET_AUTHORIZER_OPTION, $params]);
148
    }
149
}
150