1 | <?php |
||
34 | class Authorizer |
||
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 | * Authorizer AppId. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $appId; |
||
59 | |||
60 | /** |
||
61 | * OpenPlatform AppId. |
||
62 | * |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $openPlatformAppId; |
||
66 | |||
67 | /** |
||
68 | * Authorizer Constructor. |
||
69 | * |
||
70 | * @param \EasyWeChat\OpenPlatform\Api\BaseApi $api |
||
71 | * @param string $openPlatformAppId OpenPlatform AppId |
||
72 | * @param \Doctrine\Common\Cache\Cache $cache |
||
73 | */ |
||
74 | 6 | public function __construct(BaseApi $api, $openPlatformAppId, 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 $appId |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | 6 | public function setAppId($appId) |
|
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 getAppId() |
|
122 | |||
123 | /** |
||
124 | * Saves the authorizer access token in cache. |
||
125 | * |
||
126 | * @param string $token |
||
127 | * @param int $expires |
||
128 | * |
||
129 | * @return $this |
||
130 | */ |
||
131 | 1 | public function setAccessToken($token, $expires = 7200) |
|
137 | |||
138 | /** |
||
139 | * Gets the authorizer access token. |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | 1 | public function getAccessToken() |
|
147 | |||
148 | /** |
||
149 | * Saves the authorizer refresh token in cache. |
||
150 | * |
||
151 | * @param string $refreshToken |
||
152 | * |
||
153 | * @return $this |
||
154 | */ |
||
155 | 2 | public function setRefreshToken($refreshToken) |
|
161 | |||
162 | /** |
||
163 | * Gets the authorizer refresh token. |
||
164 | * |
||
165 | * @return string |
||
166 | * |
||
167 | * @throws \EasyWeChat\Core\Exception when refresh token is not present |
||
168 | */ |
||
169 | 1 | public function getRefreshToken() |
|
179 | |||
180 | /** |
||
181 | * Gets the authorizer access token cache key. |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | 1 | public function getAccessTokenCacheKey() |
|
189 | |||
190 | /** |
||
191 | * Gets the authorizer refresh token cache key. |
||
192 | * |
||
193 | * @return string |
||
194 | */ |
||
195 | 2 | public function getRefreshTokenCacheKey() |
|
199 | } |
||
200 |