https://www.cnblogs.com/zzdylan/p/5922477.html
首先composer安装依赖:
composer require socialiteproviders/qq
注册服务提供者(同时注释掉原有的Socialite提供者):
'providers' => [
// 移除 'LaravelSocialiteSocialiteServiceProvider',
SocialiteProvidersManagerServiceProvider::class, // 添加
];
添加Socialite门面(如果已有略过本操作):
'Socialite' => LaravelSocialiteFacadesSocialite::class,
添加事件监听器(App/Providers/EventServiceProvider
):
protected $listen = [
'SocialiteProvidersManagerSocialiteWasCalled' => [
'SocialiteProvidersQqQqExtendSocialite@handle',//这里的SocialiteProvidersQqQqExtendSocialite@handle,里面有个q改成大写
'SocialiteProvidersQQQqExtendSocialite@handle',//改成这样就对了,之前如果那个q是小写的话会报找不到类的错误。
], ];
在config/services.php中添加:
'qq' => [
'client_id' => env('QQ_KEY'),
'client_secret' => env('QQ_SECRET'),
'redirect' => env('QQ_REDIRECT_URI'),
],
在.env中添加:
QQ_KEY=101331049
QQ_SECRET=1fabaf75e41336b41ab1bbd65d3b3e57
QQ_REDIRECT_URI=http://schoolshop.51gogo.club/qqlogin
QQ_KEY和QQ_SECRET需要在qq互联上申请,QQ_REDIRECT_URI需要在qq互联上设置。
这里的回调地址必须要跟qq互联管理中心(https://connect.qq.com)设置的回调地址一样。
路由:
Route::get('/qqlogin','TestController@qqlogin');
Route::get('/qq','TestController@qq');
控制器:
public function qq(){
return Socialite::with('qq')->redirect();
}
public function qqlogin(){
$user = Socialite::driver('qq')->user();
dd($user);
}
访问方法“qq”对应的路由:
成功获取用户资料: