This commit is contained in:
yangduo 2025-01-10 20:13:24 +08:00
parent ef834d99cd
commit 1581e58642

View File

@ -227,6 +227,110 @@ class RechargeController
));
}
public function prePurchase()
{
$account_id = $_REQUEST['account_id'];
//登录校验
$login = loginVerify($account_id, $_REQUEST['session_id']);
if (!$login) {
phpcommon\sendError(ERR_USER_BASE + 1, 'session无效');
return;
}
$conn = $this->getMysql($account_id);
if (!$conn) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$raw_data = file_get_contents('php://input');
$sigdata = json_decode($raw_data, true);
if (!$this->checkPurchaseLimit($conn, $account_id, $sigdata['productId'])) {
phpcommon\sendError(ERR_USER_BASE + 2, '不能购买');
return;
}
$url = '';
if (SERVER_ENV == _ONLINE) {
$url = 'https://payservice.kingsome.cn/api/ingame/sprepurchase';
} else {
$url = 'https://payservice-test.kingsome.cn/api/ingame/sprepurchase';
}
$sign = md5($_REQUEST['account_id'] . 'f3a6a9a5-217a-4079-ab99-b5d69b8212be' . $_REQUEST['session_id']);
$params = array(
'account_id' => $_REQUEST['account_id'],
'session_id' => $_REQUEST['session_id'],
'user_ip' => phpcommon\getIPv4(),
'sign' => $sign,
'sig_data' => $raw_data,
);
if (!phpcommon\HttpClient::post($url, json_encode($params), $rsp)) {
phpcommon\sendError(ERR_RETRY, '系统繁忙');
return;
}
if ($rsp == null || $rsp == '') {
phpcommon\sendError(ERR_RETRY, '系统繁忙2');
return;
}
$response = json_decode($rsp, true);
echo json_encode(array(
'errcode' => $response['errcode'],
'errmsg' => $response['errmsg'],
'order_id' => $response['order_id'],
'pay_sig' => $response['pay_sig'],
'signature' => $response['signature'],
'sig_data' => $response['sig_data'],
));
}
protected function checkPurchaseLimit($conn, $account_id, $productid)
{
$prod_conf = metatable\getShopGoodsById($productid);
if (!$prod_conf) {
return false;
}
if ($prod_conf['type'] != 2) {
return true;
}
$conn = $this->getMysql($_REQUEST['account_id']);
$rechargerow = $conn->execQueryOne(
'SELECT * FROM recharge WHERE accountid=:accountid;',
array(
':accountid' => $account_id
)
);
if (!$rechargerow) {
return true;
}
$daily_purchase = $rechargerow['daily_purchase'];
if ($daily_purchase == null || $daily_purchase == '') {
return true;
}
$todaysecs = phpcommon\getdayseconds(time());
$daily_obj = json_decode($daily_purchase . true);
if ($productid == 10) {
foreach ($daily_obj as $item) {
if ($item['time'] > $todaysecs) {
return false;
}
}
} else {
foreach ($daily_obj as $item) {
if (($item['id'] == $productid || $item['id'] == 10) && $item['time'] > $todaysecs) {
return false;
}
}
}
return true;
}
public function purchaseNotify()
{
$params = array(