|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the overtrue/socialite. |
|
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 Overtrue\Socialite\Providers; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class WeChatProvider. |
|
18
|
|
|
* |
|
19
|
|
|
* @link https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318590&token=&lang=zh_CN [WeChat - 公众开放平台代公众号 OAuth 文档] |
|
20
|
|
|
*/ |
|
21
|
|
|
class WeChatOpenPlatformProvider extends WeChatProvider |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Component AppId. |
|
25
|
|
|
* |
|
26
|
|
|
* @deprecated 2.0 Will be removed in the future |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $componentAppId; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Component Access Token. |
|
34
|
|
|
* |
|
35
|
|
|
* @deprecated 2.0 Will be removed in the future |
|
36
|
|
|
* |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $componentAccessToken; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var \EasyWeChat\OpenPlatform\AccessToken|array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $credentials; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* {@inheritdoc}. |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $scopes = ['snsapi_base']; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Create a new provider instance. |
|
53
|
|
|
* (Overriding). |
|
54
|
|
|
* |
|
55
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
56
|
|
|
* @param string $clientId |
|
57
|
|
|
* @param \EasyWeChat\OpenPlatform\AccessToken|array $credentials |
|
58
|
|
|
* @param string|null $redirectUrl |
|
59
|
|
|
*/ |
|
60
|
|
|
public function __construct(Request $request, $clientId, $credentials, $redirectUrl = null) |
|
61
|
|
|
{ |
|
62
|
|
|
parent::__construct($request, $clientId, null, $redirectUrl); |
|
63
|
|
|
|
|
64
|
|
|
$this->credentials = $credentials; |
|
65
|
|
|
if (is_array($credentials)) { |
|
66
|
|
|
list($this->componentAppId, $this->componentAccessToken) = $credentials; |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc}. |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getCodeFields($state = null) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->with(['component_appid' => $this->componentAppId()]); |
|
76
|
|
|
|
|
77
|
|
|
return parent::getCodeFields($state); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritdoc}. |
|
82
|
|
|
*/ |
|
83
|
|
|
protected function getTokenUrl() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->baseUrl.'/oauth2/component/access_token'; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* {@inheritdoc}. |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function getTokenFields($code) |
|
92
|
|
|
{ |
|
93
|
|
|
return [ |
|
94
|
|
|
'appid' => $this->clientId, |
|
95
|
|
|
'component_appid' => $this->componentAppId(), |
|
96
|
|
|
'component_access_token' => $this->componentAccessToken(), |
|
97
|
|
|
'code' => $code, |
|
98
|
|
|
'grant_type' => 'authorization_code', |
|
99
|
|
|
]; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Get component app id. |
|
104
|
|
|
* |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
|
|
protected function componentAppId() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->componentAppId ?: $this->credentials->getAppId(); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get component access token. |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
protected function componentAccessToken() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->componentAccessToken ?: $this->credentials->getToken(); |
|
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.