<?php
|
|
namespace CommFunc;
|
|
include_once 'ConfigReader.php';
|
|
static $interfaceConfig = null;
|
|
function parseConfigIni()
|
{
|
global $interfaceConfig;
|
if ($interfaceConfig == null) {
|
$interfaceConfig = parse_ini_file("/InterfaceConfig.php", true);
|
if ($interfaceConfig) {
|
\Logging\LogInfo("do parse_ini_file InterfaceConfig.php");
|
}
|
}
|
return $interfaceConfig;
|
}
|
|
function GetConfig($section, $option, &$value, $defaultValue = null)
|
{
|
$interfaceConfig = parseConfigIni();
|
if (array_key_exists($section, $interfaceConfig)) {
|
if (array_key_exists($option, $interfaceConfig[$section])) {
|
$value = $interfaceConfig[$section][$option];
|
return true;
|
} else {
|
\Logging\LogError("InterfaceConfig.php can not found option:" . $option . " in section:" . $section);
|
}
|
} else {
|
\Logging\LogError("InterfaceConfig.php can not found section:" . $section);
|
}
|
$value = $defaultValue;
|
return false;
|
}
|
|
function Has_section($section)
|
{
|
$interfaceConfig = parseConfigIni();
|
if (array_key_exists($section, $interfaceConfig)) {
|
return true;
|
}
|
return false;
|
}
|
|
function Has_option($section, $option)
|
{
|
$interfaceConfig = parseConfigIni();
|
if (array_key_exists($section, $interfaceConfig)) {
|
if (array_key_exists($option, $interfaceConfig[$section])) {
|
return true;
|
}
|
}
|
return false;
|
}
|
|
function GetGameName()
|
{
|
GetConfig("ServerInfo", "GameName", $gameName);
|
return $gameName;
|
}
|
|
/**
|
* 获取该游戏所有运营渠道
|
*/
|
function GetAllChannel()
|
{
|
GetConfig("ServerInfo", "ChannelList", $channelInfo);
|
return explode(",", $channelInfo);
|
}
|
|
/**
|
* 获取该游戏所有管理组织
|
*/
|
function GetAllOrganization()
|
{
|
GetConfig("ServerInfo", "OrganizationList", $OrganizationList);
|
return explode(",", $OrganizationList);
|
}
|
|
/**
|
* 获取该组织对应可管理的渠道
|
*/
|
function GetOrganizationChannel($Organization)
|
{
|
GetConfig("ServerInfo", "Channel_" . $Organization, $channels);
|
return explode(",", $channels);
|
}
|
|
function EchoDateTimeSelect($dateName, $hourName, $minuteName, $secondName, $setDateStr = "", $hours = null, $minutes = null, $seconds = null)
|
{
|
$defaultDate = "";
|
$defaultHour = 0;
|
$defaultMinute = 0;
|
$defaultSecond = 0;
|
if ($setDateStr == "") {
|
$setDateStr = date("Y-m-d H:i:s");
|
}
|
if ($setDateStr) {
|
// 2022-05-08 04:38:44
|
$defaultDate = substr($setDateStr, 0, 10);
|
$defaultHour = substr($setDateStr, 11, 2);
|
$defaultMinute = substr($setDateStr, 14, 2);
|
$defaultSecond = substr($setDateStr, 17, 2);
|
}
|
|
$html = "<input type=\"text\" name=\"" . $dateName . "\" id=\"" . $dateName
|
. "\" onclick=\"new Calendar().show(this);\" readonly value=\"" . $defaultDate . "\" size=\"8\"/>";
|
// hour
|
$html .= "<select name=\"" . $hourName . "\">";
|
if (!isset($hours)) {
|
$hours = range(0, 23);
|
}
|
foreach ($hours as $h) {
|
if ($h < 10) {
|
$hourStr = "0" . $h;
|
} else {
|
$hourStr = "" . $h;
|
}
|
$html .= "<option value=\"" . $hourStr . "\"";
|
if ($hourStr <= $defaultHour) {
|
$html .= " selected";
|
}
|
$html .= ">" . $hourStr . "</option>";
|
}
|
$html .= "</select>:";
|
// minute
|
$html .= "<select name=\"" . $minuteName . "\">";
|
if (!isset($minutes)) {
|
$minutes = range(0, 59);
|
}
|
foreach ($minutes as $m) {
|
if ($m < 10) {
|
$minuteStr = "0" . $m;
|
} else {
|
$minuteStr = "" . $m;
|
}
|
$html .= "<option value=\"" . $minuteStr . "\"";
|
if ($minuteStr <= $defaultMinute) {
|
$html .= " selected";
|
}
|
$html .= ">" . $minuteStr . "</option>";
|
}
|
$html .= "</select>:";
|
// second
|
if (!isset($seconds)) {
|
$seconds = range(0, 59);
|
}
|
$html .= "<select name=\"" . $secondName . "\">";
|
foreach ($seconds as $s) {
|
if ($s < 10) {
|
$secondStr = "0" . $s;
|
} else {
|
$secondStr = "" . $s;
|
}
|
$html .= "<option value=\"" . $secondStr . "\"";
|
if ($secondStr <= $defaultSecond) {
|
$html .= " selected";
|
}
|
$html .= ">" . $secondStr . "</option>";
|
}
|
$html .= "</select>";
|
echo $html;
|
}
|
|
/**
|
* 比较版本号
|
* @param string $curVersion 当前版本
|
* @param string $cmpVersion 要比较的版本
|
* @return -1-小于比较版本;0-等于比较版本;1-大于比较版本
|
*/
|
function CheckVersion($curVersion, $cmpVersion)
|
{
|
$curValue = VersionNum($curVersion);
|
$cmpValue = VersionNum($cmpVersion);
|
if ($curValue < $cmpValue) {
|
return -1;
|
}
|
if ($curValue > $cmpValue) {
|
return 1;
|
}
|
return 0;
|
}
|
|
function VersionNum($version)
|
{
|
$arrver = explode('.', $version);
|
if (isset($arrver[2])) {
|
$integer_version = $arrver[0] * 10000 + $arrver[1] * 100 + $arrver[2];
|
} else if (isset($arrver[1])) {
|
$integer_version = $arrver[0] * 10000 + $arrver[1] * 100;
|
} else {
|
$integer_version = $arrver[0];
|
}
|
return intval($integer_version);
|
}
|
|
/**
|
* 优化的require_once
|
* @param string $filename 文件地址
|
* @return boolean
|
*/
|
function require_cache($filename)
|
{
|
static $_importFiles = array();
|
if (!isset($_importFiles[$filename])) {
|
if (file_exists_case($filename)) {
|
require $filename;
|
$_importFiles[$filename] = true;
|
} else {
|
$_importFiles[$filename] = false;
|
}
|
}
|
return $_importFiles[$filename];
|
}
|
|
/**
|
* 强制类型转换
|
* @param mixed &$value 数据
|
* @param string $valueType 数据类型(int, str, float, array)
|
* @return boolean
|
*/
|
function ConvValue(&$value, $valueType = "str")
|
{
|
if ($valueType == 'array') {
|
$newValue = is_array($value) ? $value : array($value);
|
} else {
|
$valueType .= "val";
|
$newValue = @$valueType($value);
|
}
|
$ret = $newValue == $value;
|
if ($ret) {
|
$value = $newValue;
|
return true;
|
# 如果转换后不等 说明原数据类型差异过大
|
} else {
|
return false;
|
}
|
}
|
|
#检查GET参数是否被设置,如果设置则返回true,否则返回false,
|
#$strModuleLogName:如果检查失败,记录log的文件名字
|
#$checkErrorPintValue:在检查参数失败的时候,传回给浏览器的内容
|
function CheckGetParam($param, $checkErrorPrintValue = null)
|
{
|
return CheckParam($_GET, $param, $checkErrorPrintValue);
|
}
|
|
#检查POST参数是否被设置,如果设置则返回true,否则返回false,
|
#$strModuleLogName:如果检查失败,记录log的文件名字
|
#$checkErrorPintValue:在检查参数失败的时候,传回给浏览器的内容
|
function CheckPostParam($param, $checkErrorPrintValue = null)
|
{
|
return CheckParam($_POST, $param, $checkErrorPrintValue);
|
}
|
|
function CheckParam($arrayToCheck, $param, $checkErrorPrintValue = null)
|
{
|
if (!isset($arrayToCheck[$param])) {
|
\Logging\LogWarn("" . var_export($arrayToCheck, True) . " query:$param is null!");
|
|
if ($checkErrorPrintValue != null) {
|
echo $checkErrorPrintValue;
|
}
|
return false;
|
}
|
|
return true;
|
}
|
|
#从配置文件获得key,返回值为true则成功,否则失败
|
#需要传入配置文件名(全路径),section名和ident名以及日志对象
|
#$strErrorPrintValue:用来在发生读取失败时打印的内容
|
|
function GetKeyFromConfig(
|
$strConfigName,
|
$strSection,
|
$strIdent,
|
&$strRet,
|
$strErrorPrintValue = ''
|
) {
|
static $arrayConfig = array();
|
|
$config = null;
|
|
if (!array_key_exists($strConfigName, $arrayConfig)) {
|
$config = new \ConfigReader\ConfigReader($strConfigName);
|
$arrayConfig[$strConfigName] = $config;
|
} else {
|
$config = $arrayConfig[$strConfigName];
|
}
|
|
|
if (!$config->load()) {
|
\Logging\LogError('配置文件载入失败!文件路径:' . $strConfigName);
|
echo $strErrorPrintValue;
|
return false;
|
}
|
if (!$config->GetData($strSection, $strIdent, $strRet)) {
|
\Logging\LogError('read config Key error!Error:' . $config->GetErrInfo());
|
echo $strErrorPrintValue;
|
return false;
|
}
|
|
\Logging\LogInfo(sprintf(
|
'配置文件:%s, section:%s, ident:%s载入成功!',
|
$strConfigName,
|
$strSection,
|
$strIdent
|
));
|
return true;
|
}
|
|
#判断是否有Section存在于指定的配置中
|
function IsSectionExist($strSection, $strConfigName)
|
{
|
$config = new \ConfigReader\ConfigReader($strConfigName);
|
if (!$config->load()) {
|
\Logging\LogError('配置文件载入失败!文件路径:' . $strConfigName);
|
return false;
|
}
|
|
return $config->IsSectionExist($strSection);
|
}
|
|
|
#传入数组参数,批量检测数组中的参数是否都存在(CheckGetParam的批量处理版)
|
function ArrayCheckGetParam($arrayParam, $checkErrorPrintValue = null)
|
{
|
$bRet = true;
|
foreach ($arrayParam as $strValue) {
|
if (!CheckGetParam($strValue, $strValue . ' ' . $checkErrorPrintValue)) {
|
$bRet = false;
|
}
|
}
|
|
return $bRet;
|
}
|
|
/**
|
* 根据游戏账号返回平台账号明细
|
*/
|
function GetAccountInfoByAccID($accID)
|
{
|
$accIDInfoList = explode("@", $accID);
|
$infoCount = count($accIDInfoList);
|
if ($infoCount < 3) {
|
return array();
|
}
|
$sid = $accIDInfoList[$infoCount - 1];
|
$platform = $accIDInfoList[$infoCount - 2];
|
$AccountID = join("@", array_slice($accIDInfoList, 0, $infoCount - 2));
|
$accountInfo = array(
|
"AccountID" => $AccountID,
|
"Channel" => $platform,
|
"ServerID" => GetServerIDBySid($sid),
|
);
|
return $accountInfo;
|
}
|
|
/**
|
* 根据字符串取服务器id,一般正常的格式为 sxxx
|
* @param string $sid 字符串 s+服务器ID
|
* @return number 大于等于0代表服务器ID
|
*/
|
function GetServerIDBySid($sid)
|
{
|
if (!substr($sid, 0, 1) == "s") {
|
return 0;
|
}
|
if (!is_numeric(substr($sid, 1))) {
|
return 0;
|
}
|
return intval(substr($sid, 1));
|
}
|
|
static $gameservers = null;
|
function GetGameServers($spid)
|
{
|
global $gameservers;
|
if ($gameservers != null) {
|
return $gameservers;
|
}
|
$gameservers = array();
|
$ConfigFile = dirname(__FILE__) . "\\..\\Account\Server\Server_" . $spid . ".ini";
|
if (!file_exists($ConfigFile)) {
|
\Logging\LogError("file is not exist:" . $ConfigFile);
|
return $gameservers;
|
}
|
$serverCfg = parse_ini_file($ConfigFile, true);
|
foreach ($serverCfg as $Name => $serverInfo) {
|
$gameservers[$serverInfo["ServerID"]] = array(
|
"Page" => $serverInfo["Page"],
|
"MainServer" => $serverInfo["MainServer"],
|
"Name" => $Name,
|
);
|
}
|
return $gameservers;
|
}
|
|
function GetGameServerInfo($spid, $queryServerID)
|
{
|
$ConfigFile = dirname(__FILE__) . "\\..\\Account\Server\Server_" . $spid . ".ini";
|
if (!file_exists($ConfigFile)) {
|
return;
|
}
|
|
$serverCfg = parse_ini_file($ConfigFile, true);
|
|
foreach ($serverCfg as $serverName => $serverInfo) {
|
$Page = $serverInfo["Page"];
|
$serverID = $serverInfo["ServerID"];
|
$mainServerID = $serverInfo["MainServer"];
|
if (!$mainServerID) {
|
!$mainServerID = $serverID;
|
}
|
if (!$mainServerID) {
|
continue;
|
}
|
if (!$serverID) {
|
continue;
|
}
|
$serverID = intval($serverID);
|
|
if ($queryServerID != $serverID) {
|
continue;
|
}
|
|
return array(
|
"Name" => $serverName,
|
"ServerID" => $serverID,
|
"Page" => $Page,
|
"MainServer" => $mainServerID,
|
);
|
}
|
return;
|
}
|
|
function GetGameServerInfoByName($spid, $serverName)
|
{
|
$ConfigFile = dirname(__FILE__) . "\\..\\Account\Server\Server_" . $spid . ".ini";
|
if (!file_exists($ConfigFile)) {
|
return;
|
}
|
|
$serverCfg = parse_ini_file($ConfigFile, true);
|
$serverInfo = $serverCfg[$serverName];
|
if ($serverInfo) {
|
$Page = $serverInfo["Page"];
|
$serverID = $serverInfo["ServerID"];
|
$mainServerID = $serverInfo["MainServer"];
|
if (!$mainServerID) {
|
!$mainServerID = $serverID;
|
}
|
return array(
|
"Name" => $serverName,
|
"ServerID" => $serverID,
|
"Page" => $Page,
|
"MainServer" => $mainServerID,
|
);
|
}
|
return;
|
}
|
|
/**
|
* 获取游戏服务器地址信息列表
|
* @param string $spid 运营id
|
* @param array $serverIDArray 服务器ID数组,为空时返回所有服务器
|
* @return array (mainServerID=>("MixServerIDList"=>(区服ID1,2,3,...), "Page"=>"主服地址"), ...)
|
*/
|
function GetGameServerPageInfo($spid, $serverIDArray = null)
|
{
|
$serverArray = array();
|
$ConfigFile = dirname(__FILE__) . "\\..\\Account\Server\Server_" . $spid . ".ini";
|
if (!file_exists($ConfigFile)) {
|
return $serverArray;
|
}
|
|
$serverCfg = parse_ini_file($ConfigFile, true);
|
|
foreach ($serverCfg as $serverInfo) {
|
$Page = $serverInfo["Page"];
|
$serverID = $serverInfo["ServerID"];
|
$mainServerID = $serverInfo["MainServer"];
|
if (!$mainServerID) {
|
!$mainServerID = $serverID;
|
}
|
if (!$mainServerID) {
|
continue;
|
}
|
if (!$serverID) {
|
continue;
|
}
|
$serverID = intval($serverID);
|
|
if ($serverIDArray) {
|
if (in_array($serverID, $serverIDArray)) {
|
$serverArray[$mainServerID] = array("Page" => $Page);
|
break;
|
}
|
continue;
|
}
|
|
if (!array_key_exists($mainServerID, $serverArray)) {
|
$serverArray[$mainServerID] = array("MixServerIDList" => array(), "Page" => $Page);
|
}
|
array_push($serverArray[$mainServerID]["MixServerIDList"], $serverID);
|
}
|
return $serverArray;
|
}
|
|
/**
|
* 发送GMT命令到游戏服务器
|
* @param bool $isSuperGMT 是否高级命令
|
* @param string $pack_type GMT命令,一般是 GMT_XXX
|
* @param array $pack_data 命令参数数值
|
* @param string $spid 运营id
|
* @param array $serverIDArray 服务器ID数组,为空时发给所有服务器
|
* @return 返回发送结果列表
|
*/
|
function SendGMTToGameServers($isSuperGMT, $pack_type, $pack_data, $spid, $serverIDArray = null)
|
{
|
$serverPageInfo = \CommFunc\GetGameServerPageInfo($spid, $serverIDArray);
|
if (count($serverPageInfo) <= 0) {
|
return;
|
}
|
|
if ($isSuperGMT) {
|
\CommFunc\GetKeyFromConfig(dirname(__FILE__) . '\\..\\InterfaceConfig.php', "Config", "GMKey2", $key);
|
} else {
|
\CommFunc\GetKeyFromConfig(dirname(__FILE__) . '\\..\\InterfaceConfig.php', "Config", "GMKey", $key);
|
}
|
|
$pack_data["pack_type"] = $pack_type;
|
$pack_data["key"] = $key;
|
$pack_data["coding"] = "utf8";
|
|
$mainServerID = 0;
|
$sendServers = array();
|
foreach ($serverPageInfo as $mainServerID => $serverInfo) {
|
//其他每个服可能不同的参数处理
|
//$pack_data[""] = "";
|
|
//使用key加密
|
$pack_data_dict = json_encode($pack_data);
|
$sign = md5($pack_data_dict . $key);
|
$post = array();
|
$post['pack'] = $pack_data_dict;
|
$post['sign'] = $sign;
|
$post['toServerID'] = $mainServerID;
|
|
$sendServers[$mainServerID] = array($mainServerID, $serverInfo['Page'], $post);
|
}
|
|
if (count($sendServers) == 1) {
|
$retStr = \CommFunc\DoPost($sendServers[$mainServerID][1], $sendServers[$mainServerID][2]);
|
$ServerIDValues = array_values($serverIDArray);
|
$ServerID = $ServerIDValues[0];
|
$retList = array($ServerID => $retStr);
|
} else {
|
$retList = \CommFunc\DoPostMulti($sendServers);
|
}
|
return $retList;
|
}
|
|
/**
|
* 向指定游戏服务器发送个人邮件
|
* @param string $spid 渠道id
|
* @param string $serverID 服务器id,账号对应的服务器id即可
|
* @param string $title 邮件标题
|
* @param string $content 邮件内容
|
* @param array $playerList 目标玩家列表,可以是账号、角色名、仙盟id,由 queryType 参数决定,默认为账号
|
* @param array $itemList 物品列表,[[itemID,个数,可选参数是否拍品], ...]
|
* @param int $endDays 有效天数,默认30
|
* @param string $queryType 决定参数 playerList 中的玩家类型
|
* @return 返回发送结果列表
|
*/
|
function SendMailPersonal($spid, $serverID, $title, $content, $playerList, $itemList, $endDays = 30, $queryType = "accID")
|
{
|
// 参数值必须都是字符串
|
$pack_data = array();
|
$pack_data["playerList"] = implode(",", $playerList);
|
$pack_data["queryType"] = $queryType;
|
$pack_data['playerFind'] = "0"; // 实际不用该参数,兼容旧版用
|
|
$pack_data['EndTime'] = date('Y-m-d', strtotime('+' . $endDays . ' day')) . " 00:00:00";
|
$pack_data["Title"] = $title;
|
$pack_data["Text"] = $content;
|
$pack_data["Gold"] = "0";
|
$pack_data["GoldPaper"] = "0";
|
$pack_data["Silver"] = "0";
|
|
# 物品信息
|
$pack_data["itemNums"] = implode(",", array_keys($itemList));
|
foreach ($itemList as $itemIndex => $itemInfo) {
|
$pack_data["ItemID" . $itemIndex] = "" . $itemInfo[0];
|
$pack_data["ItemCnt" . $itemIndex] = "" . $itemInfo[1];
|
$pack_data["IsBind" . $itemIndex] = "" . (count($itemInfo) > 2 ? $itemInfo[2] : 0);
|
}
|
|
\Logging\LogInfo("SendMailPersonal: spid=" . $spid . " serverID=" . $serverID . " pack_data:" . print_r($pack_data, true));
|
|
$serverIDArray = array($serverID);
|
$retList = \CommFunc\SendGMTToGameServers(true, "GMT_AddPersonalCompensation", $pack_data, $spid, $serverIDArray);
|
if (!$retList || !is_array($retList)) {
|
\Logging\LogError("retList error:" . $retList);
|
return array(false, null);
|
}
|
$ret = json_decode($retList[$serverID], true);
|
if (!$ret || !array_key_exists("ResultType", $ret) || $ret["ResultType"] != 0) {
|
\Logging\LogError("error retList:" . print_r($retList, true));
|
return array(false, $ret);
|
}
|
\Logging\LogInfo("retList:" . print_r($retList, true));
|
return array(true, $ret);
|
}
|
|
/**
|
* 查询流向数据
|
* @param \User\User $user
|
*/
|
function QueryEventData($user, &$retList)
|
{
|
\Logging\LogInfo("QueryEventData _POST:" . print_r($_POST, true));
|
|
$pack_data = $_POST;
|
|
$sendServers = array();
|
$serversArray = $user->GetServers();
|
$onlyServerID = $_POST['OnlyServerID'];
|
// 多服查询的
|
if ($_POST["MultiServer"] == 1) {
|
// $onlyServerID = 0; // 默认0
|
foreach ($serversArray as $serverName => $serverInfo) {
|
$postServerName = urlencode($serverName);
|
if (!array_key_exists($postServerName, $_POST)) {
|
continue;
|
}
|
if (!$_POST[$postServerName] == 'on') {
|
continue;
|
}
|
unset($pack_data[$postServerName]);
|
|
if ($serverInfo['MainServer'] && !$onlyServerID && $serverInfo['MainServer'] != $serverInfo['ServerID']) {
|
# 有主服的代表是合服的,只发主服;因为子服是同一台服务器,没必要重复发送
|
continue;
|
}
|
$sendServers[] = array($serverName, GetQueryEventToolUrl($serverInfo['Page'], array()));
|
}
|
} else if ($_SESSION['server_id']) {
|
$sendServers[] = array($_SESSION['server_id'], GetQueryEventToolUrl($_SESSION['tool_page']), array());
|
}
|
|
if (!$sendServers) {
|
echo "Error. " . \Lang\gettext("请先选择服务器");
|
return;
|
}
|
|
// 去除参数
|
unset($pack_data['submit']);
|
unset($pack_data["OnlyServerID"]);
|
unset($pack_data["server_select_all"]);
|
|
$pack_data["spID"] = $user->GetSPID();
|
for ($i = 0; $i < count($sendServers); $i++) {
|
$serverName = $sendServers[$i][0];
|
if ($serversArray[$serverName]["MixServerStr"]) {
|
$pack_data["mixServerIDInfo"] = $serversArray[$serverName]["MixServerStr"];
|
} else {
|
$pack_data["mixServerIDInfo"] = $serversArray[$serverName]["ServerID"];
|
}
|
$pack_data["serverID"] = $serversArray[$serverName]["ServerID"];
|
$pack_data["mainServer"] = $serversArray[$serverName]["MainServer"];
|
if ($onlyServerID) {
|
$pack_data["OnlyServerID"] = $pack_data["serverID"];
|
}
|
$sendServers[$i][2] = $pack_data;
|
}
|
|
\Logging\LogInfo("待发送的服务器信息: " . count($sendServers) . " " . print_r($sendServers, true));
|
|
if (count($sendServers) == 1) {
|
$retStr = DoPost($sendServers[0][1], $sendServers[0][2]);
|
$ret = json_decode($retStr, true);
|
if (!isset($ret)) {
|
$retList[$sendServers[0][0]] = $retStr;
|
} else {
|
$retList[$sendServers[0][0]] = $ret;
|
}
|
} else {
|
$retMulti = DoPostMulti($sendServers);
|
if ($retMulti && count($retMulti) == count($sendServers)) {
|
for ($i = 0; $i < count($sendServers); $i++) {
|
$ret = json_decode($retMulti[$i], true);
|
if (!isset($ret)) {
|
$retList[$sendServers[$i][0]] = $retMulti[$i];
|
} else {
|
$retList[$sendServers[$i][0]] = $ret;
|
}
|
}
|
}
|
}
|
$retCount = count($retList);
|
\Logging\LogInfo("返回查询结果条数: " . $retCount);
|
// \Logging\LogInfo("返回查询结果: " . $retCount . " " . print_r($retList, true));
|
}
|
|
/**获取目标服务器流向查询url地址 */
|
function GetQueryEventToolUrl($tool_page)
|
{
|
// 在原GM工具地址下同层级
|
return substr($tool_page, 0, -strlen("tool.php")) . "eventdata/tool.php";
|
}
|
|
#批量进行post请求
|
function DoPostMulti($sendServers)
|
{
|
if (!is_array($sendServers))
|
return false;
|
|
$handle = array();
|
foreach ($sendServers as $key => $value) {
|
$server_url = $value[1];
|
$post = $value[2];
|
$ch = curl_init();
|
curl_setopt($ch, CURLOPT_URL, $server_url);
|
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
$handle[$key] = $ch;
|
}
|
|
//创建批处理curl句柄
|
$mh = curl_multi_init();
|
//将单个curl句柄添加到批处理curl句柄中
|
foreach ($handle as $ch) {
|
curl_multi_add_handle($mh, $ch);
|
}
|
$active = null;
|
/* 执行 */
|
do {
|
$mrc = curl_multi_exec($mh, $active);
|
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
|
// 升级5.5版本后, curl_multi_select 一直等于-1,导致不执行 curl_multi_exec ,然后卡到超时,暂不明原因,先特殊处理
|
if (CheckVersion(phpversion(), "5.5.0") >= 0) {
|
do {
|
usleep(10000); // 10ms
|
curl_multi_exec($mh, $active);
|
// \Logging\LogInfo("while active:" . $active);
|
} while ($active > 0);
|
} else {
|
while ($active && $mrc == CURLM_OK) {
|
if (curl_multi_select($mh) != -1) {
|
do {
|
$mrc = curl_multi_exec($mh, $active);
|
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
|
}
|
}
|
}
|
|
$data = array();
|
/* 读取资料 */
|
foreach ($handle as $key => $ch) {
|
$content = curl_multi_getcontent($ch);
|
//$data[$i] = (curl_errno($ch) == 0) ? $content : false;
|
$data[$key] = $content;
|
}
|
/* 移除 handle*/
|
foreach ($handle as $ch) {
|
curl_multi_remove_handle($mh, $ch);
|
}
|
curl_multi_close($mh);
|
return $data;
|
}
|
|
#进行post请求
|
function DoPost($url, $post, $passSession = false, $timeout = 30)
|
{
|
$ch = curl_init();
|
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
if ($passSession) {
|
curl_setopt($ch, CURLOPT_COOKIE, 'PHPSESSID=' . $_COOKIE['PHPSESSID']);
|
}
|
$result = curl_exec($ch);
|
curl_close($ch);
|
unset($ch);
|
return $result;
|
}
|
|
#进行postjson请求
|
function DoPostJson($url, $post)
|
{
|
$ch = curl_init();
|
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_HEADER, false);
|
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
|
$result = curl_exec($ch);
|
curl_close($ch);
|
unset($ch);
|
return $result;
|
}
|
|
|
|
#进行Get请求
|
function DoGet($url, $get, $delay = 30)
|
{
|
$getData = http_build_query($get);
|
$getData = str_replace("%3D", "=", $getData);
|
$url = $url . '?' . $getData;
|
$ch = curl_init($url);
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
|
curl_setopt($ch, CURLOPT_TIMEOUT, $delay);
|
$result = curl_exec($ch);
|
curl_close($ch);
|
unset($ch);
|
return $result;
|
}
|
|
function curl_get($url, $get, $timeout = 10)
|
{
|
$getData = http_build_query($get);
|
$getData = str_replace("%3D", "=", $getData);
|
$url = $url . '?' . $getData;
|
$ch = curl_init();
|
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
$ret = curl_exec($ch);
|
curl_close($ch);
|
unset($ch);
|
return $ret;
|
}
|
|
function curl_post($url, $post, $timeout = 10, $bulid = false)
|
{
|
$ch = curl_init();
|
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $bulid ? http_build_query($post) : json_encode($post));
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
$ret = curl_exec($ch);
|
curl_close($ch);
|
unset($ch);
|
return $ret;
|
}
|
|
/**
|
* 使用 SessionStart SessionSave
|
* 防止出现 session_start 时该php还未执行完毕又调用另一个存在 session_start 的php时卡主的问题
|
* 比如 a.php 页面逻辑中有 post 到 b.php 的逻辑时,a b两页面同时session_start时会卡主
|
* 原因:因为 session_start 后会锁住该回话session文件,直到回话结束,可以使用 session_write_close 释放该session锁,防止同时调用 session_start 卡主
|
*/
|
function SessionStart()
|
{
|
session_start();
|
session_write_close();
|
}
|
|
function SessionSave($set)
|
{
|
session_start();
|
foreach ($set as $key => $value) {
|
$_SESSION[$key] = $value;
|
}
|
session_write_close();
|
}
|
|
// 测试http请求
|
function TestQuery($url, $data, $method = "Get", $resultFunc = null)
|
{
|
echo '<pre>url:' . $url . "\n";
|
echo '参数:' . var_export($data, true) . "\n";
|
$method = $method ? ucfirst(strtolower($method)) : "Get";
|
echo '请求类型: ' . $method . "\n";
|
$func = "\CommFunc\Do{$method}";
|
$result = $func($url, $data);
|
if ($resultFunc) $result = $resultFunc($result);
|
echo '结果:' . var_export($result, true) . "\n\n</pre>";
|
return $result;
|
}
|
|
//字符串时间格式的数据转换成time格式的,如2000-02-12 16:20:35转成time 950368835
|
function StrDateTimeToTime($strDateTime)
|
{
|
$array = explode("-", $strDateTime);
|
$year = $array[0];
|
$month = $array[1];
|
|
$array = explode(":", $array[2]);
|
$minute = $array[1];
|
$second = $array[2];
|
|
$array = explode(" ", $array[0]);
|
$day = $array[0];
|
$hour = $array[1];
|
|
$timestamp = mktime($hour, $minute, $second, $month, $day, $year);
|
return $timestamp;
|
}
|
|
//time格式转换成字符串时间格式,如time 950368835转成2000-02-12 16:20:35
|
function TimeToStrDateTime($time, $format = "Y-m-d H:i:s")
|
{
|
return date($format, $time);
|
}
|
|
/**
|
* 计算时间转化为字符串时间
|
* @param string $datetime The string to parse. Before PHP 5.0.0, microseconds weren't allowed in the time, since PHP 5.0.0 they are allowed but ignored.
|
*/
|
function CalcToStrDateTime($datetime, $format = "Y-m-d H:i:s")
|
{
|
return TimeToStrDateTime(strtotime($datetime, StrDateTimeToTime(date($format))), $format);
|
}
|
|
/**
|
* 字符串时间格式转换
|
* @param string $datetimeStr 需要转化的时间字符串
|
* @param string $format 需要转化的格式,默认 Y-m-d H:i:s , 或 DATE_ISO8601 等
|
* @return string 返回转化后的时间格式字符串
|
*/
|
function StrDateTimeFormatConver($datetimeStr = "", $format = "Y-m-d H:i:s")
|
{
|
if ($datetimeStr == "") {
|
$datetimeStr = date("Y-m-d H:i:s");
|
}
|
$time2 = strtotime($datetimeStr);
|
return date($format, $time2);
|
}
|
|
#加解密算法需要的定义
|
|
#加密的次数
|
const NUM_ENCODE_CNT = 3;
|
#异或的key
|
const NUM_XOR_KEY = 151;
|
|
#公司内部通用解密算法
|
function GetDecodePsw($strPsw)
|
{
|
$strResult = $strPsw;
|
for ($nIndex = 0; $nIndex < NUM_ENCODE_CNT; $nIndex++) {
|
$strResult = base64_decode($strResult);
|
}
|
|
$nLen = strlen($strResult);
|
for ($nIndex = 0; $nIndex < $nLen; $nIndex++) {
|
$strResult[$nIndex] = chr(ord($strResult[$nIndex]) ^ NUM_XOR_KEY);
|
}
|
|
return $strResult;
|
}
|
|
#公司内部用加密算法
|
function GetEncodePsw($strPsw)
|
{
|
$strResult = $strPsw;
|
$nLen = strlen($strResult);
|
|
for ($nIndex = 0; $nIndex < $nLen; $nIndex++) {
|
$strResult[$nIndex] = chr(ord($strResult[$nIndex]) ^ NUM_XOR_KEY);
|
}
|
|
for ($nIndex = 0; $nIndex < NUM_ENCODE_CNT; $nIndex++) {
|
$strResult = base64_encode($strResult);
|
}
|
|
return $strResult;
|
}
|
|
#数字字符串转换为数字
|
function NumStringToNum($strSrc)
|
{
|
if (!is_numeric($strSrc)) {
|
return intval($strSrc);
|
}
|
|
return $strSrc;
|
}
|
|
#全局接收,不管是POST或者GET调用此接口即可
|
#$ProcessFunc:函数定义必须是$ProcessFunc($RecvArray, $Decribe),$RecvArray可能是$_POST或者$_GET, $Decribe相对的是POST或者GET
|
function GLOBAL_RECV($ProcessFunc)
|
{
|
if (!function_exists($ProcessFunc)) {
|
\Logging\LogError("not exist func:" . $ProcessFunc);
|
return;
|
}
|
$RecvArray = $_GET;
|
$Decribe = 'GET';
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
$RecvArray = $_POST;
|
$Decribe = 'POST';
|
}
|
|
$ProcessFunc($RecvArray, $Decribe);
|
}
|
|
#二进制转换为十六进制的字符串,每个字符中间用空格隔开,便于查看
|
function BinToStr($strSource)
|
{
|
$nLen = strlen($strSource);
|
|
$strHexConverted = '0x';
|
for ($nIndex = 0; $nIndex < $nLen; $nIndex++) {
|
$strHexConverted = $strHexConverted . bin2hex($strSource{
|
$nIndex}) . ' ';
|
}
|
|
return $strHexConverted;
|
}
|
|
#记录错误日志信息的同时打印到浏览器上
|
function LogErrorAndPrint($strError)
|
{
|
\Logging\LogError($strError);
|
echo $strError;
|
}
|
|
function str_xor($astring, $xornum = 150)
|
{
|
$ret = '';
|
$nLen = strLen($astring);
|
for ($nIndex = 0; $nIndex < $nLen; $nIndex++) {
|
$ret .= chr(ord($astring[$nIndex]) ^ $xornum);
|
}
|
return $ret;
|
}
|
|
function ParseBuff($buff)
|
{
|
$ret = '';
|
$nLen = strLen($buff);
|
for ($nIndex = 0; $nIndex < $nLen; $nIndex++) {
|
if ($nIndex % 2 == 0 && $nIndex != 0) {
|
$ret = $ret . ' ' . $buff[$nIndex];
|
} else {
|
$ret = $ret . $buff[$nIndex];
|
}
|
}
|
return $ret;
|
}
|
|
/**
|
* 客户端IP,
|
*/
|
function GetIP()
|
{
|
if (@$_SERVER["HTTP_X_FORWARDED_FOR"])
|
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
|
else if (@$_SERVER["HTTP_CLIENT_IP"])
|
$ip = $_SERVER["HTTP_CLIENT_IP"];
|
else if (@$_SERVER["REMOTE_ADDR"])
|
$ip = $_SERVER["REMOTE_ADDR"];
|
else if (@getenv("HTTP_X_FORWARDED_FOR"))
|
$ip = getenv("HTTP_X_FORWARDED_FOR");
|
else if (@getenv("HTTP_CLIENT_IP"))
|
$ip = getenv("HTTP_CLIENT_IP");
|
else if (@getenv("REMOTE_ADDR"))
|
$ip = getenv("REMOTE_ADDR");
|
else
|
$ip = "Unknown";
|
if (preg_match('/^((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1 -9]?\d))))$/', $ip))
|
return $ip;
|
else
|
return '';
|
return $ip;
|
}
|
|
/**
|
* 服务器端IP
|
* @return string
|
*/
|
function ServerIP()
|
{
|
return gethostbyname($_SERVER["SERVER_NAME"]);
|
}
|
|
/**
|
* 是否内网测试
|
*/
|
function IsInnerTest()
|
{
|
return GetIP() == "127.0.0.1" || substr(GetIP(), 0, 8) == "192.168.";
|
}
|
|
//获得当前的年月
|
function GetMonth()
|
{
|
return date("Y-m", time());
|
}
|
|
//获得当前的年月日
|
function GetDay()
|
{
|
return date("Y-m-d", time());
|
}
|
|
//获得兑换历史记录对象
|
function GetExchangeHistorySaveObj($strDirName = 'ExchangeHistory', $strFileName = 'DirectionFlow')
|
{
|
return new \MultiLogging\MultiLogging(dirname(__FILE__) . "\\..", $strDirName, $strFileName);
|
}
|
|
function guid()
|
{
|
if (function_exists('com_create_guid')) {
|
return com_create_guid();
|
} else {
|
mt_srand((float) microtime() * 10000); //optional for php 4.2.0 and up.
|
$charid = strtoupper(md5(uniqid(rand(), true)));
|
$hyphen = chr(45); // "-"
|
$uuid = chr(123) // "{"
|
. substr($charid, 0, 8) . $hyphen
|
. substr($charid, 8, 4) . $hyphen
|
. substr($charid, 12, 4) . $hyphen
|
. substr($charid, 16, 4) . $hyphen
|
. substr($charid, 20, 12)
|
. chr(125); // "}"
|
return $uuid;
|
}
|
}
|
|
function GetBrowser()
|
{
|
$agent = $_SERVER["HTTP_USER_AGENT"];
|
|
if (strpos($agent, 'MSIE') !== false) {
|
$agentArr = explode('.', strstr($agent, 'MSIE'));
|
return $agentArr[0];
|
} else if (strpos($agent, 'rv:11.0'))
|
return 'IE11';
|
else if (strpos($agent, 'Firefox') !== false) {
|
$agentArr = explode('.', strstr($agent, 'Firefox'));
|
return $agentArr[0];
|
} else if (strpos($agent, 'OPR') !== false) {
|
$agentArr = explode('.', strstr($agent, 'OPR'));
|
return $agentArr[0];
|
} else if (strpos($agent, 'QQBrowser') !== false) {
|
$agentArr = explode('.', strstr($agent, 'QQBrowser'));
|
return $agentArr[0];
|
} else if (strpos($agent, 'SE 2') !== false) {
|
$agentArr = explode('.', strstr($agent, 'SE 2'));
|
return $agentArr[0];
|
} else if (strpos($agent, 'BIDUBrowser') !== false) {
|
$agentArr = explode('.', strstr($agent, 'BIDUBrowser'));
|
return $agentArr[0];
|
} else if (strpos($agent, 'LBBROWSER') !== false) {
|
return 'LBBROWSER';
|
} else if (strpos($agent, 'Edge') !== false) {
|
$agentArr = explode('.', strstr($agent, 'Edge'));
|
return $agentArr[0];
|
} else if (strpos($agent, 'Chrome') !== false) {
|
$agentArr = explode('.', strstr($agent, 'Chrome'));
|
return $agentArr[0];
|
} else if (strpos($agent, 'Safari') !== false) {
|
$agentArr = explode('.', strstr($agent, 'Safari'));
|
return $agentArr[0];
|
} else
|
return 'others';
|
}
|
|
function GetOS()
|
{
|
$agent = $_SERVER["HTTP_USER_AGENT"];
|
|
if (strpos($agent, 'NT 5.1') !== false) {
|
return 'Windows XP';
|
} else if (strpos($agent, 'NT 6.1') !== false) {
|
return 'Windows 7';
|
} else if (strpos($agent, 'NT 5.2') !== false) {
|
return 'Windows 8';
|
} else if (strpos($agent, 'NT 10') !== false) {
|
return 'Windows 10';
|
} else if (strpos($agent, 'Windows') !== false) {
|
return 'Windows';
|
} else
|
return 'others';
|
}
|
|
|
function myopen($reportHost, $reportPort, $reportUrl, $reportData)
|
{
|
$fp = fsockopen($reportHost, $reportPort, $errno, $errstr, 1);
|
if (!$fp) {
|
\Logging\LogInfo('fsockopen error' . $errno . $errstr);
|
} else {
|
stream_set_blocking($fp, 0);
|
$getData = http_build_query($reportData);
|
$getData = str_replace("%3D", "=", $getData);
|
$url = $reportUrl . '?' . $getData;
|
|
$out = "GET " . $url . " HTTP/1.1\r\n";
|
$out .= "Host: " . $reportHost . "\r\n";
|
$out .= "Connection: Close\r\n\r\n";
|
|
fwrite($fp, $out);
|
fclose($fp);
|
}
|
}
|
|
#进行Get请求 毫秒级超时
|
function MS_DoGet($url, $get)
|
{
|
$getData = http_build_query($get);
|
$getData = str_replace("%3D", "=", $getData);
|
$url = $url . '?' . $getData;
|
$ch = curl_init($url);
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
|
curl_setopt($ch, CURLOPT_NOSIGNAL, true);
|
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 100);
|
$result = curl_exec($ch);
|
curl_close($ch);
|
unset($ch);
|
return $result;
|
}
|
|
function GetFileContents($filePath, $defaultContent = "", $isutf8 = true)
|
{
|
$c = "";
|
if (file_exists($filePath)) {
|
$c = file_get_contents($filePath);
|
}
|
if (!$c) {
|
$c = $defaultContent;
|
}
|
if ($isutf8) {
|
return TrimUTF8BOM($c);
|
}
|
return $c;
|
}
|
|
# 去除UTF8 BOM 头
|
function TrimUTF8BOM($str)
|
{
|
return trim($str, "\xEF\xBB\xBF");
|
}
|
|
/**
|
* 数组转化为Json,支持utf8中文处理,如需要排版格式化则在调用 JsonFormat
|
* json_encode 值支持utf8
|
* 数组中所有中文在json_encode之后都不见了或者出现\u2353等。
|
* 解决方法是用 urlencode()函数处理以下,在json_encode之前,把所有数组内所有内容都用urlencode()处理一下
|
* 然用json_encode()转换成json字符串,最后再用urldecode()将编码过的中文转回来。
|
*/
|
function MyJson_encode($code)
|
{
|
$code = json_encode(urlencodeAry($code));
|
return urldecode($code);
|
}
|
|
# 对数组内容进行 urlencode
|
function urlencodeAry($data)
|
{
|
if (is_array($data)) {
|
foreach ($data as $key => $val) {
|
$data[$key] = urlencodeAry($val);
|
}
|
return $data;
|
} elseif (is_string($data)) {
|
return urlencode($data);
|
} else {
|
return $data;
|
}
|
}
|
|
/**
|
* Json数据格式化
|
* @param String $data json数据字符串
|
* @param String $indent 缩进字符,默认4个空格
|
* @return 排版格式化后的Json字符串
|
*/
|
function JsonFormat($data, $indent = null)
|
{
|
// 缩进处理
|
$ret = '';
|
$pos = 0;
|
$length = strlen($data);
|
$indent = isset($indent) ? $indent : ' ';
|
$newline = "\r\n";
|
$prevchar = '';
|
$outofquotes = true;
|
|
for ($i = 0; $i <= $length; $i++) {
|
|
$char = substr($data, $i, 1);
|
|
if ($char == '"' && $prevchar != '\\') {
|
$outofquotes = !$outofquotes;
|
} elseif (($char == '}' || $char == ']') && $outofquotes) {
|
$ret .= $newline;
|
$pos--;
|
for ($j = 0; $j < $pos; $j++) {
|
$ret .= $indent;
|
}
|
}
|
|
$ret .= $char;
|
|
if (($char == ',' || $char == '{' || $char == '[') && $outofquotes) {
|
$ret .= $newline;
|
if ($char == '{' || $char == '[') {
|
$pos++;
|
}
|
|
for ($j = 0; $j < $pos; $j++) {
|
$ret .= $indent;
|
}
|
}
|
|
$prevchar = $char;
|
}
|
|
return $ret;
|
}
|
|
static $CfgKeyNameContent = null;
|
function getCfgKeyNameContent($cfgName, $toArray, $spid = "")
|
{
|
global $CfgKeyNameContent;
|
if (!isset($CfgKeyNameContent)) {
|
$CfgKeyNameContent = array();
|
}
|
if (!array_key_exists($cfgName, $CfgKeyNameContent)) {
|
if (!$spid) {
|
$spid = $_SESSION['spid'];
|
}
|
$lang = \Lang\getLang();
|
$fdir = dirname(__FILE__) . "\config\\" . $spid . "\\" . $lang . "\\" . $cfgName . ".txt";
|
if (!file_exists($fdir)) {
|
$fdir = dirname(__FILE__) . "\config\\" . $spid . "\\" . $cfgName . ".txt";
|
}
|
$kvArray = array();
|
if (file_exists($fdir)) {
|
$rf = fopen($fdir, "r");
|
while (!feof($rf)) {
|
$line = trim(fgets($rf));
|
if (!$line) {
|
continue;
|
}
|
$ls = explode("\t", $line);
|
$kvArray[$ls[0]] = $ls[1];
|
}
|
} else {
|
echo "file is not exist: " . $fdir, "<br/>";
|
}
|
$CfgKeyNameContent[$cfgName] = $kvArray;
|
}
|
$kvArray = $CfgKeyNameContent[$cfgName];
|
if ($toArray) {
|
return $kvArray;
|
}
|
return MyJson_encode($kvArray);
|
}
|
|
static $SPConfig = null;
|
/**
|
* 获取sp运营项目对应专属配置
|
* @param string $section 配置节点
|
* @param string $option 配置项
|
* @param string $value 获取对应的值对象
|
* @param string $toArray 是否转为array,默认false
|
* @return 是否成功获取到配置
|
*/
|
function GetSPConfig($section, $option, &$value, $toArray = false)
|
{
|
global $SPConfig;
|
if (!isset($SPConfig)) {
|
$spid = $_SESSION['spid'];
|
$iniPath = dirname(__FILE__) . "\config\\" . $spid . "\\config.ini";
|
if (!file_exists($iniPath)) {
|
return false;
|
}
|
|
$SPConfig = parse_ini_file($iniPath, true);
|
}
|
|
if (array_key_exists($section, $SPConfig) && array_key_exists($option, $SPConfig[$section])) {
|
$value = $SPConfig[$section][$option];
|
if ($toArray) {
|
$value = json_decode($value, true);
|
}
|
} else {
|
// 不存在该配置
|
}
|
return true;
|
}
|
|
function getPayOrderTypeName($payOrderType)
|
{
|
$PayOrderTypeName = array(
|
1 => \Lang\gettext("人民币"),
|
2 => \Lang\gettext("美元"),
|
3 => \Lang\gettext("越南盾"),
|
4 => \Lang\gettext("soha币"),
|
5 => \Lang\gettext("金票点券"),
|
6 => \Lang\gettext("代币"),
|
);
|
if (!array_key_exists($payOrderType, $PayOrderTypeName)) {
|
return \Lang\gettext("未知订单类型");
|
}
|
return $PayOrderTypeName[$payOrderType];
|
}
|
|
function getPayOrderCoinRate($payOrderType)
|
{
|
$rateSet = array(
|
3 => 1,
|
6 => 1,
|
);
|
if (!array_key_exists($payOrderType, $rateSet)) {
|
return 100;
|
}
|
return $rateSet[$payOrderType];
|
}
|
|
function startsWith($text, $prefix)
|
{
|
return strpos($text, $prefix) === 0;
|
}
|
|
// 邮件类型
|
function GetMailTypes()
|
{
|
return json_decode(GetFileContents(dirname(__FILE__) . "/mailtypes.json", "[]"), true);
|
}
|
|
// 组合服务器ID查询条件,搭配 common.js AddServerIDCondition 使用
|
function MatchServerIDCond(&$find, &$serverIDCondArray)
|
{
|
if (!isset($serverIDCondArray)) {
|
$serverIDCondArray = array();
|
}
|
$serverIDCondNumMax = 20;
|
$serverIDCondIn = array();
|
$serverIDCondFind = array();
|
for ($i = 1; $i < $serverIDCondNumMax + 1; $i++) {
|
if (!array_key_exists("ServerIDGTE" . $i, $_POST)) {
|
continue;
|
}
|
$eValue = intval($_POST["ServerIDE" . $i]);
|
$gteValue = intval($_POST["ServerIDGTE" . $i]);
|
$lteValue = intval($_POST["ServerIDLTE" . $i]);
|
// \Logging\LogInfo("serverIDCond." . $i . " : eValue:" . $eValue . " gteValue:" . $gteValue . " lteValue:" . $lteValue);
|
if ($eValue <= 0 && $gteValue <= 0 && $lteValue <= 0) {
|
continue;
|
}
|
if ($gteValue > 0 && $lteValue > 0 && $gteValue > $lteValue) {
|
continue;
|
}
|
if ($eValue > 0) {
|
array_push($serverIDCondIn, $eValue);
|
}
|
$cond = array();
|
if ($gteValue > 0) {
|
$cond['$gte'] = $gteValue;
|
}
|
if ($lteValue > 0) {
|
$cond['$lte'] = $lteValue;
|
}
|
if (count($cond)) {
|
array_push($serverIDCondFind, array("ServerID" => $cond));
|
}
|
array_push($serverIDCondArray, array($eValue, $gteValue, $lteValue));
|
}
|
if (count($serverIDCondIn) > 0) {
|
array_push($serverIDCondFind, array("ServerID" => array('$in' => $serverIDCondIn)));
|
}
|
if (count($serverIDCondFind) > 0) {
|
$find['$or'] = $serverIDCondFind;
|
}
|
// \Logging\LogInfo("find:" . json_encode($find));
|
}
|
|
// 组合服务器ID列表,搭配 common.js AddServerIDCondition 使用
|
function MatchServerIDList(&$serverIDCondArray, &$serverIDList)
|
{
|
if (!isset($serverIDCondArray)) {
|
$serverIDCondArray = array();
|
}
|
if (!isset($serverIDList)) {
|
$serverIDList = array();
|
}
|
$serverIDCondNumMax = 20;
|
for ($i = 1; $i < $serverIDCondNumMax + 1; $i++) {
|
if (!array_key_exists("ServerIDGTE" . $i, $_POST)) {
|
continue;
|
}
|
$eValue = intval($_POST["ServerIDE" . $i]);
|
$gteValue = intval($_POST["ServerIDGTE" . $i]);
|
$lteValue = intval($_POST["ServerIDLTE" . $i]);
|
// \Logging\LogInfo("serverIDCond." . $i . " : eValue:" . $eValue . " gteValue:" . $gteValue . " lteValue:" . $lteValue);
|
if ($eValue <= 0 && $gteValue <= 0 && $lteValue <= 0) {
|
continue;
|
}
|
if ($gteValue > 0 && $lteValue > 0 && $gteValue > $lteValue) {
|
continue;
|
}
|
if ($eValue > 0) {
|
array_push($serverIDList, array($eValue, $eValue));
|
}
|
if ($gteValue > 0 && $lteValue > 0) {
|
array_push($serverIDList, array($gteValue, $lteValue));
|
} else if ($gteValue > 0) {
|
array_push($serverIDList, array($gteValue, 10000));
|
} else if ($lteValue > 0) {
|
array_push($serverIDList, array(1, $lteValue));
|
}
|
array_push($serverIDCondArray, array($eValue, $gteValue, $lteValue));
|
}
|
}
|