ecshop 整合 QQ登陆 和 支付宝快捷登陆代码

首先 目录结构

我基本上是把 文档里面的 有用的直接上传进了 /api/里面然后 分别登陆 处理 、返回文件 分别写在了 qqlogin.php  和 alipaylogin.php 文件里面

QQ

<?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();
    }
    
}

支付宝的

<?php
define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
require_once("/api/alipay/alipay.config.php");
require_once("/api/alipay/lib/alipay_notify.class.php");

$user_id = $_SESSION['user_id'];


//计算得出通知验证结果
$alipayNotify = new AlipayNotify($alipay_config);
$verify_result = $alipayNotify->verifyReturn();
if($verify_result) {

    //验证成功

    //支付宝用户号

    $open_id = $_GET['user_id'];
    $real_name = $_GET['real_name'];
    //授权令牌
    $token = $_GET['token'];
    
    $_SESSION['is_alipay'] = 1;
    //根据 OPEN_ID 判断数据
    $sql = "SELECT * FROM".$ecs->table('users')." where alipay_open_id = '".$open_id."'";
    $row = $db->getRow($sql);

    if($row)
    {
        //曾经登陆过,存在信息 ,调用信息登录
    
        $username = $row['user_name'];
        $password = $row['$open_id'];
    
        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
        {
            $_SESSION['login_fail'] ++ ;
            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 = $real_name;
        $password = $open_id;
        $email    = 'alipay'.time().'@alipay.com';
        $other['alipay_open_id'] = $open_id;
    
        if (register($username, $password, $email, $other) !== false)
        {            
            header("Location:flow.php");
            die();
        }
        else
        {
            show_message('登陆异常,请联系网站人员! ');
            exit();
        }
    
    }

}
else {
    //验证失败
    //如要调试,请看alipay_notify.php页面的verifyReturn函数
    echo "验证失败,请联系管理人员!";
}

360 存在 session 丢失问题 如有知道怎么解决的 请指导  感激不尽

 

转载于:https://www.cnblogs.com/yxbs/archive/2013/02/01/2889196.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值