<?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);
|