完成开发者认证申请腾讯开放平台使用qq登录完成实名认证,点击createapplication创建网站应用并填写相关信息回调字段填写很重要如果填写扫码错误,会出现100010【QQ登录】登录前端常见错误代码这是网站当前访问的qq登录。Note1.好像涉及**appkey**的接口是不能通过客户端提交的。我猜是因为腾讯的认知。**appkey**在前端调用不安全,得用后台调用。2、获取**access_token**时,前端可以通过**window.location.href**='腾讯获取access_token的url地址',腾讯会返回**access_token**给html,但是是不好获取,当然也可以用正则表达式匹配,但是我觉得这样获取的姿势不太对。我目前的方法是在服务端获取**access_token**获取,然后返回给客户端。//qq登录完整代码import{token,qquserinfo}from'@servers/qq';import{qqlogin}from'@servers/login/login.js';importjsonpfrom'jsonp';constapp_cinfig={appid:******,appkey:'********************',redirecturi:'https://www.vipbic.com/qq.html',state:'******',url:'https://graph.qq.com/oauth2.0',scope:'******',client_id:'',openid:'',}lethome='/index.html'letcode=window.globalSelf.utils.getQueryString('code');//code等于空,表示第一个入口if(!code){leturl=app_cinfig.url+'/authorize?response_type=code&client_id='+app_cinfig.appid+'&redirect_uri='+app_cinfig.redirecturi+'&state='+app_cinfig.state+'&scope='+app_cinfig.scope;window.location.href=url//qq会携带code返回域名这样https://www.vipbic.com/qq.html?code=3FC4EDAEADC5668A549317C8CDEE946E}else{token({code}).then((res)=>{//jsonp是git库上开源的,跨域请求很方便jsonp(app_cinfig.url+'/me?access_token='+res,{name:'callback'},函数(错误,数据){如果(错误)抛出错误;让{client_id,openid}=数据;app_cinfig.client_id=client_id;app_cinfig.openid=openid;qquserinfo({token:res,openid}).then((res)=>{letdata=JSON.parse(res);console.log(data)//打印出qq个人信息})});}).catch(()=>{window.location.href=home})}后台服务器在获取的时候没有遇到什么大问题。正常发起request网络请求,一切正常。//后台qq登录publicfunction__construct(Request$request=null){$this->url=config('qq.url');$this->appid=config('qq.appid');$this->redirecturi=config('qq.redirecturi');$this->appkey=config('qq.appkey');$this->state=config('qq.state');父母::__构造($请求);}//启动url访问保护函数url_get($url){returnfile_get_contents($url,false);}//获取access_token公共函数肯(){$代码=输入('代码');$url=$this->url.'/token?grant_type=authorization_code&client_id='.$this->appid.'&client_secret='.$this->appkey.'&code='.$code.'&state='.$this->state.'&redirect_uri='.$this->redirecturi;$res=$this->url_get($url);$data=(explode('=',(explode('&',$res))[0]))[1];//&分割符串成数字组returnkeyShow($data);}//获取qq用户信息publicfunctionqquserinfo(){$token=input('token');$openid=input('openid');$url='https://graph.qq.com/user/get_user_info?access_token='.$token.'&oauth_consumer_key='.$this->appid.'&openid='.$openid;$data=$this->url_get($url);返回键显示($数据);}