1
This commit is contained in:
parent
f57c656369
commit
83dea0260c
@ -401,11 +401,18 @@ class Index extends Frontend
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAuthUrl($type, $view)
|
private function getAuthUrl($type, $view, $state = '')
|
||||||
{
|
{
|
||||||
$component_token = $this->component_token();
|
$component_token = $this->component_token();
|
||||||
$preauthcode = $this->create_preauthcode();
|
$preauthcode = $this->create_preauthcode();
|
||||||
$redirect_uri = urlencode("https://ye4s.wms.gztbyc.com/index/index/authNotic");
|
|
||||||
|
// 回跳地址必须携带 state:微信只会额外回传 auth_code/expires_in,
|
||||||
|
// 不带 state 时 authNotic 无法定位授权上下文(会报“参数不完整”)
|
||||||
|
$redirectUri = "https://ye4s.wms.gztbyc.com/index/index/authNotic";
|
||||||
|
if (!empty($state)) {
|
||||||
|
$redirectUri .= '?state=' . $state;
|
||||||
|
}
|
||||||
|
$redirect_uri = urlencode($redirectUri);
|
||||||
|
|
||||||
switch ($view) {
|
switch ($view) {
|
||||||
case 'pc':
|
case 'pc':
|
||||||
@ -422,6 +429,11 @@ class Index extends Frontend
|
|||||||
}
|
}
|
||||||
public function authNotic($state=null) {
|
public function authNotic($state=null) {
|
||||||
try {
|
try {
|
||||||
|
\think\Log::info('授权回调 authNotic: ' . json_encode([
|
||||||
|
'state' => $state,
|
||||||
|
'auth_code' => $this->request->get('auth_code', '')
|
||||||
|
]));
|
||||||
|
|
||||||
// 1. 基础验证
|
// 1. 基础验证
|
||||||
if (empty($state) || empty($this->request->get('auth_code'))) {
|
if (empty($state) || empty($this->request->get('auth_code'))) {
|
||||||
return view('error', ['msg' => '参数不完整']);
|
return view('error', ['msg' => '参数不完整']);
|
||||||
@ -541,8 +553,8 @@ class Index extends Frontend
|
|||||||
$view = $this->request->get('view', 'pc'); // 默认PC端
|
$view = $this->request->get('view', 'pc'); // 默认PC端
|
||||||
$appid = $this->request->get('appid', ''); // 可选:指定要授权的公众号appid
|
$appid = $this->request->get('appid', ''); // 可选:指定要授权的公众号appid
|
||||||
|
|
||||||
// 生成授权链接
|
// 生成授权链接(带上 state,微信回跳 authNotic 时才能还原上下文)
|
||||||
$authUrl = $this->getAuthUrl($type, $view);
|
$authUrl = $this->getAuthUrl($type, $view, $state);
|
||||||
|
|
||||||
if (empty($authUrl)) {
|
if (empty($authUrl)) {
|
||||||
$this->error('获取授权链接失败,请检查配置');
|
$this->error('获取授权链接失败,请检查配置');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user