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
|
|
|
namespace EasyWeChat\OpenPlatform\Authorizer\Auth; |
13
|
|
|
|
14
|
|
|
use EasyWeChat\Kernel\AccessToken as BaseAccessToken; |
15
|
|
|
use EasyWeChat\OpenPlatform\Application; |
16
|
|
|
use Pimple\Container; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class AccessToken. |
20
|
|
|
* |
21
|
|
|
* @author mingyoung <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class AccessToken extends BaseAccessToken |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $requestMethod = 'POST'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $queryName = 'access_token'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc}. |
37
|
|
|
*/ |
38
|
|
|
protected $tokenKey = 'authorizer_access_token'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var \EasyWeChat\OpenPlatform\Application |
42
|
|
|
*/ |
43
|
|
|
protected $component; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* AuthorizerAccessToken constructor. |
47
|
|
|
* |
48
|
|
|
* @param \Pimple\Container $app |
49
|
|
|
* @param \EasyWeChat\OpenPlatform\Application $component |
50
|
|
|
*/ |
51
|
|
|
public function __construct(Container $app, Application $component) |
52
|
|
|
{ |
53
|
|
|
parent::__construct($app); |
54
|
|
|
|
55
|
|
|
$this->component = $component; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc}. |
60
|
|
|
*/ |
61
|
|
|
protected function getCredentials(): array |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
'component_appid' => $this->component['config']['app_id'], |
65
|
|
|
'authorizer_appid' => $this->app['config']['app_id'], |
66
|
|
|
'authorizer_refresh_token' => $this->app['config']['refresh_token'], |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getEndpoint(): string |
74
|
|
|
{ |
75
|
|
|
return 'cgi-bin/component/api_authorizer_token?'.http_build_query([ |
76
|
|
|
'component_access_token' => $this->component['access_token']->getToken()['component_access_token'], |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|