qq登陆
来源:互联网 发布:移动电源检测软件 编辑:程序博客网 时间:2024/04/30 22:04
<?php// =============qq登陆(仅供测试使用)==============$qq = new QQ;if( !isset($_GET['code']) ){$qq->login();}else{$qq->access_token($_GET['code']);$qq->get_user_info(); // 获取用户信息。}class QQ{private $appid,$appkey,$redirect_uri,$access_token,$openid,$img;public function __construct(){$this->appid = "";$this->appkey = "";$this->redirect_uri = "http://www.useryx.net";$this->img = "./qq_login.png"; // qq登陆图片echo '<html><head><meta charset="UTF-8"><meta property="qc:admins" content="126626657765352106654" /></head><body>';}// 测试public function html($url){// 等同于加载模板echo '<a href="'.$url.'"><img src="'.$this->img.'" alt="QQ登陆"></a>';}// qq登陆,页面public function login(){// $this->ceshi(); exit; // 此处打开做验证。默认关闭。$url = "https://graph.qq.com/oauth2.0/authorize";$array = array( "response_type" => "code", "client_id" => $this->appid, "redirect_uri" => $this->redirect_uri, "state" => time(), "scope" => "get_user_info,get_info,add_t,del_t,add_pic_t,get_repost_list,get_other_info,get_fanslist,get_idollist,add_idol,del_idol", // 以获取的权限。 );$url = $url.'?'.http_build_query($array);$this->html($url);}public function access_token($code){$url = "https://graph.qq.com/oauth2.0/token";$array = array("grant_type" => "authorization_code","client_id" => $this->appid,"client_secret" => $this->appkey,"code" => $code,"redirect_uri" => $this->redirect_uri,);$url = $url.'?'.http_build_query($array);$token = file_get_contents($url);// 获取token,解析字符串$a = explode("&",$token);for ($i=0; $i < count($a); $i++) { $ar = explode("=",$a[$i]);$arr[$ar[0]] = $ar[1];}$this->access_token = $arr['access_token'];$this->openid();}// 用户基础信息。public function openid(){$url = "https://graph.qq.com/oauth2.0/me?access_token=$this->access_token";$str = file_get_contents($url);// 正则匹配preg_match("/{.*}/i",$str,$m); $user = json_decode($m[0],true);// echo '<pre>用户基础信息为:<br>';// print_r($user);// echo '<pre>';$this->openid = $user['openid'];}public function get_user_info(){$url = "https://graph.qq.com/user/get_user_info?";$array = array("access_token" => $this->access_token,"oauth_consumer_key" => $this->appid,"openid" => $this->openid,);$get_user_info = file_get_contents($url.http_build_query($array));$get_user_info = json_decode($get_user_info,true);echo '<pre>';print_r($get_user_info);}// 析构方法public function __destruct(){echo "</body></html>";}}
0 0
- QQ 登陆
- qq登陆
- qq登陆
- QQ登陆
- qq登陆
- QQ登陆,获取QQ用户信息
- 清除QQ登陆记录
- QQ登陆助手
- MSN,QQ网上登陆
- QQ登陆批处理
- 用批处理登陆QQ
- QQ防盗登陆器
- QQ登陆加密算法
- QQ批量自动登陆
- QQ登陆界面
- QQ登陆界面
- QQ登陆界面
- QQ登陆界面
- 插件开发技术(9)---SQL查询记录与对象的映射
- phonegap(cordova)在ios系统实现录音功能的几种特殊情况
- Objective-C----实例变量
- linux环境下python 库模块安装
- Search Insert Position
- qq登陆
- Scala数组操作
- 给cell 添加阴影
- 最长回文字串
- java正则表达式验证
- 用Kinect实现人脸动画
- Mybaits的Jave API
- PostgreSQL pgcrypto模块加密解密函数
- 每天一次IO流复习