Completed
Push — master ( 73ed3f...e38e9f )
by Carlos
02:46
created

Authorizer::getAuthInfo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 0
cts 8
cp 0
crap 6
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
 * Authorizer.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
 * @copyright 2016
22
 *
23
 * @see      https://github.com/overtrue
24
 * @see      http://overtrue.me
25
 */
26
27
namespace EasyWeChat\OpenPlatform\Components;
28
29
class Authorizer extends AbstractComponent
30
{
31
    /**
32
     * Get auth info api.
33
     */
34
    const GET_AUTH_INFO = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth';
35
36
    /**
37
     * Authorization token api.
38
     */
39
    const AUTHORIZATION_TOKEN = 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token';
40
41
    /**
42
     * Get authorizer info api.
43
     */
44
    const GET_AUTHORIZER_INFO = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info';
45
46
    /**
47
     * Get authorizer options api.
48
     */
49
    const GET_AUTHORIZER_OPTION = 'https://api.weixin.qq.com/cgi-bin/component/ api_get_authorizer_option';
50
51
    /**
52
     * Set authorizer options api.
53
     */
54
    const SET_AUTHORIZER_OPTION = 'https://api.weixin.qq.com/cgi-bin/component/ api_set_authorizer_option';
55
56
    /**
57
     * Get authorizer info.
58
     *
59
     * @param $authorizationCode
60
     *
61
     * @return \EasyWeChat\Support\Collection
62
     */
63
    public function getAuthInfo($authorizationCode = null)
64
    {
65
        $data = [
66
            'component_appid' => $this->getComponentAppId(),
67
            'authorization_code' => $authorizationCode ?: $this->request->get('auth_code'),
68
        ];
69
70
        return $this->parseJSON('json', [self::GET_AUTH_INFO, $data]);
71
    }
72
73
    /**
74
     * Get authorization token.
75
     *
76
     * @param $appId
77
     * @param $refreshToken
78
     *
79
     * @return \EasyWeChat\Support\Collection
80
     */
81 View Code Duplication
    public function getAuthorizationToken($appId, $refreshToken)
82
    {
83
        $data = [
84
            'component_appid' => $this->getComponentAppId(),
85
            'authorizer_appid' => $appId,
86
            'authorizer_refresh_token' => $refreshToken,
87
        ];
88
89
        return $this->parseJSON('json', [self::AUTHORIZATION_TOKEN, $data]);
90
    }
91
92
    /**
93
     * Get authorizer info.
94
     *
95
     * @param $authorizerAppId
96
     *
97
     * @return \EasyWeChat\Support\Collection
98
     */
99 View Code Duplication
    public function getAuthorizerInfo($authorizerAppId)
100
    {
101
        $data = [
102
            'component_appid' => $this->getComponentAppId(),
103
            'authorizer_appid' => $authorizerAppId,
104
        ];
105
106
        return $this->parseJSON('json', [self::GET_AUTHORIZER_INFO, $data]);
107
    }
108
109
    /**
110
     * Get options.
111
     *
112
     * @param $authorizerAppId
113
     * @param $optionName
114
     *
115
     * @return \EasyWeChat\Support\Collection
116
     */
117 View Code Duplication
    public function getAuthorizerOption($authorizerAppId, $optionName)
118
    {
119
        $data = [
120
            'component_appid' => $this->getComponentAppId(),
121
            'authorizer_appid' => $authorizerAppId,
122
            'option_name' => $optionName,
123
        ];
124
125
        return $this->parseJSON('json', [self::GET_AUTHORIZER_OPTION, $data]);
126
    }
127
128
    /**
129
     * Set authorizer option.
130
     *
131
     * @param $authorizerAppId
132
     * @param $optionName
133
     * @param $optionValue
134
     *
135
     * @return \EasyWeChat\Support\Collection
136
     */
137 View Code Duplication
    public function setAuthorizerOption($authorizerAppId, $optionName, $optionValue)
138
    {
139
        $data = [
140
            'component_appid' => $this->getComponentAppId(),
141
            'authorizer_appid' => $authorizerAppId,
142
            'option_name' => $optionName,
143
            'option_value' => $optionValue,
144
        ];
145
146
        return $this->parseJSON('json', [self::SET_AUTHORIZER_OPTION, $data]);
147
    }
148
149
    /**
150
     * Get component appId.
151
     *
152
     * @return string
153
     */
154
    private function getComponentAppId()
155
    {
156
        return $this->config['app_id'];
157
    }
158
}
159