admin/scripts/debug-upsert-small-bag.ps1
zzh bd1288edc9 fix(track): send UpsertSmallBag auth via HTTP headers
Track SignatureValidationFilter reads appKey/timestamp/sign from headers, not query. Reverts e642f08 query transport and aligns debug script.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 12:35:39 +08:00

75 lines
2.7 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 单独调试 POST /OrderV2/UpsertSmallBag(与 SmallBagTrackOrderClient 一致:鉴权走 Header)
param(
[string]$BaseUrl = "https://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&timestamp=$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"
Write-Host "Body:"
Write-Host ($body | ConvertFrom-Json | ConvertTo-Json -Depth 5)
Write-Host "========================================" -ForegroundColor Cyan
try {
$response = Invoke-WebRequest -Uri $url -Method POST `
-Headers @{ appKey = $AppKey; timestamp = "$timestamp"; sign = $sign } `
-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 SignatureValidationFilter reads appKey/timestamp/sign from HTTP Headers." -ForegroundColor Yellow
exit 1
}