# 拉取钉钉组织数据:调试 token -> POST /api/system/sync/dingtalk $base = "http://127.0.0.1:8081" $userId = "739564171091247104" # 1. verify profile 调试 token $tokResp = Invoke-RestMethod -Method Get -Uri "$base/api/auth/debug/token?userId=$userId" -TimeoutSec 30 $token = $tokResp.data if (-not $token) { Write-Output "=== TOKEN FAIL ===" $tokResp | ConvertTo-Json -Depth 5 exit 1 } $token | Out-File -Encoding ascii "d:\code\crm-backend-matt\tmp\dt-token.txt" Write-Output "token OK (len=$($token.Length))" # 2. 触发钉钉组织同步(阻塞,组织规模大时较慢) try { $syncResp = Invoke-RestMethod -Method Post -Uri "$base/api/system/sync/dingtalk" ` -Headers @{ Authorization = "Bearer $token" } ` -ContentType "application/x-www-form-urlencoded" -TimeoutSec 900 Write-Output "=== SYNC OK ===" $syncResp | ConvertTo-Json -Depth 6 } catch { Write-Output "=== SYNC FAIL ===" $resp = $_.Exception.Response if ($resp) { try { $sr = New-Object IO.StreamReader($resp.GetResponseStream()) Write-Output ("HTTP " + [int]$resp.StatusCode) Write-Output $sr.ReadToEnd() } catch { Write-Output $_.Exception.Message } } else { Write-Output $_.Exception.Message } }