Blogger Information
Blog 91
fans 2
comment 4
visits 127854
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
一个控制器让更多的新手程序猿了解QQ登陆原理
夏日的烈风的博客
Original
630 people have browsed it

/声明: 本代码并非完美,也许存在不佳之处,请放肆吐槽!

 //作者: 小曾

 //扣扣: 839024615

 //网址: www.yun8888.net

 //关于我的ThinkPHP http://www.thinkphp.cn/u/87696.html

 //----------------------------------------------------------

 

//登陆模块

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//QQ登陆SDK下载地址 http://connect.qq.com/

//申请时填写回调地址 域名/index.php/Login/qq_callback.html

//下载好SDK解压到 /ORG/  类下目录 或自定的目录

//直接访问SDK下的index.php按提示进行安装

//配置时填写回调地址 域名/index.php/Login/qq_callback.html

//获得权限全打勾,这个可以随便,如果你要发微博关注等就勾上

//配置完了,把API之外的文件与目录删除 我把API改成Connect

//把qqConnectAPI.php 改成 qqConnectAPI.class.php

//引入方法 import('@.ORG.Connect.qqConnectAPI');

//当然用别的方法也一样,由个人喜欢而定哈

//下面根据代码说明 了解QQ登陆的详细原理吧

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

class LoginAction extends Action {

    public function _initialize(){

        //引入QQ登陆类

        import('@.ORG.Connect.qqConnectAPI');

        //实例化

        $this->QC = new QC();

    }

    //开始登陆

    public function qq_login(){

        $this->QC->qq_login();

    }

    //回调

    public function qq_callback(){

        $token  = $this->QC->qq_callback();

        $openid = $this->QC->get_openid();

        $QC = new QC($token,$openid);

        $arr = $QC->get_user_info();

         

        $db=M("Member");

        $where['qq_openid']=$openid;

        //判断此QQ是否注册 唯一标识符openid 在表里加了个qq_openid为唯一哈

        $isqq=$db->where($where)->find();

        if($isqq){

            //写入登陆状态

            session('id', $isqq['id']);

            session('account', $isqq['account']); 

            session('nickname', $isqq['account']);

            session('email', $isqq['email']); 

            session('lastLoginTime', $isqq['lastLoginTime']); 

            session('login_count', $isqq['login_count']); 

            $this->success('登陆成功!',U('Member/index'));

        }else{

            $data['qq_openid']=$openid; //QQ登陆唯openid

            $data['account']=$arr['nickname']; //用户名

            $data['nickname']=$arr['nickname']; //网名

            $data['thumb']=$arr['figureurl_2']; //头像

            $data['status']='1'; //用户状态为启用

            //如果用户名存在

            $name['account']=$arr['nickname'];

            $isname=$db->where($name)->find();

            if($isname){

                //用户名存在添加随机数

                $data['account']=$arr['nickname']."_".rand(1000,9999);

            }

            //判断是否写入成功

            if($id=$db->add($data)){

                //写入登陆状态

                session('id', $id);

                session('account', $data['account']);

                session('nickname', $data['account']);

                session('email', '未填写');

                session('lastLoginTime', time());

                session('login_count', '1');

                $this->success('注册成功!',U('Member/index'));

            }else{

                $this->error('注册失败!',U('Member/login'));

            }    

        }

    }

}

 

 //----------------------------------------------------------

 //声明: 本代码并非完美,也许存在不佳之处,请放肆吐槽!

 //作者: 小曾

 //扣扣: 839024615

 //网址: www.yun8888.net

 //关于我的ThinkPHP http://www.thinkphp.cn/u/87696.html

 //----------------------------------------------------------


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post