test-payment-trigger.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // 测试支付成功触发API
  2. async function testPaymentTrigger() {
  3. console.log('=== 测试支付成功触发API ===\n');
  4. const apiUrl = 'http://localhost:8080/api/v1/payments/payment/trigger-success';
  5. const testOrderId = 999; // 使用一个不存在的订单ID来测试
  6. console.log(`测试API: ${apiUrl}`);
  7. console.log(`测试订单ID: ${testOrderId}\n`);
  8. try {
  9. const response = await fetch(apiUrl, {
  10. method: 'POST',
  11. headers: {
  12. 'Content-Type': 'application/json',
  13. 'Authorization': 'Bearer test-token' // 需要有效的token
  14. },
  15. body: JSON.stringify({
  16. orderId: testOrderId
  17. })
  18. });
  19. console.log(`状态码: ${response.status}`);
  20. console.log(`状态文本: ${response.statusText}`);
  21. if (response.ok) {
  22. const result = await response.json();
  23. console.log('成功响应:', JSON.stringify(result, null, 2));
  24. console.log('\n✅ API调用成功');
  25. } else {
  26. const errorText = await response.text();
  27. console.log('错误响应:', errorText.substring(0, 500));
  28. console.log('\n❌ API调用失败');
  29. }
  30. } catch (error) {
  31. console.error('请求失败:', error.message);
  32. console.error('错误堆栈:', error.stack);
  33. }
  34. }
  35. // 运行测试
  36. testPaymentTrigger().catch(error => {
  37. console.error('测试脚本执行失败:', error);
  38. process.exit(1);
  39. });