admin/scripts/debug-upsert-small-bag.ps1
zzh 545f0825f8 feat(order): 规则快照下游元数据、订单绑定字段与系统其他配置
排货发布 enrich Providers 并确认渠道时写入 t_order 下游四字段;接入 itfx 元数据客户端;系统其他配置与小包轨迹 DB 配置;手动轨迹 UpsertSmallBag 接口。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 11:31:15 +08:00

78 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 一致)
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&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 = @{
appKey = $AppKey
timestamp = $timestamp
sign = $sign
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 "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
}