# 单独调试 POST /OrderV2/UpsertSmallBag(与 SmallBagTrackOrderClient 一致) param( [string]$BaseUrl = "http://api.nanafa.com/track", [string]$AppKey = "W2606001", [string]$AppSecret = "ziK8UzlQ39m3kdL346XEBg8nljY8os52", [string]$OrderNo = "", [string]$Client = "TEST001" ) function Get-SmallBagSign { param([string]$Key, [long]$Ts, [string]$Secret) $signString = "appKey=$Key×tamp=$Ts&appSecret=$Secret" $md5 = [System.Security.Cryptography.MD5]::Create() $bytes = [System.Text.Encoding]::UTF8.GetBytes($signString) $hash = $md5.ComputeHash($bytes) -join ($hash | ForEach-Object { $_.ToString("X2") }) } if ([string]::IsNullOrWhiteSpace($OrderNo)) { $OrderNo = "LP-DEBUG-" + (Get-Date -Format "yyyyMMddHHmmss") } $timestamp = [DateTimeOffset]::UtcNow.ToUnixTimeSeconds() $sign = Get-SmallBagSign -Key $AppKey -Ts $timestamp -Secret $AppSecret $body = @{ client = $Client orderNo = $OrderNo trackNo = "" otherNo = "DEBUG-CLIENT-001" channel = "test01" product = "test01" apiCode = "" consignee = @{ countryCode = "US" province = "California" postcode = "90001" city = "Los Angeles" email = "debug@example.com" } } | ConvertTo-Json -Depth 5 -Compress $base = $BaseUrl.TrimEnd('/') $url = "$base/OrderV2/UpsertSmallBag?appKey=$([uri]::EscapeDataString($AppKey))×tamp=$timestamp&sign=$([uri]::EscapeDataString($sign))" Write-Host "========== UpsertSmallBag Debug ==========" -ForegroundColor Cyan Write-Host "URL: $url" Write-Host "Timestamp: $timestamp" Write-Host "Sign: $sign" Write-Host "Body:" Write-Host ($body | ConvertFrom-Json | ConvertTo-Json -Depth 5) Write-Host "========================================" -ForegroundColor Cyan try { $response = Invoke-WebRequest -Uri $url -Method POST ` -ContentType "application/json; charset=utf-8" ` -Body ([System.Text.Encoding]::UTF8.GetBytes($body)) ` -UseBasicParsing Write-Host "HTTP $($response.StatusCode)" -ForegroundColor Green Write-Host $response.Content } catch { if ($_.Exception.Response) { $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream()) $errBody = $reader.ReadToEnd() Write-Host "HTTP $([int]$_.Exception.Response.StatusCode)" -ForegroundColor Red if ($errBody) { Write-Host $errBody } else { Write-Host "(empty body — 请核对 appKey/appSecret 或联系轨迹平台)" } } else { Write-Host $_.Exception.Message -ForegroundColor Red } Write-Host "" Write-Host "Tip: start OMS and POST /order/debug/track-upsert-small-bag with optional body fields." -ForegroundColor Yellow exit 1 }