From 9d9409acc405f5c1806eee1703d66f46fcdcf552 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 9 Sep 2022 13:25:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8E=88=E6=9D=83=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/Wechat.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controller/Wechat.php b/app/controller/Wechat.php index 633daae..9e5d6fb 100644 --- a/app/controller/Wechat.php +++ b/app/controller/Wechat.php @@ -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 : */ - 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