zoukankan      html  css  js  c++  java
  • 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,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,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 丢失问题 如有知道怎么解决的 请指导  感激不尽

  • 相关阅读:
    5
    4
    2
    3
    1
    IOS js交互
    vm安装mac
    索引
    ORM 基础
    reids 日志no
  • 原文地址:https://www.cnblogs.com/yxbs/p/2889196.html
Copyright © 2011-2022 走看看