您的位置:首页 > 其它

第三方登录示例

2017-02-17 16:43 260 查看
  实现效果:







实现流程:

1、注册QQ互联开发者

QQ互联官网

注册成为开发者(需要审核)

2、审核通过之后



申请应用(需要互联人员审核*需要备案成功的线上域名)



下面我们开始下载QQsdk包

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] view
plain copy print?





<?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 

 

[php] view
plain copy print?





    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);  

          

/********/  <
17036
/span>

        //将上列的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] view
plain copy print?





<?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] view
plain copy print?





<?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] view
plain copy print?





<?php  

require_once("./qqConnectAPI.php");  

$qc = new QC();  

echo $qc->qq_callback();  

echo $qc->get_openid();  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: