public function beforeAction($action) { $_token = \yii::$app->request->post_get('token'); //判断token是否合法 $user_id = TokenService::getService()->getIdByToken($_token); if (is_int($user_id) && $user_id < 0) { exit(\common\helpers\JsonHelper::returnError($user_id)); } $_POST['data']['user_id'] = $user_id; return true; }
public function beforeAction($action) { $_token = \yii::$app->request->post_get(CommonConstant::TOKEN_NAME); //ÅжÏtokenÊÇ·ñºÏ·¨ $user_id = TokenService::getService()->getIdByToken($_token); if (is_numeric($user_id) && $user_id > 0) { $_POST[CommonConstant::REQUEST_PARAM]['user_id'] = $user_id; } else { $_POST[CommonConstant::REQUEST_PARAM]['user_id'] = null; } return true; }
/** * 获取token * @param int $user_id * @return mixed * @deprecate 具有代码冗余的嫌疑 暂时先不用 */ private function _buildToken($user_id) { return TokenService::getService()->createToken($user_id); }