isWeixin = util::isWeixin(); $get = Yii::$app->request->get(); $account = isset($get['account']) ? $get['account'] : ''; $one = xhMerchantService::getOne(); $wxOpenId = configDict::getConfig('openId'); $this->wxOpen = xhWxOpenService::getById($wxOpenId); $noNeedLogin = false; if(!empty($one)){ if(empty($account)){ $merchant = xhWxOpenService::getMerchant(); }else{ $merchant = xhMerchantService::getByAccount($account); } $account = $merchant['id']; $this->merchant = $merchant; $merchantId = $merchant['id']; $this->merchantId = $merchantId; $this->merchantExtend = xhMerchantExtendService::getByMerchantId($merchantId); if($this->isWeixin){ $jssdk = new jsSDK();//微信分享 $this->signPackage = $jssdk->GetSignPackage($merchant); } }else{ $noNeedLogin = true; } if(in_array($action->id, $this->withoutLogin) || $this->isLogin == true){ $noNeedLogin = true; } $session = Yii::$app->session; if(isset($session['visitingMerchantAccount']) && $session['visitingMerchantAccount'] != $account){ xhUserService::logout(); } $this->isLogin = xhUserService::isLogin(); if($this->isLogin){ $userId = xhUserService::getId(); $user = xhUserService::getById($userId); $this->userId = $userId; $this->user = $user; $noNeedLogin = true; } if ($this->isWeixin) {//如果是微信,走微信授权取用户信息 if($noNeedLogin == false){ //snsapi_userinfo 需要用户授权获取用户信息,snsapi_base表示自动静默方式 $authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_userinfo'; $params = empty($_SERVER['REQUEST_URI']) ? '' : base64_encode($_SERVER['REQUEST_URI']);//取主域名后面的参数 $url = 'http://'.$_SERVER['HTTP_HOST'].'/auth/get-user-info?params='.$params.'&authScope='.$authScope; weixinUtil::getToken($url,$merchant,$authScope); util::end(); } }else{ if($noNeedLogin == false){ $this->redirect(['main/login']); util::stop(); } } return parent::beforeAction($action); } }