适用于thinkphp5.1thinkphp6.0的社会化登录扩展
目前已支持:QQ、微信、新浪、百度、Gitee、Github、Oschina、Google、Facebook、淘宝
安装(扩展包)composerrequireliliuwei/thinkphp-social配置Config信息//安装之后会在config目录里自动生成social.php配置文件<?phpreturn[//腾讯QQ登录配置'qq'=>['app_key'=>'*******',//应用注册成功后分配的APPID'app_secret'=>'*******',//应用注册成功后分配的KEY'callback'=>'https://www.youquanya.com/oauth/callback/type/qq',//应用回调地址],//微信扫码登录配置'weixin'=>['app_key'=>'*******',//应用注册成功后分配的APPID'app_secret'=>'*******',//应用注册成功后分配的KEY'callback'=>'https://www.youquanya.com/oauth/callback/type/weixin',//应用回调地址],];用法示例<ahref="{:url('Oauth/login',['type'=>'qq'])}">QQ登录</a><ahref="{:url('Oauth/login',['type'=>'sina'])}">新浪微博登录</a><ahref="{:url('Oauth/login',['type'=>'weixin'])}">微信登录</a><ahref="{:url('Oauth/login',['type'=>'baidu'])}">百度登录</a><ahref="{:url('Oauth/login',['type'=>'gitee'])}">gitee登录</a><ahref="{:url('Oauth/login',['type'=>'github'])}">github登录</a><ahref="{:url('Oauth/login',['type'=>'oschaina'])}">oschaina登录</a><ahref="{:url('Oauth/login',['type'=>'google'])}">google登录</a><ahref="{:url('Oauth/login',['type'=>'facebook'])}">facebook登录</a><ahref="{:url('Oauth/login',['type'=>'taobao'])}">淘宝登录</a>//设置路由Route::get('oauth/callback','index/oauth/callback');<?phpnamespaceapp\index\controller;usethink\Controller;classOauthextendsController{//登录地址publicfunctionlogin($type=null){if($type==null){$this->error('参数错误');}//获取对象实例$sns=\liliuwei\social\Oauth::getInstance($type);//跳转到授权页面$this->redirect($sns->getRequestCodeURL());}//授权回调地址publicfunctioncallback($type=null,$code=null){if($type==null||$code==null){$this->error('参数错误');}$sns=\liliuwei\social\Oauth::getInstance($type);//获取TOKEN$token=$sns->getAccessToken($code);//获取当前第三方登录用户信息if(is_array($token)){$user_info=\liliuwei\social\GetInfo::getInstance($type,$token);dump($user_info);//获取第三方用户资料$sns->openid();//统一使用$sns->openid()获取openid//$sns->unionid();//QQ和微信、淘宝可以获取unioniddump($sns->openid());echo'登录成功!!';echo'正在持续开发中,敬请期待!!';}else{echo"获取第三方用户的基本信息失败";}}}
评论