微信授权调整

This commit is contained in:
2022-09-09 13:25:21 +08:00
parent 13c6ceb3ca
commit 9d9409acc4

View File

@@ -5,6 +5,7 @@ namespace app\controller;
use EasyWeChat\Factory;
use EasyWeChat\OfficialAccount\Application;
use think\facade\Config;
use think\facade\Route;
class Wechat
{
@@ -27,12 +28,13 @@ class Wechat
* @Date : 2022/9/9 11:29
* @Author : <Jason.C>
*/
public function url()
public function url(): string
{
$post = $GLOBALS['data']['data']['url'];
$url = $GLOBALS['data']['data']['url'];
$redirect = Route::buildUrl('wechat/code', ['callback' => $url])
->domain(true);
$this->initWechat();
return $this->app->oauth->scopes(['snsapi_userinfo'])->redirect($post);
return $this->app->oauth->scopes(['snsapi_userinfo'])->redirect($redirect);
}
/**
@@ -43,8 +45,9 @@ class Wechat
*/
public function code()
{
$code = $GLOBALS['data']['data']['code'];
$this->initWechat();
$user = $this->app->oauth->user();
$code = $GLOBALS['data']['data']['code'];
$user = $this->app->oauth->userFromCode($code);
// $user 可以用的方法:
// $user->getId(); // 对应微信的 OPENID