laravel前后端分离获取微信授权,结合laravel-wechat-LMLPHP

laravel前后端分离获取微信授权,结合laravel-wechat-LMLPHP

http://test.***.com/index?code=021Azdiu12zdXd05kkju1ZYkiu1AzdiR&state=1

  public function handle($request, Closure $next, $scopes = null)
  {
         $wechatCacheKey = 'wechat.oauth_user.default';
            if (config("qa.mock_user") == 1){
                $user = new SocialiteUser(config('wechat.mock_user'));
            } else {
                $code = $request->get("code", "");
                if ($code === ""){
                    $appId = $this->config["app_id"];
                    return Response::toJson(["aid" => $appId], "请重新获取授权CODE!",10006);
                }
                // 开始拉取用户信息
                $app = Factory::officialAccount($this->config);
                $user = $app->oauth->user();
            }
            session([$wechatCacheKey => $user]);
        }
        return $next($request);
  }
登录后复制

注:这个例子只是写了授权的逻辑,token相关验证我已经做了剔除

坑点:

以上就是laravel前后端分离获取微信授权,结合laravel-wechat的详细内容,更多请关注Work网其它相关文章!

08-29 11:32