test-api-fixed.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // 测试修复后的API
  2. async function testApiFixed() {
  3. console.log('=== 测试修复后的支付成功触发API ===\n');
  4. const apiUrl = 'http://localhost:8080/api/v1/payments/payment/trigger-success';
  5. // 使用测试token(从现有测试文件中获取)
  6. const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidGVuYW50SWQiOjEsImlhdCI6MTczMzgxMjAwMCwiZXhwIjoxNzMzODE1NjAwfQ.test-signature';
  7. console.log(`API地址: ${apiUrl}`);
  8. console.log(`测试订单ID: 25`);
  9. console.log(`Token: ${token.substring(0, 50)}...\n`);
  10. try {
  11. const response = await fetch(apiUrl, {
  12. method: 'POST',
  13. headers: {
  14. 'Content-Type': 'application/json',
  15. 'Authorization': `Bearer ${token}`
  16. },
  17. body: JSON.stringify({
  18. orderId: 25
  19. })
  20. });
  21. console.log(`状态码: ${response.status}`);
  22. console.log(`状态文本: ${response.statusText}`);
  23. if (response.ok) {
  24. const result = await response.json();
  25. console.log('\n✅ API调用成功!');
  26. console.log('响应内容:', JSON.stringify(result, null, 2));
  27. // 等待一会儿让后台处理
  28. console.log('\n等待2秒让后台处理打印任务...');
  29. await new Promise(resolve => setTimeout(resolve, 2000));
  30. // 检查数据库
  31. console.log('\n检查数据库中的打印任务...');
  32. const { exec } = require('child_process');
  33. const util = require('util');
  34. const execPromise = util.promisify(exec);
  35. try {
  36. const { stdout } = await execPromise(
  37. '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"'
  38. );
  39. console.log('查询结果:');
  40. console.log(stdout);
  41. if (stdout.includes('(0 rows)')) {
  42. console.log('\n❌ 数据库中仍然没有找到订单ID 25的打印任务');
  43. console.log('\n可能的原因:');
  44. console.log('1. 飞鹅打印模块导入失败');
  45. console.log('2. 订单信息获取失败');
  46. console.log('3. 打印机获取失败');
  47. console.log('4. 数据库插入失败');
  48. } else {
  49. console.log('\n✅ 成功创建打印任务!');
  50. }
  51. } catch (dbError) {
  52. console.error('查询数据库失败:', dbError.message);
  53. }
  54. } else {
  55. const errorText = await response.text();
  56. console.log('\n❌ API调用失败');
  57. console.log('错误响应:', errorText);
  58. }
  59. } catch (error) {
  60. console.error('请求失败:', error.message);
  61. console.error('错误堆栈:', error.stack);
  62. }
  63. }
  64. // 运行测试
  65. testApiFixed().catch(error => {
  66. console.error('测试脚本执行失败:', error);
  67. process.exit(1);
  68. });