# 单独调试 POST /OrderV2/UpsertSmallBag(与 SmallBagTrackOrderClient 一致:鉴权走 Header + Bearer) param( [string]$BaseUrl = "https://api.nanafa.com/track", [string]$AppKey = "W2606001", [string]$AppSecret = "ziK8UzlQ39m3kdL346XEBg8nljY8os52", [string]$Authorization = "", [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 $url = ($BaseUrl.TrimEnd('/')) + "/OrderV2/UpsertSmallBag" Write-Host "========== UpsertSmallBag Debug ==========" -ForegroundColor Cyan Write-Host "URL: $url" Write-Host "Headers: appKey=$AppKey, timestamp=$timestamp, sign=$sign" if (-not [string]::IsNullOrWhiteSpace($Authorization)) { Write-Host "Headers: Authorization=" } Write-Host "Body:" Write-Host ($body | ConvertFrom-Json | ConvertTo-Json -Depth 5) Write-Host "========================================" -ForegroundColor Cyan try { $headers = @{ appKey = $AppKey timestamp = "$timestamp" sign = $sign } if (-not [string]::IsNullOrWhiteSpace($Authorization)) { $headers.Authorization = $Authorization } $response = Invoke-WebRequest -Uri $url -Method POST ` -Headers $headers ` -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)" } } else { Write-Host $_.Exception.Message -ForegroundColor Red } Write-Host "" Write-Host "Tip: track gateway requires Authorization Bearer from logged-in user, plus appKey/timestamp/sign headers." -ForegroundColor Yellow exit 1 }