ecshop qq互联登录OAuth2.0

下载最新的sdk

http://wiki.open.qq.com/wiki/website/SDK%E4%B8%8B%E8%BD%BD

然后我把最新的sdk文档里面的有用的程序包直接上传进了 /api/里面然后 分别登陆 处理 、返回文件 分别写在了 qqlogin.php 文件里面 目录结构注意看下面的程序require部分。

<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/user.php');
require(ROOT_PATH.'api/QQConnect/API/qqConnectAPI.php');
$user_id = $_SESSION['user_id'];
$action  = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'default';
$qc = new Qc();
if($action == 'default')
{
    $qc->qq_callback();
    $open_id =  $qc->get_openid();
    //根据 OPEN_ID 判断数据
    $sql = "SELECT * FROM".$ecs->table('users')." where qq_open_id = '".$open_id."'";
    $row = $db->getRow($sql);
    if($row)
    {
        //曾经登陆过,存在信息 ,调用信息登录
        $username = $row['user_name'];
        $password = $row['user_name'];

        if ($user->login($username, $password,isset($_POST['remember'])))
        {
            update_user_info();
            recalculate_price();

            $ucdata = isset($user->ucdata)? $user->ucdata : '';
            show_message($_LANG['login_success'] . $ucdata , array($_LANG['back_up_page'], $_LANG['profile_lnk']), array($back_act,'user.php'), 'info');
        }
        else
        {

            show_message($_LANG['login_failure'], $_LANG['relogin_lnk'], '#" onClick="Hongru.box.open(document.getElementById(\'dengludiv\').innerHTML,{isBar:0,width:0,height:0})" ', 'error');
        }



    }else
    {
        //注册新用户
        include_once(ROOT_PATH . 'includes/lib_passport.php');

        $username = 'qq_'.time();
        $password = 'qq_'.time();
        $email    = 'qq_login'.time().'@qq.com';
        $other['qq_open_id'] = $open_id;

        if (register($username, $password, $email, $other) !== false)
        {
            //$user = $qc->get_user_info();


            header("Location:flow.php");
            die();
        }
        else
        {
            show_message('QQ登陆异常,请联系网站人员! ');
            exit();
        }

    }

    //处理QQ 登陆的用户的信息

}elseif($action == 'login')
{
    if($_SESSION['user_id']>0)
    {
        show_message('您已经登录了! ');
        header("Location:/");
    }else
    {
        $qc->qq_login();
    }

}