1 | <?php |
||
34 | class Authorization |
||
35 | { |
||
36 | const CACHE_KEY_ACCESS_TOKEN = 'easywechat.open_platform.authorizer_access_token'; |
||
37 | const CACHE_KEY_REFRESH_TOKEN = 'easywechat.open_platform.authorizer_refresh_token'; |
||
38 | |||
39 | /** |
||
40 | * Cache. |
||
41 | * |
||
42 | * @var \Doctrine\Common\Cache\Cache |
||
43 | */ |
||
44 | protected $cache; |
||
45 | |||
46 | /** |
||
47 | * Base API. |
||
48 | * |
||
49 | * @var \EasyWeChat\OpenPlatform\Api\BaseApi |
||
50 | */ |
||
51 | protected $api; |
||
52 | |||
53 | /** |
||
54 | * Open Platform App Id, aka, Component App Id. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $appId; |
||
59 | |||
60 | /** |
||
61 | * Authorizer App Id. |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $authorizerAppId; |
||
66 | |||
67 | /** |
||
68 | * Authorization Constructor. |
||
69 | * |
||
70 | * @param \EasyWeChat\OpenPlatform\Api\BaseApi $api |
||
71 | * @param string $appId |
||
72 | * @param \Doctrine\Common\Cache\Cache $cache |
||
73 | */ |
||
74 | 6 | public function __construct(BaseApi $api, $appId, Cache $cache) |
|
80 | |||
81 | /** |
||
82 | * Gets the base api. |
||
83 | * |
||
84 | * @return \EasyWeChat\OpenPlatform\Api\BaseApi |
||
85 | */ |
||
86 | 3 | public function getApi() |
|
90 | |||
91 | /** |
||
92 | * Sets the authorizer app id. |
||
93 | * |
||
94 | * @param string $authorizerAppId |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | 6 | public function setAuthorizerAppId($authorizerAppId) |
|
104 | |||
105 | /** |
||
106 | * Gets the authorizer app id, or throws if not found. |
||
107 | * |
||
108 | * @return string |
||
109 | * |
||
110 | * @throws \EasyWeChat\Core\Exception |
||
111 | */ |
||
112 | 3 | public function getAuthorizerAppId() |
|
122 | |||
123 | /** |
||
124 | * Saves the authorizer access token in cache. |
||
125 | * |
||
126 | * @param string $token |
||
127 | * |
||
128 | * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise |
||
129 | */ |
||
130 | 1 | public function setAuthorizerAccessToken($token, $expires = 7200) |
|
134 | |||
135 | /** |
||
136 | * Gets the authorizer access token. |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | 1 | public function getAuthorizerAccessToken() |
|
144 | |||
145 | /** |
||
146 | * Saves the authorizer refresh token in cache. |
||
147 | * |
||
148 | * @param string $refreshToken |
||
149 | * |
||
150 | * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise |
||
151 | */ |
||
152 | 2 | public function setAuthorizerRefreshToken($refreshToken) |
|
156 | |||
157 | /** |
||
158 | * Gets the authorizer refresh token. |
||
159 | * |
||
160 | * @return string |
||
161 | * |
||
162 | * @throws \EasyWeChat\Core\Exception when refresh token is not present |
||
163 | */ |
||
164 | 1 | public function getAuthorizerRefreshToken() |
|
174 | |||
175 | /** |
||
176 | * Removes the authorizer access token from cache. |
||
177 | * |
||
178 | * @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise. |
||
179 | * Deleting a non-existing entry is considered successful |
||
180 | */ |
||
181 | public function removeAuthorizerAccessToken() |
||
185 | |||
186 | /** |
||
187 | * Removes the authorizer refresh token from cache. |
||
188 | * |
||
189 | * @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise. |
||
190 | * Deleting a non-existing entry is considered successful |
||
191 | */ |
||
192 | public function removeAuthorizerRefreshToken() |
||
196 | |||
197 | /** |
||
198 | * Gets the authorizer access token cache key. |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | 1 | public function getAuthorizerAccessTokenKey() |
|
206 | |||
207 | /** |
||
208 | * Gets the authorizer refresh token cache key. |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | 2 | public function getAuthorizerRefreshTokenKey() |
|
216 | } |
||
217 |