From fb2130116d567908d8001a36a4a2aa91bdc639d1 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 9 Sep 2022 14:17:08 +0800 Subject: [PATCH 1/2] token --- app/controller/Wechat.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controller/Wechat.php b/app/controller/Wechat.php index fcd9b1c..8211971 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\Request; use think\facade\Route; use think\facade\View; @@ -48,9 +49,12 @@ class Wechat public function code() { $this->initWechat(); - $user = $this->app->oauth->user(); - $code = $GLOBALS['data']['data']['code']; - $user = $this->app->oauth->userFromCode($code); + $user = $this->app->oauth->user(); + $callback = Request::get('callback'); + + $token = '怎样获得一个 token'; + return redirect($callback.'?token='.$token); + // $user 可以用的方法: // $user->getId(); // 对应微信的 OPENID // $user->getNickname(); // 对应微信的 nickname From 2ae394976c370af1a46c790a90a238a8d1411b23 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 9 Sep 2022 14:20:14 +0800 Subject: [PATCH 2/2] w --- app/controller/Wechat.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controller/Wechat.php b/app/controller/Wechat.php index 8211971..5ba9307 100644 --- a/app/controller/Wechat.php +++ b/app/controller/Wechat.php @@ -8,6 +8,7 @@ use think\facade\Config; use think\facade\Request; use think\facade\Route; use think\facade\View; +use think\response\Json; class Wechat { @@ -30,14 +31,15 @@ class Wechat * @Date : 2022/9/9 11:29 * @Author : */ - public function url(): string + public function url(): Json { $url = $GLOBALS['data']['data']['url']; $redirect = Route::buildUrl('wechat/code', ['callback' => $url]) ->suffix(false) ->domain(true); $this->initWechat(); - return $this->app->oauth->scopes(['snsapi_userinfo'])->redirect($redirect); + + return show(SUCCESS_MESSAGE,SUCCESS_CODE,$this->app->oauth->scopes(['snsapi_userinfo'])->redirect($redirect)); } /**