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