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 AbstractOpenPlatform |
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
|
|
|
* Get authorizer 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
|
|
|
const GET_AUTHORIZER_LIST = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list'; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get authorization info. |
61
|
|
|
* |
62
|
|
|
* @param $authCode |
63
|
|
|
* |
64
|
|
|
* @return \EasyWeChat\Support\Collection |
65
|
|
|
*/ |
66
|
1 |
|
public function getAuthorizationInfo($authCode = null) |
67
|
|
|
{ |
68
|
|
|
$params = [ |
69
|
1 |
|
'component_appid' => $this->getAppId(), |
70
|
1 |
|
'authorization_code' => $authCode ?: $this->request->get('auth_code'), |
71
|
1 |
|
]; |
72
|
|
|
|
73
|
1 |
|
return $this->parseJSON('json', [self::GET_AUTH_INFO, $params]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get authorizer token. |
78
|
|
|
* |
79
|
|
|
* It doesn't cache the authorizer-access-token. |
80
|
|
|
* So developers should NEVER call this method. |
81
|
|
|
* It'll called by: AuthorizerAccessToken::renewAccessToken() |
82
|
|
|
* |
83
|
|
|
* @param $appId |
84
|
|
|
* @param $refreshToken |
85
|
|
|
* |
86
|
|
|
* @return \EasyWeChat\Support\Collection |
87
|
|
|
*/ |
88
|
1 |
View Code Duplication |
public function getAuthorizerToken($appId, $refreshToken) |
89
|
|
|
{ |
90
|
|
|
$params = [ |
91
|
1 |
|
'component_appid' => $this->getAppId(), |
92
|
1 |
|
'authorizer_appid' => $appId, |
93
|
1 |
|
'authorizer_refresh_token' => $refreshToken, |
94
|
1 |
|
]; |
95
|
|
|
|
96
|
1 |
|
return $this->parseJSON('json', [self::GET_AUTHORIZER_TOKEN, $params]); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get authorizer info. |
101
|
|
|
* |
102
|
|
|
* @param string $authorizerAppId |
103
|
|
|
* |
104
|
|
|
* @return \EasyWeChat\Support\Collection |
105
|
|
|
*/ |
106
|
1 |
|
public function getAuthorizerInfo($authorizerAppId) |
107
|
|
|
{ |
108
|
|
|
$params = [ |
109
|
1 |
|
'component_appid' => $this->getAppId(), |
110
|
1 |
|
'authorizer_appid' => $authorizerAppId, |
111
|
1 |
|
]; |
112
|
|
|
|
113
|
1 |
|
return $this->parseJSON('json', [self::GET_AUTHORIZER_INFO, $params]); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Get options. |
118
|
|
|
* |
119
|
|
|
* @param $authorizerAppId |
120
|
|
|
* @param $optionName |
121
|
|
|
* |
122
|
|
|
* @return \EasyWeChat\Support\Collection |
123
|
|
|
*/ |
124
|
1 |
View Code Duplication |
public function getAuthorizerOption($authorizerAppId, $optionName) |
125
|
|
|
{ |
126
|
|
|
$params = [ |
127
|
1 |
|
'component_appid' => $this->getAppId(), |
128
|
1 |
|
'authorizer_appid' => $authorizerAppId, |
129
|
1 |
|
'option_name' => $optionName, |
130
|
1 |
|
]; |
131
|
|
|
|
132
|
1 |
|
return $this->parseJSON('json', [self::GET_AUTHORIZER_OPTION, $params]); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Set authorizer option. |
137
|
|
|
* |
138
|
|
|
* @param $authorizerAppId |
139
|
|
|
* @param $optionName |
140
|
|
|
* @param $optionValue |
141
|
|
|
* |
142
|
|
|
* @return \EasyWeChat\Support\Collection |
143
|
|
|
*/ |
144
|
1 |
View Code Duplication |
public function setAuthorizerOption($authorizerAppId, $optionName, $optionValue) |
145
|
|
|
{ |
146
|
|
|
$params = [ |
147
|
1 |
|
'component_appid' => $this->getAppId(), |
148
|
1 |
|
'authorizer_appid' => $authorizerAppId, |
149
|
1 |
|
'option_name' => $optionName, |
150
|
1 |
|
'option_value' => $optionValue, |
151
|
1 |
|
]; |
152
|
|
|
|
153
|
1 |
|
return $this->parseJSON('json', [self::SET_AUTHORIZER_OPTION, $params]); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get authorizer list. |
158
|
|
|
* |
159
|
|
|
* @param int $offset |
160
|
|
|
* @param int $count |
161
|
|
|
* |
162
|
|
|
* @return \EasyWeChat\Support\Collection |
163
|
|
|
*/ |
164
|
1 |
View Code Duplication |
public function getAuthorizerList($offset = 0, $count = 500) |
165
|
|
|
{ |
166
|
|
|
$params = [ |
167
|
1 |
|
'component_appid' => $this->getAppId(), |
168
|
1 |
|
'offset' => $offset, |
169
|
1 |
|
'count' => $count, |
170
|
1 |
|
]; |
171
|
|
|
|
172
|
1 |
|
return $this->parseJSON('json', [self::GET_AUTHORIZER_LIST, $params]); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|