admin管理员组

文章数量:1657214

qq互联官网文档地址:

基本流程:

在qq互联官网申请开发者,审核通过后创建网站应用,网站应用审核通过后会有app id 和 app key 然后所有qq账号的数据都是通过这两个去获取。

都是封装好的函数,直接调用就可以实现各种功能了。

一键登录代码://先放置一键登录qq图片,和打开qq登录界面oa授权地址,参数回调地址

οnclick="javascript:window.open('

client_id=appID&redirect_uri=

state=65c747f767&scope=get_user_info','_self')" width="150">

//QQ回调地址代码:

ini_set('display_errors','on');

include_once( '../../config.php' );//引入qqDemo配置文件

//qq api开始

$code = $_GET['code'];

$state = $_GET['state'];//接收来自点击一键登录按钮后传过来的参数

if(empty($code)||empty($state)){

echo '';

exit;

}else{

//通过code和state的参数获取token

$token = file_get_contents("https://graph.qq/oauth2.0/token?grant_type=authorization_code&client_id

=12345&client_secret=1e29c4cd120e&code=".$code."&redirect_uri="

.urlencode('http://www.zixuephp/qq/index.php'));

$token_arr = explode('&',$token);

$token0 = explode('=',$token_arr[0]);

if($token0){

//通过token获取qq的唯一openid,token有生存时间

$token0 = $token0[1];

$openid = file_get_contents("https://graph.qq/oauth2.0/me?access_token=".$token0);

$id = explode('"',$openid);

$ids = $id[7];

//通过openid获取qq用户信息

$get_info = file_get_contents("https://graph.qq/user/get_user_info?oauth_consumer_key=

12345&access_token={$token0}&openid={$ids}&format=json");

$userinfo = json_decode($get_info);

$userinfo = (array)$userinfo;

$uid = $ids;

$name = $userinfo['nickname'];

$head = $userinfo['figureurl_qq_2'];

//通过查询保存数据库的openid判断用户之前有没有登录过

$res = $dbh->query("select * from user where other_id='qq_{$uid}'");

$u = $res ->fetch();

if($u){

session_write_close();

session_start();

$_SESSION['account']=$u['account'];

$_SESSION['uid']=$u[0];

header("Location:iphp.php");

exit;

}

?>

//如果是第一次登录则进行数据保存到数据库

html>

QQ一键登录

----------QQ一键登陆授权成功,信息设置----------

邮箱设置

密码设置

" />

" />

" />

确定

$('#set').click(function(){

var email = $('input[name=account]').val();

var pw = $('input[name=passwd]').val();

var ou_id = $('input[name=ou_id]').val();

var sname = $('input[name=sname]').val();

var head = $('input[name=head]').val();

$.ajax({

type:'post',

url:'reg_process.php',

data:{

'email':email,

'pw':pw,

'ou_id':ou_id,

'sname':sname,

'head':head

},

success:function(data){

if(data=='登陆成功!'){

$('.logintips span').text('登陆成功!3s后自动关闭窗口...');

setTimeout(function(){

window.close();

},3000);

}else{

$('.logintips span').text(data);

}

},error:function(){

$('.logintips span').text('请求出错!');

}

});

});

}else{

echo '';

exit;

}

}

?>

QQ登录的优点,通过“QQ登录”,用户能使用QQ帐号一键登录接入网站,大大降低了用户注册、登录的门槛,借助庞大的QQ用户群,给第三方网站带来更多新用户。

已登录用户还可以将在第三方网站发布、分享的信息即时同步到QQ空间,使网站内容通过好友关系得到进一步的传播,从而提升网站的访问量和用户数。

来源:QQ互联

本文标签: 一键功能网页网站PHP