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
96
97
98
99
100
101
102
103
104
105
106
107
<?php
include_once '/Common/CommFunc.php';
include_once '/Common/Logging.php';
include_once '/Common/PayOrder.php';
include_once "/ProjComm/CfgReader.php";
include_once "quicksdkAsy.php";
 
header("Content-type: text/html; charset=utf-8");
 
// $_SERVER['PHP_SELF'] = /api/quick/payxxxxx.php
// strripos 最后一次出现 / 的位置,再+1得到 payxxxxx.php
// +3   从pay后面开始
// -4   去除最后的.php
$appid = substr($_SERVER['PHP_SELF'], strripos($_SERVER['PHP_SELF'], "/") + 1 + 3, -4);
$appid = "mlgtgame";
$channelName = "jf"; # 绝峰
$success = "success";
$failed = "failed";
 
\Logging\CreateLogging("quick.pay" . $appid . "." . $channelName . ".php");
\Logging\LogInfo("CONTENT_TYPE: " . $_SERVER["CONTENT_TYPE"]);
$postData = $_POST;
\Logging\LogInfo("postData: " . print_r($postData, true));
 
$orderId = $postData['orderId']; //     SDK唯一订单号
$gameRole = $postData['gameRole']; //     游戏内对应角色唯一id
$gameArea = $postData['gameArea']; //     游戏内区服id
$productName = $postData['productName']; //     游戏内购买物品定义名称
$productDesc = $postData['productDesc']; //     游戏内购买物品定义描述
$remark = $postData['remark']; //     游戏自定义信息,游戏方订单编号,方便数据查询,建议长度<=64,‘透传字段
$payTime = $postData['payTime']; //     玩家在sdk中支付的时间 格式:yyyy-MM-dd HH:mm:ss
$amount = $postData['amount']; //     支付金额[String] (单位:元),如 amount=10.22
$payWay = $postData['payWay']; //     支付方式,如 payWay=支付宝
$sign = $postData['sign']; //     签名值,游戏应根据签名约定,本地计算后与此值进行比对
 
if (!$gameRole || !$orderId || !$payTime || !$amount || !$sign) {
    Ret($failed, "ParamError");
    exit;
}
 
if (
    !\CfgReader\ReadConfig()
    || !\CfgReader\GetConfigData("Quick", "Key_" . $appid . "_" . $channelName . "_Callback_Key", $Callback_Key)
) {
    Ret($failed, "CfgError");
    exit;
}
 
$md5SignLocal = quickAsy::getMd5Sign2($Callback_Key, false);
if ($md5SignLocal != $sign) {
    Ret($failed, "SignError" . " md5SignLocal:" . $md5SignLocal . " != sign:" . $sign);
    exit;
}
 
$extrasLen = 5;
$extrasParams = explode("_",  $remark, $extrasLen); // channelID_cp订单id_区服id_游戏充值编号_uid
\Logging\LogInfo("extrasParams:" . print_r($extrasParams, true));
$extras_params = $extrasParams;
 
if (!isset($extras_params) || count($extras_params) != $extrasLen) {
    Ret("extras_params_error", " extras_params:" . print_r($extras_params, true));
    exit;
}
 
// 同步游戏服务器
$channelID = $extras_params[0];
$cpOrderID = $extras_params[1];
$serverID = intval($extras_params[2]);
$OrderInfo = $extras_params[3];
$uid = $extras_params[4];
 
$AccountID = $uid . "@" . $channelID;
 
$result = $failed;
$retMsg = "";
// 没有创建订单步骤,直接使用sdk订单号
$returnArr = \PayOrder\DoReceivePayOrder($appid, $cpOrderID, $orderId, $AccountID, $serverID, $OrderInfo, floatval($amount), $payTime, false);
switch ($returnArr["errorcode"]) {
    case 1:
        $result = $success;
        break;
    case 2:
        $result = $success;
        break;
    default:
        if ($returnArr["errordesc"]) {
            $retMsg = $returnArr["errordesc"];
        }
        break;
}
Ret($result, $retMsg);
exit;
 
function Ret($ret, $msg = "")
{
    global $success;
    echo $ret;
    $logMsg = $ret;
    if ($msg) {
        $logMsg .= " msg => " . $msg;
    }
    if ($ret != $success) {
        \Logging\LogError($logMsg);
    } else {
        \Logging\LogInfo($logMsg);
    }
}