<?php
/**
* 腾讯免登-直连2.0(优品诚)
*
* @version 2.0
* @author upincheng@gmail.com
* @copyright © 2011, Upin99 Corporation. All rights reserved.(http://www.upin99.com)
*/
class shop_upc_qq_directct extends shopPage{
var $noCache = true;
var $appid;
var $appkey;
function shop_upc_qq_directct(){
$this->system = &$GLOBALS['system'];
$this->db = &$this->system->database();
$this->appid = $this->system->getConf('app.upc_qq_directct.appid');
$this->appkey = $this->system->getConf('app.upc_qq_directct.appkey');
$this->sUri = str_replace("index.php?action_upc_qq_directct-login.html", "index.php?action_upc_qq_directct-relogin.html", $_SERVER["REQUEST_URI"]);
}
function nowredirect($status='success',$url,$msg="",$json=false){
if($status!='failed'){
if($json){
echo json_encode(array('status'=>$status, 'url'=>$url));
}else{
$url = $this->system->mkUrl("cart","checkout",array(1));
if($_COOKIE['Cart_Fastbuy']){
echo "<script>opener.location.href = '".$url."'; window.close();</script>";
}else{
echo "<script>opener.location.reload(); window.close();</script>";
}
}
}else{
if($json){
echo json_encode(array('status'=>'failed', 'msg'=>$msg));
exit;
}else{
$url = $this->system->mkUrl('passport','login',array($url,base64_encode(str_replace(array('+','/','='),array('_',',','~'),$msg))));
echo "<script>opener.location.href = '".$url."'; window.close();</script>";
exit;
}
}
}
function login(){
$this->wedb = DB_PREFIX;
$sState = md5(date("YmdHis".$this->getip()));
$this->system->setCookie('state',$sState);
$this->system->setCookie('URI',$this->sUri);
$aParam = array(
"response_type" => "code",
"client_id" => $this->appid,
"redirect_uri" => $this->sUri,
"state" => $sState
);
$aGet = array();
foreach($aParam as $key=>$val){
$aGet[] = $key."=".urlencode($val);
}
$sUrl = "https://graph.qq.com/oauth2.0/authorize?";
$sUrl .= join("&",$aGet);
header("location:".$sUrl);
}
function relogin(){
$this->wedb = DB_PREFIX;
$sUrl = "https://graph.qq.com/oauth2.0/token";
$aGetParam = array(
"grant_type" => "authorization_code",
"client_id" => $this->appid,
"client_secret" => $this->appkey,
"code" => $_GET["code"],
"state" => $_GET["state"],
"redirect_uri" => $this->sUri
);
$sContent = $this->get($sUrl,$aGetParam);
if($sContent!==FALSE){
$aTemp = explode("&", $sContent);
$aParam = array();
foreach($aTemp as $val){
$aTemp2 = explode("=", $val);
$aParam[$aTemp2[0]] = $aTemp2[1];
}
$this->system->setCookie('access_token',$aParam["access_token"]);
$sUrl = "https://graph.qq.com/oauth2.0/me";
$aGetParam = array(
"access_token" => $aParam["access_token"]
);
$sContent = $this->get($sUrl, $aGetParam);
if($sContent!==FALSE){
$aTemp = array();
preg_match('/callback\(\s+(.*?)\s+\)/i', $sContent,$aTemp);
$aResult = json_decode($aTemp[1],true);
$this->system->setCookie('openid',$aResult["openid"]);
$sUrl = "https://graph.qq.com/user/get_user_info";
$aGetParam = array(
"access_token" => $aParam["access_token"],
"oauth_consumer_key" => $this->appid,
"openid" => $aResult["openid"],
"format" => "json"
);
$sContent = $this->get($sUrl,$aGetParam);
if($sContent!==FALSE){
$aResultn = json_decode($sContent,true);
}
}
}
if($aResult["openid"]){
$user = $this->db->selectrow('select member_id from '.$this->wedb.'upc_qq_directct_user where openid = "'.$aResult["openid"].'"');
if($user['member_id']){
$sql = 'update '.$this->wedb.'members set uname = "'.$aResultn["nickname"].'" where member_id='.$user['member_id'];
$this->db->exec($sql);
}else{
$insert = true;
$data['uname'] = $aResultn["nickname"];
$data['email'] = $aResultn['nickname'].'@qq.com';
$data['password'] = time();
$data['member_refer'] = 'QZONE';
$data['refer_id'] = 'QQ';
$data['regtime'] = time();
$data['reg_ip'] = $_SERVER["REMOTE_ADDR"];
$mem_level = $this->system->loadModel('member/level');
$data['member_lv_id'] = $mem_level->getDefauleLv();
// $data['member_lv_id'] = 5;
$data['cur'] = 'CNY';
$data['lang'] = NULL;
$rs = $this->db->query('SELECT * FROM '.$this->wedb.'members WHERE 0=1');
$sql = $this->db->GetInsertSQL($rs, $data);
if($this->db->exec($sql)){
$member_id = $this->db->lastInsertId();
$aData['member_id'] = $member_id;
$aData['openid'] = $aResult["openid"];
$rs_user = $this->db->query('SELECT * FROM '.$this->wedb.'upc_qq_directct_user WHERE 0=1');
$sql_user = $this->db->GetInsertSQL($rs_user, $aData);
$rrr = $this->db->exec($sql_user);
$user['member_id'] = $member_id;
}
}
$member = $this->system->loadModel('member/account');
$user_data = $this->db->selectrow('select * from '.$this->wedb.'members where member_id = '.$user['member_id']);
$user_data['secstr'] = $member->cookieValue($user_data['member_id']);
$this->system->setCookie('REFER','QQ');
$this->system->setCookie('REFER_IMAGE','<img src="'.$this->system->base_url().'/plugins/app/upc_qq_directct/image/Connect_logo_1.png" width="16px" height="16px">');
$this->system->setCookie('MEMBER',$user_data['secstr']);
$this->system->setCookie('UNAME',$user_data['uname']);
$this->system->setCookie('MLV',$user_data['member_lv_id']);
$this->system->setCookie('CUR',$user_data['cur']);
$this->system->setCookie('LANG',$user_data['lang']);
if($user_data)
{
if(isset($_REQUEST['forward']) && $_REQUEST['forward'])
{
$url = $_REQUEST['forward'].DEFAULT_INDEX;
}
elseif(isset($_POST['ref_url']) && $_POST['ref_url'])
{
$url = $_POST['ref_url'];
}
else
{
$url = $this->system->base_url();
}
$cart_count = unserialize($user_data['addon']);
$cart_count = count(explode(',',$cart_count['cart']));
$this->system->setCookie('CART_COUNT',$cart_count,null);
//购物车数量
$oCart = &$this->system->loadModel('trad
shopex中qq登录插件
需积分: 3 189 浏览量
2014-12-01
17:00:54
上传
评论
收藏 26KB RAR 举报
艾瑞可erik
- 粉丝: 28
- 资源: 89
最新资源
- 1.5数据透视进阶:切片器关联与二次计算
- 1.6 可视化入门:各类基础图表全实操
- 深度剖析C编程 初级+中级+高级 基础+数据结构源码+组成原理+操作系统及C语言高级
- HM深度技术剖析 JAVA Web全新维度 最新JAVA Web全面开发课程 最新技术与综合实战课程
- 3000多集 5门计算机考研课程全面升级 C语言+数据结构+组成原理+计算机网络+操作系统
- 系统级别的专业晋级之途 嵌入式工程师Linux系统编程深度培训与自我进阶企业级实战
- 41小时全新华为HCIA-datacom认证课程 数据通信的深度探索 华为数据通信深度探索
- Flutter实践工程自动化!深度研究与实 高级Logic iOS Flutter逻辑开发与引擎源码
- 基于matlab实现DICM程序,包含数字图像相关算法的全部流程,可用于位移和应变的检测.rar
- 基于matlab实现CPP该代码在ncorr数字图像相关代码的基础上,对应变云的色彩效果进行了改进,并添加了应变注释 .rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈