实现效果:
实现流程:
1、注冊QQ互联开发人员
注冊成为开发人员(须要审核)
2、审核通过之后
申请应用(须要互联人员审核*须要备案成功的线上域名)
以下我们開始下载QQsdk包
我下载的是php的
下载之后放在域名根文件夹下
訪问 域名/Connect2.1
输入appId 、appkey 、以及回调地址:域名/Connect2.1/callpack.php(也能够依照样例面试试) 一般仅仅点击 getuserinfo
完毕
优化SDK包
1、将em../auth/callbac.php 放到connect2.1文件夹下 将除了API文件夹以外的文件夹所有删除 并将API下的所有文件及文件夹移动到connect2.1/下 删除API
2、打开 qqConnectAPI.php 改动
<?php
session_start();
/* PHP SDK
* @version 2.0.0
* @author connect@qq.com
* @copyright © 2013, Tencent Corporation. All rights reserved.
*/
//require_once(dirname(__FILE__)."/comm/config.php");
//改动ROOT 为QQ_CONNECT_ROOT
//改动CLASS_PATH 为 QQ_CLASS_PATH 为了避免与本地项目常量冲突 将整个个connect2.1下的所有替换
define("QQ_CONNECT_ROOT",dirname(__FILE__)."/");
define("QQ_CLASS_PATH",QQ_CONNECT_ROOT."class/");
require_once(QQ_CLASS_PATH."QC.class.php");
3、删除comm 下的conf.php 以及utils.php
4.改动 class 下的Recorder.class.php
public function __construct(){
$this->error = new ErrorCase();
//将comm/下的inc.php 信息 复制过来 并删除inc.php 并删除comm文件夹
$incFileContents = '{"appid":"101337757","appkey":"f6588ae8cc52093202d92f6ee33d9af9","callback":"http://www.qqq.com/callback.php","scope":"get_user_info","errorReport":true,"storageType":"file","host":"localhost","user":"root","password":"root","database":"test"}'
//-------读取配置文件
//$incFileContents = file(ROOT."comm/inc.php");
// $incFileContents = $incFileContents[1];
// $this->inc = json_decode($incFileContents);
/********/
//将上列的contents 转位下列的模式
$this->inc->appid = "101337757";
$this->inc->appkey = "f6588ae8cc52093202d92f6ee33d9af9";
$this->inc->callback = "http://www.qqq.com/callback.php";
$this->inc->scope = "get_user_info";
$this->inc->errorReport = true;
$this->inc->storageType = "file"
$this->inc->host = "localhost";
$this->inc->user = "root";
$this->inc->password = "root";
$this->inc->database = "test";
/********/
if(empty($this->inc)){
$this->error->showError("20001");
}
if(empty($_SESSION['QC_userData'])){
self::$data = array();
}else{
self::$data = $_SESSION['QC_userData'];
}
}
完毕!
在根文件夹下定义:
function.php
<?php
/**
* [debug 调试输出函数]
* @param [mix] $val [调试输出源]
* @param [bool] $dump [是否启用var_dump调试]
* @param boolean $exit [是否在调试结束后设置断点]
* @return [void]
*/
function debug($val,$dump=flase,$exit=true){
//自己主动或区域调试函数名称$func
if($dump){
$func = 'var_dump';
}else{
$func = (is_array($val) || is_object($val)) ? 'print_r' : 'printf';
}
//输出到html
header("Content-type:text/html;charset=utf-8");
echo "<pre>debug output:<hr/>";
$func($val);
echo '</pre>';
if($exit) exit;
}
?>
定义:qqlogin.php
<?
php require_once 'function.php'; require_once 'Connect2.1/qqConnectAPI.php'; //訪问QQ的登录页面 $oauth = new Oauth(); $oauth->qq_login(); ?>
建立index.html
将qq登陆图片放入页面中、点击跳入到qqlogin.php
改动callback.php
<?php
require_once("./qqConnectAPI.php");
$qc = new QC();
echo $qc->qq_callback();
echo $qc->get_openid();
完毕!。。。!!
项目中截图调取API 演示样例 :