| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- // 测试带认证的支付成功触发API
- async function testPaymentTriggerWithAuth() {
- console.log('=== 测试带认证的支付成功触发API ===\n');
- const apiUrl = 'http://localhost:8080/api/v1/payments/payment/trigger-success';
- // 使用一个简单的测试token(实际应用中应该从登录接口获取)
- // 这里使用一个硬编码的测试token
- const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidGVuYW50SWQiOjEsImlhdCI6MTczMzgxMjAwMCwiZXhwIjoxNzMzODE1NjAwfQ.test-signature';
- console.log(`使用的测试token: ${token.substring(0, 50)}...\n`);
- // 测试不同的订单ID
- const testOrderIds = [25, 26, 27, 999]; // 包括一个不存在的订单ID 999
- for (const orderId of testOrderIds) {
- console.log(`测试订单ID: ${orderId}`);
- console.log('='.repeat(50));
- try {
- const response = await fetch(apiUrl, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': `Bearer ${token}`
- },
- body: JSON.stringify({
- orderId: orderId
- })
- });
- console.log(`状态码: ${response.status}`);
- console.log(`状态文本: ${response.statusText}`);
- if (response.ok) {
- const result = await response.json();
- console.log('成功响应:', JSON.stringify(result, null, 2));
- console.log(`✅ 订单ID ${orderId} API调用成功\n`);
- } else {
- const errorText = await response.text();
- console.log('错误响应:', errorText.substring(0, 500));
- console.log(`❌ 订单ID ${orderId} API调用失败\n`);
- }
- } catch (error) {
- console.error('请求失败:', error.message);
- console.error('错误堆栈:', error.stack);
- console.log();
- }
- }
- // 检查数据库中的打印任务
- console.log('\n=== 检查数据库中的打印任务 ===\n');
- const { exec } = require('child_process');
- const checkDb = () => {
- return new Promise((resolve, reject) => {
- exec(
- 'psql -h 127.0.0.1 -U postgres -d postgres -c "SELECT id, tenant_id, task_id, order_id, print_status, scheduled_at, created_at FROM feie_print_task_mt ORDER BY created_at DESC LIMIT 10"',
- (error, stdout, stderr) => {
- if (error) {
- reject(error);
- } else {
- resolve(stdout);
- }
- }
- );
- });
- };
- try {
- const dbResult = await checkDb();
- console.log('最新的打印任务:');
- console.log(dbResult);
- } catch (error) {
- console.error('查询数据库失败:', error.message);
- }
- }
- // 运行测试
- testPaymentTriggerWithAuth().catch(error => {
- console.error('测试脚本执行失败:', error);
- process.exit(1);
- });
|