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
<?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");
// https://www.quicksdk.com/doc-512.html
 
// uid=543&username=554230339%40qq.com&cpOrderNo=orderNo_xxx&orderNo=0020170210162721805701&payTime=2017-02-10+16%3A27%3A55&payAmount=6.00&payStatus=0&payCurrency=RMB&usdAmount=0.99&extrasParams=&sign=22abf0b204d19316d177baeec6a90fcd
 
// $_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";
\Logging\CreateLogging("quick.pay" . $appid . ".hygtgame.php");
\Logging\LogInfo("CONTENT_TYPE: " . $_SERVER["CONTENT_TYPE"]);
$postData = $_POST;
\Logging\LogInfo("postData: " . print_r($postData, true));
 
$uid = $postData['uid']; //     购买道具的用户uid
$username = $postData['username']; //     购买道具的用户username
$cpOrderNo = $postData['cpOrderNo']; //     游戏下单时传递的游戏订单号,原样返回,     可为空
$orderNo = $postData['orderNo']; //     SDK唯一订单号
$payTime = $postData['payTime']; //     用户支付时间,如2017-02-06 14:22:32
$payType = $postData['payType']; //     订单支付方式,具体值对应支付渠道详见对照表
$payAmount = $postData['payAmount']; //     用户支付金额(单位:元)
$payCurrency = $postData['payCurrency']; //     用户支付的币种,如RMB,USD等
$usdAmount = $postData['usdAmount']; //     用户支付的游戏道具以美元计价的金额(单位:元)
$payStatus = $postData['payStatus']; //     支付状态,为0表示成功,为1时游戏不做处理
$actRate = $postData['actRate']; //     充值折扣,取值范围0~1(不包含0),默认为1表示不折扣;如值为0.2表示多发20%的元宝
$sign = $postData['sign']; //     签名值,游戏应根据签名约定,本地计算后与此值进行比对
$attach = $postData['extrasParams']; //     游戏下单时传递的扩展参数,将原样返回。    可为空
$subscriptionStatus = $postData['subscriptionStatus']; //     非必有,内购订阅型商品订单使用,如果有此字段表示订单订阅状态。cp监测到有此字段时不需要发货。字段取值为:2:订阅取消
$subReason = $postData['subReason']; //     非必有,内购订阅型商品订单取消订阅原因。当有subscriptionStatus字段时此字段必有
 
if (!$uid || !$username || !$orderNo || !$payTime || !$payType || !$payAmount || !$payCurrency || !$usdAmount || !$actRate || !$sign) {
    Ret("ParamError");
    exit;
}
 
// 支付状态,为0表示成功,为1时游戏不做处理
if ($payStatus != 0) {
    Ret("FAILED");
    exit;
}
 
if ($actRate != 1) {
    Ret("ActRateError");
    exit;
}
 
if ($$subscriptionStatus != "") {
    Ret("Subscription");
    exit;
}
 
if (
    !\CfgReader\ReadConfig()
    || !\CfgReader\GetConfigData("Quick", "Key_" . $appid . "_hygtgame_Callback_Key", $Callback_Key)
) {
    Ret("CfgError");
    exit;
}
 
$md5SignLocal = quickAsy::getMd5Sign($Callback_Key);
if ($md5SignLocal != $sign) {
    Ret("SignError", " md5SignLocal:" . $md5SignLocal . " != sign:" . $sign);
    exit;
}
 
$extrasLen = 4;
$extrasParams = explode("_",  $attach, $extrasLen); // channelID_cp订单id_区服id_游戏充值编号
\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];
 
$AccountID = $uid . "@" . $channelID;
 
$result = "FAILED";
// 没有创建订单步骤,直接使用sdk订单号
$returnArr = \PayOrder\DoReceivePayOrder($appid, $cpOrderID, $orderNo, $AccountID, $serverID, $OrderInfo, floatval($usdAmount), $payTime, false);
switch ($returnArr["errorcode"]) {
    case 1:
        $result = "SUCCESS";
        break;
    case 2:
        $result = "SUCCESS";
        break;
    default:
        if ($returnArr["errordesc"]) {
            $result = $returnArr["errordesc"];
        }
        break;
}
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);
    }
}