文件
freeshop/pay_notify.php
T
2026-08-16 17:03:10 +08:00

38 行
1.2 KiB
PHP
原始文件 Blame 文件历史

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
<?php
if (!defined('IN_APP')) { define('IN_APP', true); }
require __DIR__ . '/config.php';
require __DIR__ . '/includes/db.php';
require __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/Payment.php';
require_once __DIR__ . '/includes/PaymentCodePay.php';
$gw = new CodePayGateway();
$params = array_merge($_GET, $_POST);
if (!$gw->verifyNotify($params)) {
http_response_code(400);
echo 'sign error';
exit;
}
$orderNo = $params['out_trade_no'] ?? $params['param'] ?? '';
if ($orderNo === '') {
echo 'no order';
exit;
}
if (!$gw->isPaid($params)) {
echo 'not paid';
exit;
}
$stmt = db()->prepare('SELECT * FROM ' . tn('recharge_orders') . ' WHERE order_no = ?');
$stmt->execute([$orderNo]);
$order = $stmt->fetch();
if (!$order) {
echo 'order not found';
exit;
}
$tradeNo = $gw->getTradeNo($params);
$upd = db()->prepare('UPDATE ' . tn('recharge_orders') . ' SET status=?, trade_no=?, paid_at=NOW() WHERE order_no=? AND status=?');
$upd->execute(['paid', $tradeNo, $orderNo, 'pending']);
if ($upd->rowCount() > 0) {
addPoints((int) $order['user_id'], 'recharge', (int) $order['points'], '积分充值(' . $tradeNo . '');
}
$gw->respondSuccess();