HTML页面
http://wiki.connect.qq.com/%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C_oauth2-0
准备工作_OAuth2.0
先做一个登录页面复制QQ互联网的QQ登录地址,在QQ登录中给他一个A标签跳转,然后下面给一个
下为按钮点击事件的逻辑。注意这里要重新打开窗口。然后配置他的文件放在tp五的extend里面
在给他一个回调数,然后再跳转登陆的地方给他引入给他实例化qq的下载包,然后去qq回调里面设置access_token的qq_callback返回来的值再给openind的get_openid让她得到值给他oauth_consumer_key就是创建文档的ID然后放到url里面在file_get_content一下就可以了
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="{:url('Lx/login')}" method="post">
<table>
<tr>
<td>用户:</td>
<td><input type="text" name="user"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pwd"></td>
</tr>
<tr>
<td><input type="submit" value="登录"></td>
<td><a href="#" onclick='toLogin()'><img src="http://qzonestyle.gtimg.cn/qzone/vas/opensns/res/img/Connect_logo_7.png"></a></td>
</tr>
</table>
</form>
</body>
</html>
<script>
function toLogin() {
//以下为按钮点击事件的逻辑。注意这里要重新打开窗口
//否则后面跳转到QQ登录,授权页面时会直接缩小当前浏览器的窗口,而不是打开新窗口
var A=window.open("{:url('lx/QQ_log')}","TencentLogin","width=450,height=320,menubar=0,scrollbars=1,resizable=1,status=1,titlebar=0,toolbar=0,location=1");
}
</script>
public function QQ_log(){
Loader::import('Connect.API.qqConnectAPI');
$qc=new \QC();
$qc->qq_login();
}
public function QQ_back(){
Loader::import('Connect.API.qqConnectAPI');
$qc=new \QC();
$access_token=$qc->qq_callback();
$openid=$qc->get_openid();
// print_r($openid);die;
$url='https://graph.qq.com/user/get_user_info?access_token='.$access_token.'&oauth_consumer_key=101529669&openid='.$openid.'';
$arr=file_get_contents($url,true);
$last_data=json_decode($arr,true);
$str="";
$str.="<p>当前用户的头像是:<img src='".$last_data['figureurl']."' alt=''></p>";
$str.='<p>当前登录用户昵称:'.$last_data['nickname'].'</p>';
$str.='<p>当前登录用户性别:'.$last_data['gender'].'</p>';
$str.='<p>当前登录用户城市:'.$last_data['city'].'</p>';
$str.='<p>当前登录用处出生:'.$last_data['year'].'</p>';
print_r($str);
}