private static function getFromRedis() { if (!XIIS_CACHE_REDIS) { return; } if (!empty(self::$_outputData)) { return; } if (self::$_xiiCacheID == '') { return; } $redis = @stream_socket_client(Yii::$app->redis->hostname . ':' . Yii::$app->redis->port, $errno, $errstr, 1); XiiError::ignoreError(); if (!$redis) { self::logRecord([XIIS_DATA_FROM_REDIS => self::FAIL_TO_CONNECT_REDIS]); } else { $tmp = Yii::$app->redis->get(self::$_xiiCacheID); if ($tmp) { self::$_outputData = XiiJson::decode($tmp); self::$_dataFrom = XIIS_DATA_FROM_REDIS; self::logRecord([XIIS_DATA_FROM_REDIS => self::SUCCESS_GET_FROM_REDIS]); } else { self::logRecord([XIIS_DATA_FROM_REDIS => self::FAIL_GET_FROM_REDIS]); } } }
public function initExec() { XiiError::open(); self::checkDb(); self::whoami(); }
public function checkUnique() { if (count($this->_requestData) == 1) { $validCheck = in_array(key($this->_requestData), self::$_uniqueCheckAllowField); } else { $diff = array_diff(array_keys($this->_requestData), self::$_uniqueCheckAllowField); $validCheck = empty($diff) ? true : false; } if ($validCheck) { $feedback = $this->_model->countAll([XIIS_PARAMS_CONDITION => $this->_requestData]); if ($feedback[XIIS_FEEDBACK_STATUS] === false) { $status = true; $code = EC_BACKEND_UNIQUE_CHECK_YES; } else { $status = false; $code = EC_BACKEND_UNIQUE_CHECK_NO; } $msg = XiiError::getErrorMessage($code); self::$_outData = [XIIS_FEEDBACK_STATUS => $status, XIIS_FEEDBACK_CODE => $code, XIIS_FEEDBACK_MSG => $msg, XIIS_FEEDBACK_DATA => $this->_requestData]; } else { self::sendError(EC_BACKEND_UNIQUE_INVALID_FIELD); } }
protected function generateJwt($user, $success = EC_BACKEND_SUCCESS_LOGIN) { $para = ['header' => ['typ' => 'JWT', 'alg' => XIIS_PARAMS_CONF_JWT_ALG]]; foreach (self::$_jwtPayload as $v) { if (!isset($user[$v])) { self::sendError(EC_BACKEND_FAIL_TO_CREATE_PAYLOAD); } $payload[$v] = $user[$v]; } $payload['iat'] = $payload['nbf'] = $payload['exp'] = time(); $payload['exp'] += XIIS_PARAMS_CONF_JWT_EXP; $para['payload'] = $payload; $feedback = [XIIS_FEEDBACK_STATUS => true, XIIS_FEEDBACK_CODE => $success, XIIS_FEEDBACK_MSG => XiiError::getErrorMessage($success), XIIS_FEEDBACK_DATA => [XIIS_PARAMS_CONF_JWT => XiiJwt::getJWT($para)]]; return $feedback; }
public function actionStatus() { self::$_outData = [XIIS_FEEDBACK_STATUS => true, XIIS_FEEDBACK_CODE => EC_AUTH_TOKEN_VERIFY_PASS, XIIS_FEEDBACK_MSG => XiiError::getErrorMessage(EC_AUTH_TOKEN_VERIFY_PASS), XIIS_FEEDBACK_DATA => []]; }
private static function saveToRedis() { if (!XIIS_CACHE_REDIS) { return; } if (empty(self::$_outputData[XIIS_FEEDBACK_DATA])) { return; } if (self::$_xiiCacheID == '') { return; } $redis = @stream_socket_client(Yii::$app->redis->hostname . ':' . Yii::$app->redis->port, $errno, $errstr, 1); XiiError::ignoreError(); if (!$redis) { self::logRecord([XIIS_DATA_FROM_REDIS => self::FAIL_TO_CONNECT_REDIS]); } else { if (Yii::$app->redis->get(self::$_xiiCacheID)) { self::logRecord([XIIS_DATA_FROM_REDIS => self::NONEED_SAVE_TO_REDIS]); } else { if (Yii::$app->redis->set(self::$_xiiCacheID, Yii::$app->response->content)) { Yii::$app->redis->expire(self::$_xiiCacheID, XIIS_CACHE_LIFE_DURATION); self::logRecord([XIIS_DATA_FROM_REDIS => self::SUCCESS_SAVE_TO_REDIS]); } else { self::logRecord([XIIS_DATA_FROM_REDIS => self::FAIL_SAVE_TO_REDIS]); } } } }