ecshop微信登录php代码,Ecshop微信登陆

我这是做的手机目录下的

1.在mobile下面(require(dirname(__FILE__) . '/includes/init.php');之后)粘贴这段代码

2.在users表加上wx_open_id字段(varchar累类型)

1.[代码][PHP]代码

$appid = '';

$secret ='';

if((!isset($_SESSION['wechat_id']) || $_SESSION['wechat_id']==null) && !$_SESSION['user_id'] && !$_CFG['shop_reg_closed']){

$code=isset($_GET['code'])?$_GET['code']:null;

$url = urlencode("http://mall.58zcm.com/mobile/index.php");

if($code==null){

$str="https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri=".$url."&scope=snsapi_base&state=123&response_type=code#wechat_redirect";

//echo $str;exit;

header ("Location:".$str);

}else{

$str="https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$secret}&code=".$code."&grant_type=authorization_code";

$ch = curl_init() ;

curl_setopt($ch, CURLOPT_URL, $str);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //将curl_exec()获取的信息以文件流的形式返回,而不是直接输出。

$output = curl_exec($ch);

$output=json_decode($output,true);

$_SESSION['wechat_id']=$output['openid'];

}

}

//unset($_SESSION['user_id']);exit;

/*授权登陆 注册*/

if(!$_SESSION['user_id'] && $_SESSION['wechat_id'] && !$_CFG['shop_reg_closed']){

$openid = $_SESSION['wechat_id'];

$sql = "SELECT * FROM".$ecs->table('users')." where wx_open_id = '".$openid."'";

$row = $db->getRow($sql);

if($row){

$username = $row['user_name'];

$password = $row['user_name'];

if ($user->login($username, $password)){

update_user_info();

recalculate_price();

}

}else{//注册

include_once(ROOT_PATH . 'mobile/includes/lib_passport.php');

$username = 'wx_'.time();

$password = 'wx_'.time();

$email = 'wx_login'.time().'@qq.com';

if (register($username, $password, $email) !== false){

$sql = "UPDATE ".$ecs->table('users')." SET wx_open_id = '".$openid."' WHERE user_id = '".$_SESSION['user_id']."'";

if(!$db->query($sql)){

unset($_SESSION['user_id']);

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值