1 | <?php |
||
43 | class AuthorizerAccessToken extends BaseAccessToken |
||
44 | { |
||
45 | /** |
||
46 | * @var \EasyWeChat\OpenPlatform\Authorizer |
||
47 | */ |
||
48 | protected $authorizer; |
||
49 | |||
50 | /** |
||
51 | * AuthorizerAccessToken constructor. |
||
52 | * |
||
53 | * @param string $appId |
||
54 | * @param \EasyWeChat\OpenPlatform\Authorizer $authorizer |
||
55 | */ |
||
56 | 4 | public function __construct($appId, Authorizer $authorizer) |
|
62 | |||
63 | /** |
||
64 | * Get token from WeChat API. |
||
65 | * |
||
66 | * @param bool $forceRefresh |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | 3 | public function getToken($forceRefresh = false) |
|
80 | |||
81 | /** |
||
82 | * Refresh authorizer access token. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | 2 | protected function renewAccessToken() |
|
87 | { |
||
88 | 2 | $token = $this->authorizer->getApi() |
|
89 | 2 | ->getAuthorizerToken( |
|
90 | 2 | $this->authorizer->getAppId(), |
|
91 | 2 | $this->authorizer->getRefreshToken() |
|
92 | 2 | ); |
|
93 | |||
94 | 2 | $this->authorizer->setAccessToken($token['authorizer_access_token'], $token['expires_in'] - 1500); |
|
95 | |||
96 | 2 | return $token['authorizer_access_token']; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * Return the AuthorizerAppId. |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | 1 | public function getAppId() |
|
108 | } |
||
109 |