# 微信物流取消订单测试脚本 # 使用正确的上下文路径:/recycle-admin param( [string]$openid = "test_admin_openid", [string]$deliveryId = "TEST", [string]$bizId = "test_biz_id", [string]$cancelMsg = "PowerShell自动化测试" ) $baseUrl = "http://localhost:8002/recycle-admin" $headers = @{"Content-Type"="application/json"} Write-Host "=" * 60 -ForegroundColor Green Write-Host " 微信物流取消订单测试脚本" -ForegroundColor Green Write-Host "=" * 60 -ForegroundColor Green Write-Host "" Write-Host "测试配置:" -ForegroundColor Yellow Write-Host "- 服务地址: $baseUrl" -ForegroundColor White Write-Host "- OpenID: $openid" -ForegroundColor White Write-Host "- 快递公司: $deliveryId" -ForegroundColor White Write-Host "- 商户ID: $bizId" -ForegroundColor White Write-Host "- 取消原因: $cancelMsg" -ForegroundColor White Write-Host "" # 检查服务是否可用 Write-Host "检查服务状态..." -ForegroundColor Yellow try { $healthCheck = Invoke-WebRequest -Uri "$baseUrl/actuator/health" -Method GET -TimeoutSec 5 Write-Host "✅ 服务正常运行" -ForegroundColor Green } catch { Write-Host "⚠️ 无法访问健康检查端点,继续测试..." -ForegroundColor Yellow } Write-Host "" Write-Host "开始执行完整流程测试(下单 -> 取消)..." -ForegroundColor Yellow Write-Host "" try { # 构建请求体 $requestBody = @{ openid = $openid deliveryId = $deliveryId bizId = $bizId cancelMsg = $cancelMsg } | ConvertTo-Json Write-Host "发送请求到: $baseUrl/applet/logistics/test/fullTestWithCancel" -ForegroundColor Cyan Write-Host "请求数据: $requestBody" -ForegroundColor Gray Write-Host "" # 发送请求 $response = Invoke-WebRequest -Uri "$baseUrl/applet/logistics/test/fullTestWithCancel" ` -Method POST ` -Headers $headers ` -Body $requestBody ` -TimeoutSec 30 # 解析响应 $result = $response.Content | ConvertFrom-Json Write-Host "响应状态码: $($response.StatusCode)" -ForegroundColor Cyan Write-Host "" if ($result.success) { Write-Host "🎉 测试成功!" -ForegroundColor Green Write-Host "" # 显示下单结果 if ($result.result.orderResponse) { Write-Host "📦 下单结果:" -ForegroundColor Yellow Write-Host " 订单ID: $($result.result.orderResponse.orderId)" -ForegroundColor Cyan Write-Host " 运单ID: $($result.result.orderResponse.waybillId)" -ForegroundColor Cyan Write-Host " 错误码: $($result.result.orderResponse.errCode)" -ForegroundColor Cyan Write-Host " 错误信息: $($result.result.orderResponse.errMsg)" -ForegroundColor Cyan if ($result.result.orderResponse.waybillData) { Write-Host " 运单数据: 已生成" -ForegroundColor Cyan } Write-Host "" } # 显示取消结果 if ($result.result.cancelResponse) { Write-Host "❌ 取消结果:" -ForegroundColor Yellow Write-Host " 错误码: $($result.result.cancelResponse.errCode)" -ForegroundColor Cyan Write-Host " 错误信息: $($result.result.cancelResponse.errMsg)" -ForegroundColor Cyan if ($result.result.cancelResponse.cancelTime) { $cancelTime = [DateTimeOffset]::FromUnixTimeSeconds($result.result.cancelResponse.cancelTime).ToString("yyyy-MM-dd HH:mm:ss") Write-Host " 取消时间: $cancelTime" -ForegroundColor Cyan } Write-Host "" } # 显示总结信息 Write-Host "📋 测试总结:" -ForegroundColor Yellow Write-Host " $($result.result.message)" -ForegroundColor White Write-Host "" } else { Write-Host "❌ 测试失败!" -ForegroundColor Red Write-Host "错误信息: $($result.message)" -ForegroundColor Red if ($result.result) { Write-Host "详细信息: $($result.result)" -ForegroundColor Red } Write-Host "" } } catch { Write-Host "❌ 请求失败!" -ForegroundColor Red Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red Write-Host "" # 提供排查建议 Write-Host "🔍 排查建议:" -ForegroundColor Yellow Write-Host "1. 检查应用是否在 $baseUrl 运行" -ForegroundColor White Write-Host "2. 检查微信配置是否正确" -ForegroundColor White Write-Host "3. 确认网络连接正常" -ForegroundColor White Write-Host "4. 验证测试环境权限" -ForegroundColor White Write-Host "" # 显示详细错误信息 if ($_.Exception.Response) { Write-Host "响应状态码: $($_.Exception.Response.StatusCode)" -ForegroundColor Red Write-Host "响应状态: $($_.Exception.Response.StatusDescription)" -ForegroundColor Red } Write-Host "" } Write-Host "=" * 60 -ForegroundColor Green Write-Host " 测试完成!" -ForegroundColor Green Write-Host "=" * 60 -ForegroundColor Green Write-Host "" # 提供后续操作建议 Write-Host "💡 后续操作建议:" -ForegroundColor Yellow Write-Host "1. 如果测试成功,可以在实际应用中使用相同的逻辑" -ForegroundColor White Write-Host "2. 记住每天最多只能调用10次,请合理安排测试" -ForegroundColor White Write-Host "3. 在生产环境中,请替换为实际的openid和配置" -ForegroundColor White Write-Host "4. 可以通过Swagger UI进行更详细的测试: $baseUrl/swagger-ui.html" -ForegroundColor White Write-Host "" # 参数说明 Write-Host "📖 脚本参数说明:" -ForegroundColor Yellow Write-Host "使用示例:" -ForegroundColor White Write-Host " .\test-logistics.ps1" -ForegroundColor Gray Write-Host " .\test-logistics.ps1 -openid 'your_openid' -cancelMsg '自定义取消原因'" -ForegroundColor Gray Write-Host "" Write-Host "按任意键退出..." -ForegroundColor Green $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null