hxp
2025-06-09 6c3f6335c70859ded94a1ad8d218acb0ac34239c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
include_once '/Common/CommFunc.php';
include_once '/Common/Logging.php';
include_once "/db/DBOper.php";
include_once "/ProjComm/CfgReader.php";
 
header("Content-type: text/html; charset=utf-8");
 
// https://docs.aldgames.com/docs/al-sdk#18rmb
 
\Logging\CreateLogging("serverops.hy.report_server.php");
\Logging\LogInfo("_POST: " . print_r($_POST, true));
$channel = $_POST["channel"];
$server_id = intval($_POST["server_id"]);
 
if (
    !\CfgReader\ReadConfig()
    || !\CfgReader\GetConfigData("Quick", "Key_" . $channel . "_Callback_Key", $Callback_Key)
    || !\CfgReader\GetConfigData("report_server", "game_id", $gameIDInfo)
    || !\CfgReader\GetConfigData("report_server", "jsonbranch", $jsonbranch)
) {
    exit;
}
// \Logging\LogInfo("gameIDInfo" . $gameIDInfo);
$gameIDInfo = json_decode($gameIDInfo, true);
if (!isset($gameIDInfo) || !array_key_exists($channel, $gameIDInfo) || !$Callback_Key || !$jsonbranch) {
    exit;
}
$game_id = $gameIDInfo[$channel];
 
if (!DBOper\FindOne("GameServers", array("Channel" => $channel, "ServerID" => $server_id), $serverInfo, null, false) || !isset($serverInfo)) {
    exit;
}
$StartDateStr = $serverInfo["StartDate"];
$JsonBranch = $serverInfo["JsonBranch"];
$ServerName = $serverInfo["ServerName"];
 
// 请求参数
// 属性    描述    类型    必填
// game_id    我方的游戏id,我们运营提供    int    是
// server_id    区服id    String    是
// server_name    区服名称    String    是
// open_time    开服时间,格式yyyy-MM-dd HH:mm:ss    string    是
// timestamp    请求时间,时间戳,精确到秒    int    是
// sign    签名    String    是,通用签名规则
// 响应结果
// 属性    描述    类型    必返
// code    响应码:0成功,1失败    int    是
// msg    响应消息    string    是
// data    响应数据    array    否
 
$postData = array(
    "game_id" => $game_id,
    "server_id" => $server_id,
    "server_name" => $ServerName,
    "open_time" => $StartDateStr,
    "timestamp" => time(),
);
$postData["sign"] = make_sign($postData, $Callback_Key);
 
$postUrl = "https://api.aldgames.com/cp/report_server";
// $postUrl = "http://127.0.0.1:8080/serverops/hy/report_server_t.php";
\Logging\LogInfo("postUrl: " . $postUrl);
\Logging\LogInfo("postData: " . print_r($postData, true));
 
$retStr = \CommFunc\curl_post($postUrl, $postData, 5, true);
\Logging\LogInfo("retStr: " . $retStr);
$ret = json_decode($retStr, true);
if (!isset($ret) || $ret["code"] != 0) {
    \Logging\LogError("errormsg:" . $ret["msg"]);
    echo $retStr;
    exit;
}
\Logging\LogInfo("report_server OK! server_id:" . $server_id);
$ReportSPTime = date("Y-m-d H:i:s");
 
DBOper\Update("GameServers", array("Channel" => $channel, "ServerID" => $server_id), array("ReportSPTime" => $ReportSPTime));
 
$ret["ReportSPTime"] = $ReportSPTime;
echo json_encode($ret);
exit;
 
function make_sign(array $data, $game_key)
{
    if (array_key_exists('sign', $data)) {
        unset($data['sign']);
    }
    ksort($data);
    $_data = [];
    foreach ($data as $k => $v) {
        $_data[] = $k . '=' . $v;
    }
    $str = implode('&', $_data) . '&' . $game_key;
    return sha1(md5($str));
}