|
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
|
|
|
* AccessToken.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
|
|
|
* @copyright 2016 |
|
22
|
|
|
* |
|
23
|
|
|
* @see https://github.com/overtrue |
|
24
|
|
|
* @see http://overtrue.me |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace EasyWeChat\OpenPlatform; |
|
28
|
|
|
|
|
29
|
|
|
use EasyWeChat\Core\AccessToken as CoreAccessToken; |
|
30
|
|
|
use EasyWeChat\Core\Exceptions\HttpException; |
|
31
|
|
|
|
|
32
|
|
|
class AccessToken extends CoreAccessToken |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* VerifyTicket. |
|
36
|
|
|
* |
|
37
|
|
|
* @var \EasyWeChat\OpenPlatform\VerifyTicket |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $verifyTicket; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* API. |
|
43
|
|
|
*/ |
|
44
|
|
|
const API_TOKEN_GET = 'https://api.weixin.qq.com/cgi-bin/component/api_component_token'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc}. |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $queryName = 'component_access_token'; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc}. |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $tokenJsonKey = 'component_access_token'; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc}. |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $prefix = 'easywechat.open_platform.component_access_token.'; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Set VerifyTicket. |
|
63
|
|
|
* |
|
64
|
|
|
* @param EasyWeChat\OpenPlatform\VerifyTicket $verifyTicket |
|
65
|
|
|
* |
|
66
|
|
|
* @return $this |
|
67
|
|
|
*/ |
|
68
|
12 |
|
public function setVerifyTicket(VerifyTicket $verifyTicket) |
|
69
|
|
|
{ |
|
70
|
12 |
|
$this->verifyTicket = $verifyTicket; |
|
71
|
|
|
|
|
72
|
12 |
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* {@inheritdoc}. |
|
77
|
|
|
*/ |
|
78
|
|
View Code Duplication |
public function getTokenFromServer() |
|
79
|
|
|
{ |
|
80
|
|
|
$data = [ |
|
81
|
|
|
'component_appid' => $this->appId, |
|
82
|
|
|
'component_appsecret' => $this->secret, |
|
83
|
|
|
'component_verify_ticket' => $this->verifyTicket->getTicket(), |
|
84
|
|
|
]; |
|
85
|
|
|
|
|
86
|
|
|
$http = $this->getHttp(); |
|
87
|
|
|
|
|
88
|
|
|
$token = $http->parseJSON($http->json(self::API_TOKEN_GET, $data)); |
|
89
|
|
|
|
|
90
|
|
|
if (empty($token[$this->tokenJsonKey])) { |
|
91
|
|
|
throw new HttpException('Request ComponentAccessToken fail. response: '.json_encode($token, JSON_UNESCAPED_UNICODE)); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $token; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|