request->isAjax()){ $this->userInfo = session('userInfo'); $debug = config('weixin.debug'); if(empty($this->userInfo) || $debug){ // 调试模式 $curOpenId = session('openid'); $openid = $curOpenId? $curOpenId : config('weixin.openid'); if($openid){ $this->userInfo = Member::getInfo(['openid'=> $openid, 'user_type'=> 2],$field); } $wxInfo = Fans::getInfo(['openid' => $openid]); session('openid', $openid); session('wxInfo', $wxInfo); session('userInfo', $this->userInfo); } $this->userId = isset($this->userInfo['id'])? intval($this->userInfo['id']) : 0; $this->userType = isset($this->userInfo['user_type'])? intval($this->userInfo['user_type']) : 2; $userStatus = isset($this->userInfo['user_status'])? intval($this->userInfo['user_status']) : -1; if(empty($this->userId) || $userStatus == -1){ showJson(1005,2103,['url'=> Wechat::makeRedirectUrl(url('/weixin/match/index','','',true))]); } // $realname = isset($this->userInfo['real_name'])? $this->userInfo['real_name'] : ''; $mobile = isset($this->userInfo['mobile'])? $this->userInfo['mobile'] : ''; $isReg = isset($this->userInfo['is_reg_profile'])? $this->userInfo['is_reg_profile'] : 0; if(empty($mobile) || $isReg != 1){ $this->needRegProfile = true; session('needRegProfile', true); }else{ session('needRegProfile', false); } return true; } // 调用微信授权校验 $openid = ''; $debug = config('weixin.debug'); if(empty($debug)){ $this->userInfo = session('userInfo'); $openid = session('openid'); $cacheKey = "weixin:auth:".$openid; $userStatus = isset($this->userInfo['user_status'])? intval($this->userInfo['user_status']) : -1; $agentStatus = isset($this->userInfo['agent_status'])? intval($this->userInfo['agent_status']) : -1; // PRedis::set('weixin:temp:'.$openid.'_'.get_client_ip(), ['openid'=> $openid, 'userInfo'=> $this->userInfo], 24 * 3600); if(empty($openid) || empty($this->userInfo) || $userStatus ==-1 || $agentStatus == -1 || !PRedis::get($cacheKey)){ Wechat::init(); if($openid){ PRedis::set($cacheKey, session('userInfo'), 7 * 24 * 3600); } } }else{ $curOpenId = session('openid'); $openid = $curOpenId? $curOpenId : config('weixin.openid'); $this->userInfo = session('userInfo'); $agentStatus = isset($this->userInfo['agent_status'])? intval($this->userInfo['agent_status']) : -1; $cacheKey = "weixin:test:".$openid; if(empty($this->userInfo) || $agentStatus == -1 || !PRedis::get($cacheKey)){ if($openid){ $this->userInfo = Member::getInfo(['openid'=> $openid, 'user_type'=> 2],$field); } $wxInfo = Fans::getInfo(['openid' => $openid]); session('openid', $openid); session('wxInfo', $wxInfo); session('userInfo', $this->userInfo); if($openid){ PRedis::set($cacheKey, session('userInfo'), 7 * 24 * 3600); } } $this->userId = isset($this->userInfo['id'])? $this->userInfo['id'] : 0; } // 验证信息 // $realname = isset($this->userInfo['real_name'])? $this->userInfo['real_name'] : ''; $mobile = isset($this->userInfo['mobile'])? $this->userInfo['mobile'] : ''; $isReg = isset($this->userInfo['is_reg_profile'])? $this->userInfo['is_reg_profile'] : 0; if(empty($mobile) || $isReg != 1){ $this->needRegProfile = true; session('needRegProfile', true); }else{ session('needRegProfile', false); } $this->userType = isset($this->userInfo['user_type'])? intval($this->userInfo['user_type']) : 2; } /** * 验证用户状态 */ public function checkUserStatus(){ // 验证用户是否冻结 $userStatus = Member::where(['id'=> $this->userId, 'user_type'=> 2])->value('user_status'); if($userStatus == -1) { redirect('https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=Mzg3ODEzNjMzMQ==&scene=124#wechat_redirect'); exit; }else if($userStatus != 1){ Wechat::redirectUrl(url('/weixin/page/custom', '', '', true)); exit; } } } ?>