爱简收旧衣按件回收后端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
6.1 KiB

3 weeks ago
  1. # 微信物流取消订单测试脚本
  2. # 使用正确的上下文路径:/recycle-admin
  3. param(
  4. [string]$openid = "test_admin_openid",
  5. [string]$deliveryId = "TEST",
  6. [string]$bizId = "test_biz_id",
  7. [string]$cancelMsg = "PowerShell自动化测试"
  8. )
  9. $baseUrl = "http://localhost:8002/recycle-admin"
  10. $headers = @{"Content-Type"="application/json"}
  11. Write-Host "=" * 60 -ForegroundColor Green
  12. Write-Host " 微信物流取消订单测试脚本" -ForegroundColor Green
  13. Write-Host "=" * 60 -ForegroundColor Green
  14. Write-Host ""
  15. Write-Host "测试配置:" -ForegroundColor Yellow
  16. Write-Host "- 服务地址: $baseUrl" -ForegroundColor White
  17. Write-Host "- OpenID: $openid" -ForegroundColor White
  18. Write-Host "- 快递公司: $deliveryId" -ForegroundColor White
  19. Write-Host "- 商户ID: $bizId" -ForegroundColor White
  20. Write-Host "- 取消原因: $cancelMsg" -ForegroundColor White
  21. Write-Host ""
  22. # 检查服务是否可用
  23. Write-Host "检查服务状态..." -ForegroundColor Yellow
  24. try {
  25. $healthCheck = Invoke-WebRequest -Uri "$baseUrl/actuator/health" -Method GET -TimeoutSec 5
  26. Write-Host "✅ 服务正常运行" -ForegroundColor Green
  27. } catch {
  28. Write-Host "⚠️ 无法访问健康检查端点,继续测试..." -ForegroundColor Yellow
  29. }
  30. Write-Host ""
  31. Write-Host "开始执行完整流程测试(下单 -> 取消)..." -ForegroundColor Yellow
  32. Write-Host ""
  33. try {
  34. # 构建请求体
  35. $requestBody = @{
  36. openid = $openid
  37. deliveryId = $deliveryId
  38. bizId = $bizId
  39. cancelMsg = $cancelMsg
  40. } | ConvertTo-Json
  41. Write-Host "发送请求到: $baseUrl/applet/logistics/test/fullTestWithCancel" -ForegroundColor Cyan
  42. Write-Host "请求数据: $requestBody" -ForegroundColor Gray
  43. Write-Host ""
  44. # 发送请求
  45. $response = Invoke-WebRequest -Uri "$baseUrl/applet/logistics/test/fullTestWithCancel" `
  46. -Method POST `
  47. -Headers $headers `
  48. -Body $requestBody `
  49. -TimeoutSec 30
  50. # 解析响应
  51. $result = $response.Content | ConvertFrom-Json
  52. Write-Host "响应状态码: $($response.StatusCode)" -ForegroundColor Cyan
  53. Write-Host ""
  54. if ($result.success) {
  55. Write-Host "🎉 测试成功!" -ForegroundColor Green
  56. Write-Host ""
  57. # 显示下单结果
  58. if ($result.result.orderResponse) {
  59. Write-Host "📦 下单结果:" -ForegroundColor Yellow
  60. Write-Host " 订单ID: $($result.result.orderResponse.orderId)" -ForegroundColor Cyan
  61. Write-Host " 运单ID: $($result.result.orderResponse.waybillId)" -ForegroundColor Cyan
  62. Write-Host " 错误码: $($result.result.orderResponse.errCode)" -ForegroundColor Cyan
  63. Write-Host " 错误信息: $($result.result.orderResponse.errMsg)" -ForegroundColor Cyan
  64. if ($result.result.orderResponse.waybillData) {
  65. Write-Host " 运单数据: 已生成" -ForegroundColor Cyan
  66. }
  67. Write-Host ""
  68. }
  69. # 显示取消结果
  70. if ($result.result.cancelResponse) {
  71. Write-Host "❌ 取消结果:" -ForegroundColor Yellow
  72. Write-Host " 错误码: $($result.result.cancelResponse.errCode)" -ForegroundColor Cyan
  73. Write-Host " 错误信息: $($result.result.cancelResponse.errMsg)" -ForegroundColor Cyan
  74. if ($result.result.cancelResponse.cancelTime) {
  75. $cancelTime = [DateTimeOffset]::FromUnixTimeSeconds($result.result.cancelResponse.cancelTime).ToString("yyyy-MM-dd HH:mm:ss")
  76. Write-Host " 取消时间: $cancelTime" -ForegroundColor Cyan
  77. }
  78. Write-Host ""
  79. }
  80. # 显示总结信息
  81. Write-Host "📋 测试总结:" -ForegroundColor Yellow
  82. Write-Host " $($result.result.message)" -ForegroundColor White
  83. Write-Host ""
  84. } else {
  85. Write-Host "❌ 测试失败!" -ForegroundColor Red
  86. Write-Host "错误信息: $($result.message)" -ForegroundColor Red
  87. if ($result.result) {
  88. Write-Host "详细信息: $($result.result)" -ForegroundColor Red
  89. }
  90. Write-Host ""
  91. }
  92. } catch {
  93. Write-Host "❌ 请求失败!" -ForegroundColor Red
  94. Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red
  95. Write-Host ""
  96. # 提供排查建议
  97. Write-Host "🔍 排查建议:" -ForegroundColor Yellow
  98. Write-Host "1. 检查应用是否在 $baseUrl 运行" -ForegroundColor White
  99. Write-Host "2. 检查微信配置是否正确" -ForegroundColor White
  100. Write-Host "3. 确认网络连接正常" -ForegroundColor White
  101. Write-Host "4. 验证测试环境权限" -ForegroundColor White
  102. Write-Host ""
  103. # 显示详细错误信息
  104. if ($_.Exception.Response) {
  105. Write-Host "响应状态码: $($_.Exception.Response.StatusCode)" -ForegroundColor Red
  106. Write-Host "响应状态: $($_.Exception.Response.StatusDescription)" -ForegroundColor Red
  107. }
  108. Write-Host ""
  109. }
  110. Write-Host "=" * 60 -ForegroundColor Green
  111. Write-Host " 测试完成!" -ForegroundColor Green
  112. Write-Host "=" * 60 -ForegroundColor Green
  113. Write-Host ""
  114. # 提供后续操作建议
  115. Write-Host "💡 后续操作建议:" -ForegroundColor Yellow
  116. Write-Host "1. 如果测试成功,可以在实际应用中使用相同的逻辑" -ForegroundColor White
  117. Write-Host "2. 记住每天最多只能调用10次,请合理安排测试" -ForegroundColor White
  118. Write-Host "3. 在生产环境中,请替换为实际的openid和配置" -ForegroundColor White
  119. Write-Host "4. 可以通过Swagger UI进行更详细的测试: $baseUrl/swagger-ui.html" -ForegroundColor White
  120. Write-Host ""
  121. # 参数说明
  122. Write-Host "📖 脚本参数说明:" -ForegroundColor Yellow
  123. Write-Host "使用示例:" -ForegroundColor White
  124. Write-Host " .\test-logistics.ps1" -ForegroundColor Gray
  125. Write-Host " .\test-logistics.ps1 -openid 'your_openid' -cancelMsg '自定义取消原因'" -ForegroundColor Gray
  126. Write-Host ""
  127. Write-Host "按任意键退出..." -ForegroundColor Green
  128. $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null