// 测试修复后的API async function testApiFixed() { console.log('=== 测试修复后的支付成功触发API ===\n'); const apiUrl = 'http://localhost:8080/api/v1/payments/payment/trigger-success'; // 使用测试token(从现有测试文件中获取) const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidGVuYW50SWQiOjEsImlhdCI6MTczMzgxMjAwMCwiZXhwIjoxNzMzODE1NjAwfQ.test-signature'; console.log(`API地址: ${apiUrl}`); console.log(`测试订单ID: 25`); console.log(`Token: ${token.substring(0, 50)}...\n`); try { const response = await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, body: JSON.stringify({ orderId: 25 }) }); console.log(`状态码: ${response.status}`); console.log(`状态文本: ${response.statusText}`); if (response.ok) { const result = await response.json(); console.log('\n✅ API调用成功!'); console.log('响应内容:', JSON.stringify(result, null, 2)); // 等待一会儿让后台处理 console.log('\n等待2秒让后台处理打印任务...'); await new Promise(resolve => setTimeout(resolve, 2000)); // 检查数据库 console.log('\n检查数据库中的打印任务...'); const { exec } = require('child_process'); const util = require('util'); const execPromise = util.promisify(exec); try { const { stdout } = await execPromise( '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 WHERE order_id = 25 ORDER BY created_at DESC"' ); console.log('查询结果:'); console.log(stdout); if (stdout.includes('(0 rows)')) { console.log('\n❌ 数据库中仍然没有找到订单ID 25的打印任务'); console.log('\n可能的原因:'); console.log('1. 飞鹅打印模块导入失败'); console.log('2. 订单信息获取失败'); console.log('3. 打印机获取失败'); console.log('4. 数据库插入失败'); } else { console.log('\n✅ 成功创建打印任务!'); } } catch (dbError) { console.error('查询数据库失败:', dbError.message); } } else { const errorText = await response.text(); console.log('\n❌ API调用失败'); console.log('错误响应:', errorText); } } catch (error) { console.error('请求失败:', error.message); console.error('错误堆栈:', error.stack); } } // 运行测试 testApiFixed().catch(error => { console.error('测试脚本执行失败:', error); process.exit(1); });