分享更有价值
被信任是一种快乐

phpcms如何实现微信登陆

文章页正文上

本篇内容介绍了“phpcms如何实现微信登陆”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成! phpcms实现微信登录的方法:1、在根目录新建“wechat.php”;2、在“phpcmsmodulesmemberindex.php”下增加“public function wechat() {…}”;3、在“foreground.class.php”文件中通过wechat函数判断用户是否登录即可。phpcms实现微信登陆(无需注册,直接存入)思路:回调参数,直接register (代码不够规范,自己整理)在根目录新建wechat.php访问: http://www.xxxxxx.cn/wechat.php注意回调地址phpcms实现微信登陆(无需注册,直接存入)wechat.php

phpcmsmodulesmemberindex.php下增加注:注册状态输出 $status, 可以返回错误信息 根据错误信息修改参数内容用户名称和密码做了简单区别处理,根据实际情况修改,邮箱为必须字段,随便放了一个。

_session_start();
//获取用户siteid
$siteid=isset($_REQUEST['siteid'])&&trim($_REQUEST['siteid'])?intval($_REQUEST['siteid']):1;
//定义站点id常量
if(!defined('SITEID')){
define('SITEID',$siteid);
}
//加载用户模块配置
//加载用户模块配置
$member_setting=getcache('member_setting');
if(!$member_setting['allowregister']){
showmessage(L('deny_register'),'/login.html');
}
/*----------------------微信获取用户信息------------------------*/
//换成自己的接口信息
$code=$_GET['code'];
$state=$_GET['state'];
$appid='xxxxxxxx';
$appsecret='xxxxxxxx';
if(empty($code))$this->error('授权失败');
$token_url='https://api.weixin.qq.com/sns/oauth3/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';
$token=json_decode(file_get_contents($token_url));
if(isset($token->errcode)){
showmessage(L('

错误信息:

'.$token->errmsg),HTTP_REFERER); exit; } $access_token_url='https://api.weixin.qq.com/sns/oauth3/refresh_token?appid='.$appid.'&grant_type=refresh_token&refresh_token='.$token->refresh_token; //转成对象 $access_token=json_decode(file_get_contents($access_token_url)); if(isset($access_token->errcode)){ showmessage(L('

错误信息:

'.$access_token->errmsg),HTTP_REFERER); exit; } $user_info_url='https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token->access_token.'&openid='.$access_token->openid.'&lang=zh_CN'; //转成对象 $user_info=json_decode(file_get_contents($user_info_url)); if(isset($user_info->errcode)){ showmessage(L('

错误信息:

'.$user_info->errmsg),HTTP_REFERER); exit; } $rs=json_decode(json_encode($user_info),true);//转换成数组 /*------------------------获取用户信息代码结束-----------------------*/ header("Cache-control:private"); $checkname=trim($rs['nickname'])."_".substr(md5($rs['unionid']),0,5); $this->_init_phpsso(); $cstatus=$this->client->ps_checkname($checkname); //如果存在用户用户登陆 if($cstatus==-4||$cstatus==-1){ $username=$rs['nickname']."_".substr(md5($rs['unionid']),0,5); $password=substr(md5($rs['unionid']),0,10); //is_password($_POST['password'])&&is_badword($_POST['password'])==false?trim($_POST['password']):showmessage(L('password_format_incorrect'),HTTP_REFERER); $cookietime=intval($_POST['cookietime']); $synloginstr='';//同步登陆js代码 if(pc_base::load_config('system','phpsso')){ $this->_init_phpsso(); $status=$this->client->ps_member_login($username,$password); $memberinfo=unserialize($status); if(isset($memberinfo['uid'])){ //查询帐号 $r=$this->db->get_one(array('phpssouid'=>$memberinfo['uid'])); if(!$r){ //插入会员详细信息,会员不存在插入会员 $info=array( 'phpssouid'=>$memberinfo['uid'], 'username'=>$memberinfo['username'], 'password'=>$memberinfo['password'], 'encrypt'=>$memberinfo['random'], 'email'=>$memberinfo['email'], 'regip'=>$memberinfo['regip'], 'regdate'=>$memberinfo['regdate'], 'lastip'=>$memberinfo['lastip'], 'lastdate'=>$memberinfo['lastdate'], 'groupid'=>$this->_get_usergroup_bypoint(),//会员默认组 'modelid'=>10,//普通会员 ); //如果是connect用户 if(!empty($_SESSION['connectid'])){ $userinfo['connectid']=$_SESSION['connectid']; } if(!empty($_SESSION['from'])){ $userinfo['from']=$_SESSION['from']; } unset($_SESSION['connectid'],$_SESSION['from']); $this->db->insert($info); unset($info); $r=$this->db->get_one(array('phpssouid'=>$memberinfo['uid'])); } $password=$r['password']; $synloginstr=$this->client->ps_member_synlogin($r['phpssouid']); }else{ if($status==-1){//用户不存在 showmessage(L('user_not_exist'),'/login.html'); }elseif($status==-2){//密码错误 showmessage(L('password_error'),'/login.html'); }else{ showmessage(L('login_failure'),'/login.html'); } } }else{ //密码错误剩余重试次数 $this->times_db=pc_base::load_model('times_model'); $rtime=$this->times_db->get_one(array('username'=>$username)); if($rtime['times']>4){ $minute=60-floor((SYS_TIME-$rtime['logintime'])/60); showmessage(L('wait_1_hour',array('minute'=>$minute))); } //查询帐号 $r=$this->db->get_one(array('username'=>$username)); if(!$r)showmessage(L('user_not_exist'),'/login.html'); //验证用户密码 $password=md5(md5(trim($password)).$r['encrypt']); if($r['password']!=$password){ $ip=ip(); if($rtime&&$rtime['times']times_db->update(array('ip'=>$ip,'times'=>'+=1'),array('username'=>$username)); }else{ $this->times_db->insert(array('username'=>$username,'ip'=>$ip,'logintime'=>SYS_TIME,'times'=>1)); $times=5; } showmessage(L('password_error',array('times'=>$times)),'/login.html',3000); } $this->times_db->delete(array('username'=>$username)); } //如果用户被锁定 if($r['islock']){ showmessage(L('user_is_lock')); } $userid=$r['userid']; $groupid=$r['groupid']; $username=$r['username']; $nickname=empty($r['nickname'])?$username:$r['nickname']; $updatearr=array('lastip'=>ip(),'lastdate'=>SYS_TIME); //vip过期,更新vip和会员组 if($r['overduedate']=0&&!in_array($r['groupid'],array('1','7','8'))&&empty($r[vip])){ $grouplist=getcache('grouplist'); if(!empty($grouplist[$r['groupid']]['allowupgrade'])){ $check_groupid=$this->_get_usergroup_bypoint($r['point']); if($check_groupid!=$r['groupid']){ $updatearr['groupid']=$groupid=$check_groupid; } } } //如果是connect用户 if(!empty($_SESSION['connectid'])){ $updatearr['connectid']=$_SESSION['connectid']; } if(!empty($_SESSION['from'])){ $updatearr['from']=$_SESSION['from']; } unset($_SESSION['connectid'],$_SESSION['from']); $this->db->update($updatearr,array('userid'=>$userid)); if(!isset($cookietime)){ $get_cookietime=param::get_cookie('cookietime'); } $_cookietime=$cookietime?intval($cookietime):($get_cookietime?$get_cookietime:0); $cookietime=$_cookietime?SYS_TIME+$_cookietime:0; $phpcms_auth=sys_auth($userid."t".$password,'ENCODE',get_auth_key('login')); param::set_cookie('auth',$phpcms_auth,$cookietime); param::set_cookie('_userid',$userid,$cookietime); param::set_cookie('_username',$username,$cookietime); param::set_cookie('_groupid',$groupid,$cookietime); param::set_cookie('_nickname',$nickname,$cookietime); //print_r($_COOKIE); //exit; //param::set_cookie('cookietime',$_cookietime,$cookietime); //https与http传递用户名跨域跳转cooike $forward=isset($_POST['forward'])&&!empty($_POST['forward'])?urldecode($_POST['forward']):'index.php?m=member&c=index'; $url="http://www.zhiliaoke.com.cn/set_cookie_www.php?nickname=".$_COOKIE['vuGYB__nickname']."&username=".$_COOKIE['vuGYB__username']."&userid=".$_COOKIE['vuGYB__userid']."&groupid=".$_COOKIE['vuGYB__groupid']; header("Location:".$url.""); } //如果不存在用户注册 $userinfo=array(); $userinfo['encrypt']=create_randomstr(6); $userinfo['username']=$rs['nickname'免费云主机、域名]."_".substr(md5($rs['unionid']),0,5); $userinfo['nickname']=$rs['nickname']."_".substr(md5($rs['unionid']),0,5); &nbsp

相关推荐: ps火焰效果如何制作

这篇“ps火焰效果如何制作”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“ps火焰效果如何制作”文章吧。 1、首先我们新建一个文档,然后ctrl+…

文章页内容下
赞(0) 打赏
版权声明:本站采用知识共享、学习交流,不允许用于商业用途;文章由发布者自行承担一切责任,与本站无关。
文章页正文下
文章页评论上

云服务器、web空间可免费试用

宝塔面板主机、支持php,mysql等,SSL部署;安全高速企业专供99.999%稳定,另有高防主机、不限制内容等类型,具体可咨询QQ:360163164,Tel同微信:18905205712

主机选购导航云服务器试用

登录

找回密码

注册