- 新增后台人工充值模块,支持上传支付凭证 - 新增支付结果查询接口及页面 - 新增订单支付成功跳转结果页逻辑 - 更新钱包流水类型标签区分充值方式 - 新增插件路由 PHP 8 兼容错误报告设置
37 行
2.7 KiB
PHP
37 行
2.7 KiB
PHP
<?php
|
|
define('APP_PATH', __DIR__ . '/../server/application/');
|
|
require __DIR__ . '/../server/thinkphp/base.php';
|
|
\think\App::initCommon();
|
|
|
|
use app\common\library\OrderPaymentResultService;
|
|
use think\Db;
|
|
|
|
function verifyResult($condition, $message) { if (!$condition) throw new RuntimeException($message); }
|
|
function mustReject($fn, $message) { try { $fn(); } catch (InvalidArgumentException $e) { return; } throw new RuntimeException($message); }
|
|
|
|
Db::startTrans();
|
|
try {
|
|
$order = ['id' => 2147483000, 'order_no' => 'RESULT-TEST', 'service_name' => '测试服务', 'pay_status' => 1, 'pay_type' => 'balance', 'pay_amount' => '120.00', 'pay_time' => time()];
|
|
$trade = 'RESULT' . bin2hex(random_bytes(10));
|
|
Db::name('pay_order')->insert(['out_trade_no' => $trade, 'order_id' => $order['id'], 'order_no' => $order['order_no'], 'user_id' => 1, 'scene' => 'diff', 'openid' => 'BALANCE', 'amount' => '12.34', 'status' => 'paid', 'pay_time' => time()]);
|
|
$result = OrderPaymentResultService::getResult($order, $trade);
|
|
verifyResult($result['amount'] === '12.34' && $result['pay_type'] === 'balance' && $result['scene'] === 'diff', 'Must use the actual payment transaction');
|
|
Db::name('pay_order')->where('out_trade_no', $trade)->update(['openid' => 'WX_TEST_OPENID', 'scene' => 'quote']);
|
|
$wechat = OrderPaymentResultService::getResult($order, $trade);
|
|
verifyResult($wechat['pay_type'] === 'wechat' && $wechat['scene'] === 'quote' && $wechat['amount'] === '12.34', 'WeChat payment result incorrect');
|
|
mustReject(function () use ($order, $trade) { $other = $order; $other['id']--; OrderPaymentResultService::getResult($other, $trade); }, 'Another order transaction accepted');
|
|
Db::name('pay_order')->where('out_trade_no', $trade)->update(['status' => 'pending']);
|
|
mustReject(function () use ($order, $trade) { OrderPaymentResultService::getResult($order, $trade); }, 'Unpaid transaction accepted');
|
|
Db::name('pay_order')->where('out_trade_no', $trade)->update(['status' => 'refunded']);
|
|
mustReject(function () use ($order, $trade) { OrderPaymentResultService::getResult($order, $trade); }, 'Refunded transaction shown as successful');
|
|
mustReject(function () use ($order) { OrderPaymentResultService::getResult($order, ''); }, 'Missing transaction accepted for nonzero payment');
|
|
$order['pay_type'] = 'coupon'; $order['pay_amount'] = '0.00';
|
|
$zero = OrderPaymentResultService::getResult($order, '');
|
|
verifyResult($zero['amount'] === '0.00' && $zero['pay_type'] === 'coupon', 'Zero payment not recognized');
|
|
$order['pay_status'] = 0;
|
|
mustReject(function () use ($order) { OrderPaymentResultService::getResult($order, ''); }, 'Unpaid zero order accepted');
|
|
echo "Order payment result checks passed\n";
|
|
} finally {
|
|
Db::rollback();
|
|
}
|