微信扫码登录验证PHP代码(不用开放平台)
2017-05-04 22:28
471 查看
public function wxqrcheckAction(){ if(g('ajaxchk')!=''){ //前端页面显示二维码并AJAX定时检查已否已扫码验证 if(isset($_SESSION['wxqrchk'])){ $msg=''; if(isset($_SESSION['user'])){ $msg=$_SESSION['user']['username']; } $this->ajaxReturn(array('code'=>1,'username'=>$msg)); }else{ $this->ajaxReturn(array('code'=>0)); } die(); }else if(g('wxauth')!=''){ //扫码后访问 $_SESSION['chksid']=g('wxauth'); WXAuthController::Auth('/Public/wxqrcheck/redirect/'.g('wxauth'),1); die("wxauth end..."); }else if(g('redirect')!=''){ $openid=WXAuthController::GetOpenid(); //获取微信OPENID $user=ORM::for_table('sys_user')->where('openid',$openid)->find_one(); if($user){ $chksid=$_SESSION['chksid']; session_destroy(); //thinkphp等开始已经session_start了 session_id($chksid); session_start();//这个函数必须在session_id()之后 $_SESSION['user']=$user->as_array(); if($_SESSION['user']['username']=='admin' || $_SESSION['user']['username']=='adminisrator'){ $_SESSION['isadmin']=true; }else{ unset( $_SESSION['isadmin']); } $_SESSION['islogin']=true; $_SESSION['wxqrchk']=true; echo "扫码登录成功<br/>"; }else{ echo "没有这个用户 openid:".$openid; } die("手机端验证完成"); }else{ $sessionid=session_id(); $qrurl="http://XXXXX.COM/Public/wxqrcheck/wxauth/".$sessionid; $this->assign('qrurl',$qrurl); $this->display(); } }
相关文章推荐
- QQ开放平台QQ登录PHP代码
- PHP通过session id 实现session共享和登录验证的代码
- PHP通过session id 实现session共享和登录验证的代码
- php cookie 登录验证示例代码
- PHP通过session id 实现session共享和登录验证的代码
- php中实现自动注册自动登录验证代码
- php cookie 登录验证示例代码
- 我的第二行php代码之接受get请求连接数据库实现登录验证
- php自动注册登录验证机制实现代码
- php登录验证及代码实现 含数据库设计 亲测有效
- PHP通过session id 实现session共享和登录验证的代码
- php登录验证及代码实现 含数据库设计 亲測有效
- 安卓服务端开发(1) 安卓结合PHP实现连接数据库验证登录功能(附全部代码)
- PHP通过session id 实现session共享和登录验证的代码
- php 登录mysql 验证的代码
- php自动注册登录验证机制实现代码
- php session应用实例 登录验证
- php session应用实例--登录验证
- Ajax与PHP结合实现登录验证
- php 安全基础 第七章 验证与授权 永久登录