test-video-auth.ps1 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Test auth signing and relay via both endpoints
  2. $appKey = "ZmNmOGRhNjYzZTAx"
  3. $appSecretB64 = "ZWFhMTIxNTRjMjQ4Y2FkOTE1OWE5ZDZlYThiZWRmNDY="
  4. $appSecret = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($appSecretB64))
  5. Write-Host "appKey: $appKey"
  6. Write-Host "appSecret (decoded): $appSecret"
  7. $timestamp = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds().ToString()
  8. $signStr = "$timestamp#$appSecret"
  9. Write-Host "signStr: $signStr"
  10. $md5 = [System.Security.Cryptography.MD5]::Create()
  11. $signBytes = $md5.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($signStr))
  12. $sign = ($signBytes | ForEach-Object { $_.ToString("x2") }) -join ''
  13. Write-Host "sign: $sign"
  14. Write-Host ""
  15. # Test 1: Direct call to kuaizi API (bypass relay)
  16. Write-Host "=== Test 1: Direct kuaizi API call ===" -ForegroundColor Cyan
  17. $headers1 = @{
  18. "Content-Type" = "application/json"
  19. "APP-KEY" = $appKey
  20. "AUTH-TIMESTAMP" = $timestamp
  21. "AUTH-SIGN" = $sign
  22. }
  23. $directBody = @{
  24. account_id = "12859_117409"
  25. } | ConvertTo-Json -Compress
  26. try {
  27. # Try a lightweight endpoint to check auth - /v2/video/vlog/list
  28. $r1 = Invoke-RestMethod -Uri "https://openapi.kuaizi.co/v2/video/vlog/list" -Method POST -Headers $headers1 -Body $directBody -TimeoutSec 15
  29. Write-Host "openapi.kuaizi.co Response:" -ForegroundColor Green
  30. $r1 | ConvertTo-Json -Depth 3
  31. } catch {
  32. Write-Host "openapi.kuaizi.co Error: $($_.Exception.Message)" -ForegroundColor Red
  33. }
  34. Write-Host ""
  35. # Try open.kuaizi.co instead
  36. try {
  37. $r1b = Invoke-RestMethod -Uri "https://open.kuaizi.co/v2/video/vlog/list" -Method POST -Headers $headers1 -Body $directBody -TimeoutSec 15
  38. Write-Host "open.kuaizi.co Response:" -ForegroundColor Green
  39. $r1b | ConvertTo-Json -Depth 3
  40. } catch {
  41. Write-Host "open.kuaizi.co Error: $($_.Exception.Message)" -ForegroundColor Red
  42. }
  43. Write-Host ""
  44. # Test 2: Via Parse cloud function with relay
  45. Write-Host "=== Test 2: Relay via Parse function ===" -ForegroundColor Cyan
  46. $relayData = @{
  47. apiPath = "/v2/video/vlog/list"
  48. apiBody = @{ account_id = "12859_117409" }
  49. appKey = $appKey
  50. timestamp = $timestamp
  51. sign = $sign
  52. } | ConvertTo-Json -Depth 3 -Compress
  53. $parseBody = @{
  54. id = "sWvRr8RvPT"
  55. _ApplicationId = "ncloudmaster"
  56. action = "relay"
  57. relayData = $relayData
  58. } | ConvertTo-Json -Compress
  59. try {
  60. $r2 = Invoke-RestMethod -Uri "https://server.fmode.cn/api/functions" -Method POST -ContentType "application/json" -Body $parseBody -TimeoutSec 15
  61. Write-Host "Parse relay Response:" -ForegroundColor Green
  62. $r2 | ConvertTo-Json -Depth 3
  63. } catch {
  64. Write-Host "Parse relay Error: $($_.Exception.Message)" -ForegroundColor Red
  65. }