test-apig-flow.ps1 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # Test APIG billing flow - all endpoints
  2. $utf8 = [System.Text.Encoding]::UTF8
  3. # Social media APIG id
  4. $apigId = "Vo3ROWEvDy"
  5. Write-Host "========================================" -ForegroundColor Cyan
  6. Write-Host " APIG Billing Flow - Connectivity Test" -ForegroundColor Cyan
  7. Write-Host "========================================" -ForegroundColor Cyan
  8. Write-Host ""
  9. # --- Step 1: getApig ---
  10. Write-Host "=== Step 1: getApig (authid=$apigId) ===" -ForegroundColor Cyan
  11. $body1 = @{ authid = $apigId } | ConvertTo-Json -Compress
  12. try {
  13. $r1 = Invoke-RestMethod -Uri "https://server.fmode.cn/api/apig/getApig" -Method POST -ContentType "application/json" -Body $body1 -TimeoutSec 15
  14. Write-Host "Response:" -ForegroundColor Green
  15. $r1 | ConvertTo-Json -Depth 5
  16. } catch {
  17. Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
  18. if ($_.Exception.Response) {
  19. $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
  20. Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
  21. }
  22. }
  23. Write-Host ""
  24. # --- Step 2: Try pay_code2 (generate QR code) ---
  25. Write-Host "=== Step 2: pay_code2 (generate QR code) ===" -ForegroundColor Cyan
  26. $now = Get-Date
  27. $tradeNo = "CTEST" + $now.ToString("yyyyMMddHHmmssfff")
  28. Write-Host "TradeNo: $tradeNo"
  29. # pay_code2 is a Parse Cloud Function
  30. $payBody = @{
  31. _ApplicationId = "ncloudmaster"
  32. company = "1AiWpTEDH9"
  33. out_trade_no = $tradeNo
  34. total_fee = 0.01
  35. body = "VOC Social API Test"
  36. } | ConvertTo-Json -Compress
  37. try {
  38. $r2 = Invoke-RestMethod -Uri "https://server.fmode.cn/parse/functions/pay_code2" -Method POST -ContentType "application/json" -Body $payBody -TimeoutSec 15
  39. Write-Host "Response:" -ForegroundColor Green
  40. $r2 | ConvertTo-Json -Depth 5
  41. } catch {
  42. Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
  43. if ($_.Exception.Response) {
  44. $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
  45. Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
  46. }
  47. }
  48. Write-Host ""
  49. # --- Step 3: created-apigorder (with user field per Chen Bin's update) ---
  50. Write-Host "=== Step 3: created-apigorder ===" -ForegroundColor Cyan
  51. $orderBody = @{
  52. user = "test-openclaw-user"
  53. type = "wxpay"
  54. authid = $apigId
  55. params = @{
  56. out_trade_no = $tradeNo
  57. total_fee = 0.01
  58. body = "VOC Social API Test"
  59. }
  60. apigid = $apigId
  61. oldCount = 0
  62. count = 100
  63. } | ConvertTo-Json -Depth 3 -Compress
  64. try {
  65. $r3 = Invoke-RestMethod -Uri "https://server.fmode.cn/api/apig/created-apigorder" -Method POST -ContentType "application/json" -Body $orderBody -TimeoutSec 15
  66. Write-Host "Response:" -ForegroundColor Green
  67. $r3 | ConvertTo-Json -Depth 5
  68. } catch {
  69. Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
  70. if ($_.Exception.Response) {
  71. $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
  72. Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
  73. }
  74. }
  75. Write-Host ""
  76. # --- Step 4: order_status2 (check payment status) ---
  77. Write-Host "=== Step 4: order_status2 (check payment status) ===" -ForegroundColor Cyan
  78. $statusBody = @{
  79. _ApplicationId = "ncloudmaster"
  80. out_trade_no = $tradeNo
  81. nonce_str = "test_nonce"
  82. company = "1AiWpTEDH9"
  83. } | ConvertTo-Json -Compress
  84. try {
  85. $r4 = Invoke-RestMethod -Uri "https://server.fmode.cn/parse/functions/order_status2" -Method POST -ContentType "application/json" -Body $statusBody -TimeoutSec 15
  86. Write-Host "Response:" -ForegroundColor Green
  87. $r4 | ConvertTo-Json -Depth 5
  88. } catch {
  89. Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
  90. if ($_.Exception.Response) {
  91. $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
  92. Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
  93. }
  94. }
  95. Write-Host ""
  96. # --- Step 5: saveRecharge (just test endpoint, won't actually save) ---
  97. Write-Host "=== Step 5: saveRecharge (endpoint test) ===" -ForegroundColor Cyan
  98. $rechargeBody = @{
  99. user = "test-openclaw-user"
  100. authid = $apigId
  101. apigid = "test-apig-auth-id"
  102. oldCount = 0
  103. count = 100
  104. orderid = "test-order-id"
  105. } | ConvertTo-Json -Compress
  106. try {
  107. $r5 = Invoke-RestMethod -Uri "https://server.fmode.cn/api/apig/saveRecharge" -Method POST -ContentType "application/json" -Body $rechargeBody -TimeoutSec 15
  108. Write-Host "Response:" -ForegroundColor Green
  109. $r5 | ConvertTo-Json -Depth 5
  110. } catch {
  111. Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
  112. if ($_.Exception.Response) {
  113. $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
  114. Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
  115. }
  116. }