QQ登录简单实现代码

#ThinkPHPadmin  最后发表时间:2017-05-31

qq登录很简单 先要去qq互联申请,通过后有key,然后是下面的代码

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="__PUBLIC__/index/layui/css/layui.css">
<script src="__PUBLIC__/index/layui/layui.js" type="text/javascript"></script>
<script type="text/javascript" src="http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" data-appid="999999999" data-redirecturi="http://www.zeadmin.com/login/userqq.html" charset="utf-8"></script>
</head>
<body>
<script type="text/javascript">
layui.use(['layer'], function(){
	var layer = layui.layer,
	$ = layui.jquery;
	var	is_login = QC.Login.check();
	if(is_login){
		var access_token = '999999999666666666';
		var openid = '999999999';
		QC.Login.getMe(function(openId, accessToken){
			access_token = accessToken;
			openid = openId;
		});
		var paras = {oauth_consumer_key:'999999999',access_token:access_token,openid:openid};
		QC.api('get_user_info', paras).success(function(s){
			//成功回调,通过s.data获取OpenAPI的返回数据
			var	param ={openid:openid,username:s.data.nickname,userhead:s.data.figureurl_qq_2,sex:s.data.gender};
			//console.log(s);
			$.post('{:url("login/loginqq")}',param,function(res){
		      if(res.code == 200){
		      	QC.Login.signOut()//注销qq登陆
				layer.msg(res.msg, {icon: 1, anim: 6, time: 1000},function(){
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index); //再执行关闭
				});

		      }else{
		        layer.msg(res.msg, {icon: 2, anim: 6, time: 1000});
		      }
		    });
			
			//alert("获取用户信息成功!当前用户昵称为:"+s.data.nickname);
		});

	}else{ 
		self.location.href='https://graph.qq.com/oauth2.0/authorize?client_id=999999999&response_type=token&scope=all&redirect_uri='+encodeURIComponent(self.location.href);
	}
});
	
</script>
</body>
</html>

来源于 tpt360的分享。




上一篇:关于tp程序换成php7或以上时出现的问题

下一篇:TP6的路由怎么实现?我写一个简单教程。

发表评论

0 个回复