You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
3.1 KiB

3 weeks ago
$ErrorActionPreference = 'Stop'
$base = 'http://localhost:8081'
# 1) token
$r = Invoke-RestMethod -Uri "$base/api/auth/debug/token?userId=739564171091247104" -Method Get
$token = $r.data.token
if (-not $token) { $token = $r.data }
$token | Set-Content -Path 'e:\code\crm-backend-matt\tmp\dt-token.txt' -NoNewline
Write-Host "TOKEN OK: $($token.Substring(0, [Math]::Min(20, $token.Length)))..."
$headers = @{ Authorization = "Bearer $token" }
# 2) stats - PUBLIC_POOL
$body = @{ viewType = 'PUBLIC_POOL'; pageNum = 1; pageSize = 5 } | ConvertTo-Json
$s1 = Invoke-RestMethod -Uri "$base/api/lead/stats" -Method Post -Headers $headers -Body $body -ContentType 'application/json; charset=utf-8'
Write-Host "=== stats PUBLIC_POOL ==="
$s1.data | ConvertTo-Json -Depth 4
# 3) stats - MY_LEAD
$body2 = @{ viewType = 'MY_LEAD'; pageNum = 1; pageSize = 5 } | ConvertTo-Json
$s2 = Invoke-RestMethod -Uri "$base/api/lead/stats" -Method Post -Headers $headers -Body $body2 -ContentType 'application/json; charset=utf-8'
Write-Host "=== stats MY_LEAD ==="
$s2.data | ConvertTo-Json -Depth 4
# 4) page with keyword (region name) - manual JSON to avoid \uXXXX escaping
function PostJson($url, $json) {
return Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes($json)) -ContentType 'application/json; charset=utf-8'
}
$kw = [string]::new([char[]](0x5E7F, 0x5DDE)) # 广州,避免 PS5.1 无 BOM 乱码
$p = PostJson "$base/api/lead/page" ('{"viewType":"PUBLIC_POOL","pageNum":1,"pageSize":5,"keyword":"' + $kw + '"}')
Write-Host "=== page keyword=$kw total: $($p.data.total) ==="
$recs = if ($p.data.records) { $p.data.records } else { $p.data.content }
foreach ($it in $recs) { Write-Host ("lead: {0} | {1} | {2} | channel={3} brand={4} dept={5} createBy={6}" -f $it.leadName, $it.provinceName, $it.cityName, $it.channelName, $it.brandName, $it.deptName, $it.createByName) }
# 5) detail of first record
if ($recs -and $recs.Count -gt 0) {
$id = $recs[0].id
} else {
$pa = PostJson "$base/api/lead/page" '{"viewType":"PUBLIC_POOL","pageNum":1,"pageSize":5}'
$recs2 = if ($pa.data.records) { $pa.data.records } else { $pa.data.content }
Write-Host "(keyword miss, fallback total=$($pa.data.total), rows=$($recs2.Count))"
$id = $recs2[0].id
}
$d = Invoke-RestMethod -Uri "$base/api/lead/detail?id=$id" -Method Get -Headers $headers
Write-Host "=== detail id=$id ==="
$d.data | ConvertTo-Json -Depth 4 | Out-File -FilePath 'e:\code\crm-backend-matt\tmp\detail-out.json' -Encoding utf8
Write-Host ("detail keys: channelName={0} brandName={1} productName={2} sceneName={3} deptName={4} teamDeptName={5} createByName={6}" -f $d.data.channelName, $d.data.brandName, $d.data.productName, $d.data.sceneName, $d.data.deptName, $d.data.teamDeptName, $d.data.createByName)
# 6) history
$h = Invoke-RestMethod -Uri "$base/api/lead/history?leadId=$id" -Method Get -Headers $headers
Write-Host "=== history leadId=$id count=$($h.data.Count) ==="
foreach ($hh in $h.data) { Write-Host ("op: {0} by {1}" -f $hh.historyType, $hh.opUserName) }
Write-Host "ALL API CHECKS DONE"