public static function run($para = [], $lang = 'chs') { self::init(); if (empty($para)) { return self::ERROR_PARA_EMPTY; } if (isset($para[XIIS_PARAMS_URL])) { $tmp_url = explode('/', $para[XIIS_PARAMS_URL]); $first_key = end($tmp_url); if (is_numeric($first_key)) { array_pop($tmp_url); $second_key = end($tmp_url); return $lang . '_' . $second_key . '_' . $first_key; } if (!isset($para[XIIS_PARAMS_DATA])) { return self::ERROR_PARA_NO_URL; } if (isset($para[XIIS_PARAMS_METHOD]) && strtolower(trim($para[XIIS_PARAMS_METHOD])) != 'get') { return self::ERROR_PARA_NOT_GET; } return $lang . '_' . $first_key . '_' . md5(XiiUtil::implodePlus($para[XIIS_PARAMS_DATA])); } else { $first_key = Yii::$app->controller->id; if (isset($para[XIIS_PARAMS_CONDITION][XIIS_DEFAULT_PRI_KEY]) && !is_array($para[XIIS_PARAMS_CONDITION][XIIS_DEFAULT_PRI_KEY])) { return $lang . '_' . $first_key . '_' . $para[XIIS_PARAMS_CONDITION][XIIS_DEFAULT_PRI_KEY]; } return $lang . '_' . $first_key . '_' . md5(XiiUtil::implodePlus($para)); } }
private static function preparePath() { if (substr(self::$_pathFolder, -1) != '/') { self::$_pathFolder .= '/'; } if (self::$_pathUseDateFormat && strpos(self::$_pathFolder, date("Ymd", time())) === false) { self::$_pathFolder .= date("Ymd", time()) . '/'; } self::$_pathFolder = str_replace('//', '/', self::$_pathFolder); XiiUtil::mkdir(self::$_pathFolder); }
private static function generateToken($para) { self::$_whereStart = self::$_whereStart > 10 || self::$_whereStart < 0 ? 1 : (int) self::$_whereStart; if (self::$_useImplodePlus) { $_tmp = XiiUtil::implodePlus($para, ''); } else { $_tmp = implode('', $para); } $_token = self::doEncrypt($_tmp . self::$_privateKey); return substr($_token, self::$_whereStart, self::TOKEN_LENGTH); }
public static function run($para, $usetoken = true) { self::init(); $ch = curl_init(); if (isset($para[self::XII_PARAMS_USERAGENT]) && !empty($para[self::XII_PARAMS_USERAGENT])) { curl_setopt($ch, CURLOPT_USERAGENT, $para[self::XII_PARAMS_USERAGENT]); } else { curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); } if (isset($para[XIIS_PARAMS_URL]) && !empty($para[XIIS_PARAMS_URL])) { curl_setopt($ch, CURLOPT_URL, $para[XIIS_PARAMS_URL]); } else { return [XIIS_FEEDBACK_STATUS => false, XIIS_FEEDBACK_CODE => 0, XIIS_FEEDBACK_MSG => XIIS_PARAMS_URL . ' is null!']; } if (isset($para[self::XII_PARAMS_REF_URL]) && !empty($para[self::XII_PARAMS_REF_URL])) { curl_setopt($ch, CURLOPT_REFERER, $para[self::XII_PARAMS_REF_URL]); } if (!isset($para[XIIS_PARAMS_DATA])) { if (!self::$_allowEmptyData) { return [XIIS_FEEDBACK_STATUS => false, XIIS_FEEDBACK_CODE => 0, XIIS_FEEDBACK_MSG => XIIS_PARAMS_DATA . ' is not find!']; } $para[XIIS_PARAMS_DATA] = []; } else { if (!is_array($para[XIIS_PARAMS_DATA])) { return [XIIS_FEEDBACK_STATUS => false, XIIS_FEEDBACK_CODE => 0, XIIS_FEEDBACK_MSG => XIIS_PARAMS_DATA . ' must be array!']; } } if ($usetoken) { $token = XiiToken::accessApi(); $para[XIIS_PARAMS_DATA] = array_merge($para[XIIS_PARAMS_DATA], $token); } if (count($para[XIIS_PARAMS_DATA]) > 0) { if (isset($para[XIIS_PARAMS_METHOD]) && !empty($para[XIIS_PARAMS_METHOD]) && in_array(strtoupper($para[XIIS_PARAMS_METHOD]), array('PUT', 'DELETE', 'POST'))) { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($para[XIIS_PARAMS_METHOD])); //curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-HTTP-Method-Override: " . strtoupper($para[XIIS_PARAMS_METHOD]))); $para[XIIS_PARAMS_DATA] = http_build_query($para[XIIS_PARAMS_DATA]); curl_setopt($ch, CURLOPT_POSTFIELDS, $para[XIIS_PARAMS_DATA]); } else { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); //curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-HTTP-Method-Override: POST")); $para[XIIS_PARAMS_DATA] = http_build_query($para[XIIS_PARAMS_DATA]); curl_setopt($ch, CURLOPT_URL, $para[XIIS_PARAMS_URL] . '?' . $para[XIIS_PARAMS_DATA]); } } else { if (!self::$_allowEmptyData) { return [XIIS_FEEDBACK_STATUS => false, XIIS_FEEDBACK_CODE => 0, XIIS_FEEDBACK_MSG => XIIS_PARAMS_DATA . ' is null!']; } } $timeout = isset($para[self::XII_PARAMS_TIMEOUT]) && !empty($para[self::XII_PARAMS_TIMEOUT]) ? intval($para[self::XII_PARAMS_TIMEOUT]) : 10; curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); if (isset($para[self::XII_PARAMS_SET]) && !empty($para[self::XII_PARAMS_SET])) { foreach ($para[self::XII_PARAMS_SET] as $k => $v) { curl_setopt($ch, $k, $v); } } if (isset($para[self::XII_PARAMS_INFO])) { $result = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); return [XIIS_FEEDBACK_STATUS => true, XIIS_FEEDBACK_CODE => 1, XIIS_FEEDBACK_DATA => $info]; } else { $result = curl_exec($ch); curl_close($ch); if (XiiUtil::isJson($result)) { $tmp = Json::decode($result); if (isset($tmp[XIIS_FEEDBACK_DATA][XiiToken::getIndex()])) { if (!XiiToken::verify($tmp[XIIS_FEEDBACK_DATA])) { return [XIIS_FEEDBACK_STATUS => false, XIIS_FEEDBACK_CODE => 0, XIIS_FEEDBACK_MSG => 'Response data be modify!']; } } } return [XIIS_FEEDBACK_STATUS => true, XIIS_FEEDBACK_CODE => 1, XIIS_FEEDBACK_DATA => $result]; } }
private static function jwtEncode($data) { return is_array($data) ? XiiUtil::base64Encode(XiiJson::encode($data)) : XiiUtil::base64Encode($data); }
private static function send() { if (XIIS_DEBUG) { self::logRecord([XIIS_DATA_CACHE_ID => self::$_xiiCacheID]); if (XIIS_RUN_LOG) { self::logRecord(['XiiRunLog' => Yii::$app->log->getLogger()->messages]); } self::$_outputData = array_merge(self::$_outputData, self::$_runtimeError, self::$_tmpData); } if (self::$_sendFormat == 'html') { Yii::$app->response->data = XiiUtil::implodePlus(self::$_outputData, PHP_EOL); } else { if (self::$_encrypt) { self::doEncrypt(); } Yii::$app->response->data = self::$_outputData; } }