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
<?php
include_once '/Common/CommFunc.php';
include_once '/Common/Logging.php';
 
header("Content-type: text/html; charset=utf-8");
 
// https://developer.shg.vn/article/view?id=454&lang=en
 
\Logging\CreateLogging("sohagame.giftcode.php");
 
$codeMessage = array(
    200 => "You have use giftcode successfully",
    400 => "checkdata invalid",
    408 => "giftcode invalid ...etc",
    409 => "Giftcode has been used",
    410 => "You has been used this Giftcode type",
);
 
$status = "fail";
$retCode = 99;
$retMsg = "unknown error";
 
function resfail($errorCode, $errlog = "")
{
    global $codeMessage;
    if (array_key_exists($errorCode, $codeMessage)) {
        $message = $codeMessage[$errorCode];
    } else {
        $message = $errlog;
    }
 
    if (!$message) {
        $message = "unknown error";
    }
 
    if (!$errlog) {
        $errlog = $message;
    }
 
    \Logging\LogInfo("_GET:" . print_r($_GET, true));
    \Logging\LogError($errlog);
 
    $errorRet = array("status" => "fail", "code" => $errorCode, "message" => $message);
    echo json_encode($errorRet);
}
 
$user_id = $_GET["user_id"]; // 平台账号
$role_id = $_GET["role_id"]; // 玩家ID
$area_id = $_GET["area_id"]; // 区服ID
$code = $_GET["code"];  // 媒体卡
$checkdata = $_GET["checkdata"];
 
if (!$user_id || !$role_id || !$area_id || !$code || !$checkdata) {
    resfail(408);
    return;
}
 
$spid = "sohagame";
if ($_GET["spid"]) {
    // 可选参数,也可用于测试用
    $spid = $_GET["spid"];
}
 
\CommFunc\GetKeyFromConfig(dirname(__FILE__) . '\\..\\..\\InterfaceConfig.php', "SP." . $spid, "app_secret", $app_secret);
$sign = md5($user_id . $role_id . $app_secret);
if ($checkdata != $sign) {
    resfail(400, "checkdata error! checkdata(" . $checkdata . ") != sign(" . $sign . ")");
    return;
}
\CommFunc\GetKeyFromConfig(dirname(__FILE__) . '\\..\\..\\InterfaceConfig.php', "SP." . $spid, "CouponCodeUrl", $CouponCodeUrl);
if (!$CouponCodeUrl) {
    resfail($retCode, "not CouponCodeUrl");
    return;
}
 
$serverIDArray = array(intval($area_id));
$serverPageInfo = \CommFunc\GetGameServerPageInfo($spid, $serverIDArray);
if (count($serverPageInfo) <= 0) {
    resfail($retCode, "not serverPageInfo");
    return;
}
// 目标角色对应游戏服务器gmtool地址
$serverPageValues = array_values($serverPageInfo);
 
$pushurl = $serverPageValues[0]["Page"];
if (!$pushurl) {
    resfail($retCode, "not pushurl");
    return;
}
 
$getdata = array(
    "channel" => $spid, //  目前同spid
    "spid" => $spid,    // 运营商ID,研发自己配置的,如jisu代表极速平台
    "code" => $code,    // 兑换码
    "accid" => $user_id,    // 平台账号
    "sid" => $area_id,  // 服务器ID 数字
    "pushurl" => $pushurl,
    "level" => $_GET["level"],    // 玩家等级
    "viplevel" => $_GET["viplevel"], // 玩家VIP等级
);
 
\Logging\LogInfo("CouponCodeUrl: " . $CouponCodeUrl);
\Logging\LogInfo("getdata: " . print_r($getdata, true));
$ret = \CommFunc\DoGet($CouponCodeUrl, $getdata);
\Logging\LogInfo("ret: " . $ret);
 
if ($ret) {
    $ret = json_decode($ret, true);
    \Logging\LogInfo("errcode=" . $ret["errcode"]);
    switch ($ret["errcode"]) {
        case 0: // ErrCode_OK = 0 # 成功,非0的码均代表错误
            \Logging\LogInfo("0");
            $status = "success";
            $retCode = 200;
            break;
        case 1: // ErrCode_Invalid = 1 # 兑换码无效
            \Logging\LogInfo("1");
            $retCode = 408;
            break;
        case 2: // ErrCode_Used = 2 # 礼包码已被使用
            \Logging\LogInfo("2");
            $retCode = 409;
            break;
        case 3: // ErrCode_TypeUsed = 3 # 已经使用过同类型的礼包码
            \Logging\LogInfo("3");
            $retCode = 410;
            break;
        default:
            // ErrCode_LVLimit = 4 # 等级不足
            // ErrCode_VIPLVLimit = 5 # VIP等级不足
            // ErrCode_ParamErr = 97 # 参数错误
            // ErrCode_FrequentRequest = 98 # 频繁请求
            // ErrCode_OtherErr = 99 # 其他错误,比如运行错误等
            $retCode = $ret["errcode"];
            $retMsg = $ret["errmsg"];
            \Logging\LogInfo("retCode: " . $retCode . " retMsg: " . $retMsg);
            break;
    }
}
 
if (array_key_exists($retCode, $codeMessage)) {
    $retMsg = $codeMessage[$retCode];
}
 
$retData = array(
    "status" => $status,
    "code" => $retCode,
    "message" => $retMsg,
);
echo \CommFunc\MyJson_encode($retData);