hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
include_once '/Common/CommFunc.php';
include_once '/Common/Logging.php';
include_once "/ProjComm/CfgReader.php";
include_once "/language/lang.php";
include_once "/Common/GMTRetCode.php";
 
header("Content-type: text/html; charset=utf-8");
 
$appid = $_GET["spid"];
$postData = $_POST;
\Logging\CreateLogging("quick.mail." . $appid . ".php");
\Logging\LogInfo("appid: " . $appid);
\Logging\LogInfo("postData: " . print_r($postData, true));
 
// `id` int(11) 
// `get_date` date 
// `event_code` char(10) 
// `product_id` int(11)
// `event_rebate_id` int(11) 
// `channel_id` int(11)    必须
// `trigger_order` char(36)
// `trigger_amount` decimal(10,2)
// `order_uid` varchar(100)  必须
// `game_role_id` varchar(100)
// `game_role_name` varchar(100) 
// `server_id` varchar(100)  必须
// `server_name` varchar(100)
// `rebate_type` char(10)
// `rebate_value` varchar(100) 必须
// `create_time` datetime 
// `sign` char(32)
 
// 对收到的参数排除sign进行签名计算
// 需要对参数ksort(data)字典升序排序
// stringA: 构造字符串key1=val1&key2=val2&key3=val3......
// stringB: 对字符串拼接秘钥 stringA&appkey=这里是秘钥
 
// 签名方式: MD5(stringB)
// 返回结果: 成功返回大写的SUCCESS,其他内容为失败,可能返回中文
 
// 重点关注: 
// 1. order_uid (玩家的uid) , channel_id (渠道id), server_id (服务器id)
//   账号组合如 69494792@240@hyx7game@s3 (hyx7game由链接决定)
// 2. rebate_value(返利内容)
// 格式如 标题|邮件内容邮件内容|[[物品1id,物品1数量],[物品2id,物品2数量]]
// 用 | 分割;标题,邮件内容,物品(最多5种)
 
$order_uid = $postData['order_uid'];
$channel_id = $postData['channel_id'];
$server_id = $postData['server_id'];
$rebate_value = $postData['rebate_value'];
$sign = $postData['sign'];
if (!$order_uid || !$server_id || !$rebate_value || !$sign) {
    Ret("ParamError");
    exit;
}
 
if (
    !\CfgReader\ReadConfig()
    || !\CfgReader\GetConfigData("Quick", "Key_" . $appid . "_Mail_Key", $Mail_Key)
) {
    Ret("CfgError");
    exit;
}
 
ksort($postData);
$stringA = "";
foreach ($postData as $key => $value) {
    if ($key == "sign") {
        continue;
    }
    if ($stringA != "") {
        $stringA .= "&";
    }
    $stringA .= $key . "=" . $value;
}
$stringB = $stringA . "&appkey=" . $Mail_Key;
\Logging\LogInfo("stringA: " . $stringA);
\Logging\LogInfo("stringB: " . $stringB);
 
$md5Sign = $sign;
$md5SignLocal = md5($stringB);
\Logging\LogInfo("md5SignLocal: " . $md5SignLocal);
 
if ($md5SignLocal != $md5Sign) {
    Ret("SignError", " md5SignLocal:" . $md5SignLocal . " != md5Sign:" . $md5Sign);
    exit;
}
 
$mailInfo = explode("|", $rebate_value);
if (!$mailInfo || count($mailInfo) != 3) {
    Ret("rebate_value mail split len error.");
    exit;
}
$title = $mailInfo[0];
$content = $mailInfo[1];
$itemArray = json_decode($mailInfo[2], true);;
if (!is_array($itemArray)) {
    Ret("Item json_decode error.");
    exit;
}
$itemLen = count($itemArray);
if ($itemLen > 5) {
    Ret("Item limit 5");
    exit;
}
 
// 验证物品
$itemIDNameInfo = CommFunc\getCfgKeyNameContent("item", true, $appid);
for ($i = 0; $i < $itemLen; $i++) {
    $item = $itemArray[$i];
    if (!is_array($item) || count($item) != 2) {
        Ret("Item format error.");
        exit;
    }
    $itemID = $item[0];
    $itemCount = $item[1];
    if (!array_key_exists($itemID, $itemIDNameInfo)) {
        Ret("ItemID is not exist. itemID=" . $itemID);
        exit;
    }
    if ($itemCount <= 0) {
        Ret("The number of item must be greater than 0. itemID=" . $itemID);
        exit;
    }
}
 
$sserverID = \CommFunc\startsWith($server_id, "s") ? $server_id : ("s" . $server_id);
$accID = $order_uid . "@" . $channel_id . "@" . $appid . "@" . $sserverID;
 
$playerList = array($accID);
 
$result = "FAILED";
list($isOK, $ret) = \CommFunc\SendMailPersonal($appid, $server_id, $title, $content, $playerList, $itemArray);
if ($isOK) {
    $result = "SUCCESS";
}else{
    $result = GetResultTypeMsg($ret["ResultType"]);
}
Ret($result);
exit;
 
function Ret($ret, $msg = "")
{
    echo $ret;
    $logMsg = $ret;
    if ($msg) {
        $logMsg .= " msg => " . $msg;
    }
    if ($ret != "SUCCESS") {
        \Logging\LogError($logMsg);
    } else {
        \Logging\LogInfo($logMsg);
    }
}