laravel 5.2 overtrue/socialite QQ登录和微博登录遇到的问题

用了overtrue/socialite 进行第三方登陆,有时候登录就出现这样的错误,有没有遇到相同问题的,求解答,有时候可以正常登录有时候就报错

php代码

    /**
     * QQ登录
     */
    public function qqLogin(){
        $this->otherLogin('qq',1);
        return redirect('/');
    }

    /**
     * 第三方登录
     * @param unknown $name 第三方登录名称
     * @param unknown $type 登录类型 1QQ 2微博
     * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
     */
    public function otherLogin($name, $type){
        $socialite = new SocialiteManager(config('services'));
        $clientUser = $socialite->driver($name)->user();
        $user = User::where('account',$clientUser->getId())->first();
        if (!$user){
            $user = User::create([
                    'account' => $clientUser->getId(),
                    'password' => bcrypt(str_random(16)),
                    'name' => $clientUser->getNickname(),
                    'login_type' => $type,
                    'avatar' => $clientUser->getAvatar(),
            ]);
        }
        \Auth::login($user);
    }

错误如下

Whoops, looks like something went wrong.
1/1 InvalidStateException in AbstractProvider.php line 170:

    in AbstractProvider.php line 170
    at AbstractProvider->user() in LoginController.php line 56
    at LoginController->otherLogin('qq', '1') in LoginController.php line 36
    at LoginController->qqLogin()
    at call_user_func_array(array(object(LoginController), 'qqLogin'), array()) in Controller.php line 80
    at Controller->callAction('qqLogin', array()) in ControllerDispatcher.php line 146
    at ControllerDispatcher->call(object(LoginController), object(Route), 'qqLogin') in ControllerDispatcher.php line 94
    at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
    at Pipeline->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
    at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
    at ControllerDispatcher->callWithinStack(object(LoginController), object(Route), object(Request), 'qqLogin') in ControllerDispatcher.php line 54
    at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\Home\LoginController', 'qqLogin') in Route.php line 174
    at Route->runController(object(Request)) in Route.php line 140
    at Route->run(object(Request)) in Router.php line 724
    at Router->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
    at VerifyCsrfToken->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
    at ShareErrorsFromSession->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
    at StartSession->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
    at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
    at EncryptCookies->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
    at Pipeline->then(object(Closure)) in Router.php line 726
    at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
    at Router->dispatchToRoute(object(Request)) in Router.php line 675
    at Router->dispatch(object(Request)) in Kernel.php line 246
    at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Debugbar.php line 51
    at Debugbar->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
    at CheckForMaintenanceMode->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
    at Pipeline->then(object(Closure)) in Kernel.php line 132
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
    at Kernel->handle(object(Request)) in index.php line 58

已经解决了是我自己的问题,就是顶级域名和二级域名的关系,登录的时候访问的是顶级域名,而qq回调的时候是带www的二级域名,所以才导致的问题,我现在顶级域名重定向为www的二级域名就OK了!

JellyBool
修改的评论也不能少于六个字哦!
尼好再见
修改的评论也不能少于六个字哦!
JellyBool 回复 尼好再见
修改的评论也不能少于六个字哦!
尼好再见 回复 JellyBool
修改的评论也不能少于六个字哦!
JellyBool 回复 尼好再见
修改的评论也不能少于六个字哦!
尼好再见
修改的评论也不能少于六个字哦!
jianqingweng227 回复 尼好再见
修改的评论也不能少于六个字哦!
尼好再见 回复 jianqingweng227
修改的评论也不能少于六个字哦!