| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- # Test APIG billing flow - all endpoints
- $utf8 = [System.Text.Encoding]::UTF8
- # Social media APIG id
- $apigId = "Vo3ROWEvDy"
- Write-Host "========================================" -ForegroundColor Cyan
- Write-Host " APIG Billing Flow - Connectivity Test" -ForegroundColor Cyan
- Write-Host "========================================" -ForegroundColor Cyan
- Write-Host ""
- # --- Step 1: getApig ---
- Write-Host "=== Step 1: getApig (authid=$apigId) ===" -ForegroundColor Cyan
- $body1 = @{ authid = $apigId } | ConvertTo-Json -Compress
- try {
- $r1 = Invoke-RestMethod -Uri "https://server.fmode.cn/api/apig/getApig" -Method POST -ContentType "application/json" -Body $body1 -TimeoutSec 15
- Write-Host "Response:" -ForegroundColor Green
- $r1 | ConvertTo-Json -Depth 5
- } catch {
- Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
- if ($_.Exception.Response) {
- $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
- Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
- }
- }
- Write-Host ""
- # --- Step 2: Try pay_code2 (generate QR code) ---
- Write-Host "=== Step 2: pay_code2 (generate QR code) ===" -ForegroundColor Cyan
- $now = Get-Date
- $tradeNo = "CTEST" + $now.ToString("yyyyMMddHHmmssfff")
- Write-Host "TradeNo: $tradeNo"
- # pay_code2 is a Parse Cloud Function
- $payBody = @{
- _ApplicationId = "ncloudmaster"
- company = "1AiWpTEDH9"
- out_trade_no = $tradeNo
- total_fee = 0.01
- body = "VOC Social API Test"
- } | ConvertTo-Json -Compress
- try {
- $r2 = Invoke-RestMethod -Uri "https://server.fmode.cn/parse/functions/pay_code2" -Method POST -ContentType "application/json" -Body $payBody -TimeoutSec 15
- Write-Host "Response:" -ForegroundColor Green
- $r2 | ConvertTo-Json -Depth 5
- } catch {
- Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
- if ($_.Exception.Response) {
- $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
- Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
- }
- }
- Write-Host ""
- # --- Step 3: created-apigorder (with user field per Chen Bin's update) ---
- Write-Host "=== Step 3: created-apigorder ===" -ForegroundColor Cyan
- $orderBody = @{
- user = "test-openclaw-user"
- type = "wxpay"
- authid = $apigId
- params = @{
- out_trade_no = $tradeNo
- total_fee = 0.01
- body = "VOC Social API Test"
- }
- apigid = $apigId
- oldCount = 0
- count = 100
- } | ConvertTo-Json -Depth 3 -Compress
- try {
- $r3 = Invoke-RestMethod -Uri "https://server.fmode.cn/api/apig/created-apigorder" -Method POST -ContentType "application/json" -Body $orderBody -TimeoutSec 15
- Write-Host "Response:" -ForegroundColor Green
- $r3 | ConvertTo-Json -Depth 5
- } catch {
- Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
- if ($_.Exception.Response) {
- $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
- Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
- }
- }
- Write-Host ""
- # --- Step 4: order_status2 (check payment status) ---
- Write-Host "=== Step 4: order_status2 (check payment status) ===" -ForegroundColor Cyan
- $statusBody = @{
- _ApplicationId = "ncloudmaster"
- out_trade_no = $tradeNo
- nonce_str = "test_nonce"
- company = "1AiWpTEDH9"
- } | ConvertTo-Json -Compress
- try {
- $r4 = Invoke-RestMethod -Uri "https://server.fmode.cn/parse/functions/order_status2" -Method POST -ContentType "application/json" -Body $statusBody -TimeoutSec 15
- Write-Host "Response:" -ForegroundColor Green
- $r4 | ConvertTo-Json -Depth 5
- } catch {
- Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
- if ($_.Exception.Response) {
- $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
- Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
- }
- }
- Write-Host ""
- # --- Step 5: saveRecharge (just test endpoint, won't actually save) ---
- Write-Host "=== Step 5: saveRecharge (endpoint test) ===" -ForegroundColor Cyan
- $rechargeBody = @{
- user = "test-openclaw-user"
- authid = $apigId
- apigid = "test-apig-auth-id"
- oldCount = 0
- count = 100
- orderid = "test-order-id"
- } | ConvertTo-Json -Compress
- try {
- $r5 = Invoke-RestMethod -Uri "https://server.fmode.cn/api/apig/saveRecharge" -Method POST -ContentType "application/json" -Body $rechargeBody -TimeoutSec 15
- Write-Host "Response:" -ForegroundColor Green
- $r5 | ConvertTo-Json -Depth 5
- } catch {
- Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
- if ($_.Exception.Response) {
- $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
- Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
- }
- }
|