test-trigger-api.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // 测试触发支付成功事件API
  2. const testApiPaths = async () => {
  3. const apiPaths = [
  4. '/api/v1/payments/payment/trigger-success',
  5. '/api/v1/payment/trigger-success'
  6. ];
  7. const testOrderId = 1; // 使用一个测试订单ID
  8. for (const apiPath of apiPaths) {
  9. console.log(`\n测试路径: ${apiPath}`);
  10. try {
  11. const response = await fetch(apiPath, {
  12. method: 'POST',
  13. headers: {
  14. 'Content-Type': 'application/json',
  15. },
  16. body: JSON.stringify({
  17. orderId: testOrderId
  18. })
  19. });
  20. console.log(`状态码: ${response.status}`);
  21. console.log(`状态文本: ${response.statusText}`);
  22. if (response.ok) {
  23. const result = await response.json();
  24. console.log('成功响应:', JSON.stringify(result, null, 2));
  25. console.log(`✅ 路径 ${apiPath} 可用`);
  26. return apiPath;
  27. } else if (response.status === 401) {
  28. console.log('❌ 需要认证');
  29. } else if (response.status === 404) {
  30. console.log('❌ 路径不存在');
  31. } else {
  32. const errorText = await response.text();
  33. console.log('错误响应:', errorText.substring(0, 200));
  34. }
  35. } catch (error) {
  36. console.log('请求失败:', error.message);
  37. }
  38. }
  39. console.log('\n❌ 所有路径都不可用');
  40. return null;
  41. };
  42. // 运行测试
  43. console.log('开始测试触发支付成功事件API路径...');
  44. testApiPaths().then(successfulPath => {
  45. if (successfulPath) {
  46. console.log(`\n🎉 可用的API路径: ${successfulPath}`);
  47. } else {
  48. console.log('\n😞 没有找到可用的API路径');
  49. }
  50. }).catch(error => {
  51. console.error('测试失败:', error);
  52. });