38 行
1.2 KiB
PHP
38 行
1.2 KiB
PHP
<?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();
|