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