Completed
Pull Request — master (#553)
by
unknown
02:23
created

Authorizer::getAuthorizationToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 10
loc 10
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
 * 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
     * @return \EasyWeChat\Support\Collection
61
     */
62
    public function getAuthInfo($authorizationCode = null)
63
    {
64
        $data = [
65
            'component_appid' => $this->getComponentAppId(),
66
            'authorization_code' => $authorizationCode ?: $this->request->get('auth_code')
67
        ];
68
69
        return $this->parseJSON('json', [self::GET_AUTH_INFO, $data]);
70
    }
71
72
    /**
73
     * Get authorization token.
74
     *
75
     * @param $appId
76
     * @param $refreshToken
77
     *
78
     * @return \EasyWeChat\Support\Collection
79
     */
80 View Code Duplication
    public function getAuthorizationToken($appId, $refreshToken)
81
    {
82
        $data = [
83
            'component_appid' => $this->getComponentAppId(),
84
            'authorizer_appid' => $appId,
85
            'authorizer_refresh_token' => $refreshToken
86
        ];
87
88
        return $this->parseJSON('json', [self::AUTHORIZATION_TOKEN, $data]);
89
    }
90
91
    /**
92
     * Get authorizer info.
93
     *
94
     * @param $authorizerAppId
95
     *
96
     * @return \EasyWeChat\Support\Collection
97
     */
98 View Code Duplication
    public function getAuthorizerInfo($authorizerAppId)
99
    {
100
        $data = [
101
            'component_appid' => $this->getComponentAppId(),
102
            'authorizer_appid' => $authorizerAppId,
103
        ];
104
105
        return $this->parseJSON('json', [self::GET_AUTHORIZER_INFO, $data]);
106
    }
107
108
    /**
109
     * Get options.
110
     *
111
     * @param $authorizerAppId
112
     * @param $optionName
113
     *
114
     * @return \EasyWeChat\Support\Collection
115
     */
116 View Code Duplication
    public function getAuthorizerOption($authorizerAppId, $optionName)
117
    {
118
        $data = [
119
            'component_appid' => $this->getComponentAppId(),
120
            'authorizer_appid' => $authorizerAppId,
121
            'option_name' => $optionName
122
        ];
123
124
        return $this->parseJSON('json', [self::GET_AUTHORIZER_OPTION, $data]);
125
    }
126
127
    /**
128
     * Set authorizer option.
129
     *
130
     * @param $authorizerAppId
131
     * @param $optionName
132
     * @param $optionValue
133
     *
134
     * @return \EasyWeChat\Support\Collection
135
     */
136 View Code Duplication
    public function setAuthorizerOption($authorizerAppId, $optionName, $optionValue)
137
    {
138
        $data = [
139
            'component_appid' => $this->getComponentAppId(),
140
            'authorizer_appid' => $authorizerAppId,
141
            'option_name' => $optionName,
142
            'option_value' => $optionValue
143
        ];
144
145
        return $this->parseJSON('json', [self::SET_AUTHORIZER_OPTION, $data]);
146
    }
147
148
    /**
149
     * Get component appId.
150
     *
151
     * @return string
152
     */
153
    private function getComponentAppId()
154
    {
155
        return $this->config['app_id'];
156
    }
157
}
158