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(); } }
微信扫码登录验证PHP代码(不用开放平台)
最新推荐文章于 2024-05-20 17:26:45 发布