# 验证钉钉同步落库:部门树 + 用户统计 $base = "http://127.0.0.1:8081" $userId = "739564171091247104" $tokResp = Invoke-RestMethod -Method Get -Uri "$base/api/auth/debug/token?userId=$userId" -TimeoutSec 30 $token = $tokResp.data $headers = @{ Authorization = "Bearer $token" } # 1. 用户统计(需 ADMIN) try { $stats = Invoke-RestMethod -Method Get -Uri "$base/api/system/users/stats" -Headers $headers -TimeoutSec 30 Write-Output "=== users/stats ===" $stats | ConvertTo-Json -Depth 6 -Compress } catch { Write-Output ("users/stats EX: " + $_.Exception.Message) } # 2. 部门树(统计节点数) try { $tree = Invoke-RestMethod -Method Get -Uri "$base/api/system/depts/tree" -Headers $headers -TimeoutSec 30 $count = 0 function Walk($nodes) { foreach ($n in $nodes) { $script:count++; if ($n.children) { Walk $n.children } } } Walk $tree.data Write-Output "=== depts/tree: nodes=$count ===" } catch { Write-Output ("depts/tree EX: " + $_.Exception.Message) }