language = Yii::$app->request->getHeaders()->get('app-language'); //'en-US'; \Yii::$app->params['web'] = Config::lists(); } final public function behaviors() { $behaviors = parent::behaviors(); $newBehaviors = []; $newBehaviors['corsFilter'] = [ 'class' => Cors::class, ]; foreach ($behaviors as $k=>$v){ $newBehaviors[$k]=$v; } unset($behaviors['authenticator']); //删掉,保持先cors,后authenticator //设置认证方式,接口才认证 $newBehaviors['authenticator'] = [ 'class' => HttpBearerAuth::class, 'optional' => $this->optional, ]; return $newBehaviors; } public function beforeAction($action) { $ret = parent::beforeAction($action); // TODO: Change the autogenerated stub //判断是否是游客 if(!\Yii::$app->user->isGuest){ if (\Yii::$app->request->isPost){ $this->store=$this->post('store_id'); } if (\Yii::$app->request->isGet){ $this->store=$this->get('store_id'); } \Yii::$app->store=$this->store; if (empty(\Yii::$app->store)){ throw new Exception('参数store_id不能为空'); } }else{ //游客模式 \Yii::$app->store=$this->store=11001;//默认门店 } return $ret; } }