test-apig-real-user.ps1 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Test the full payment flow with a real userId
  2. # Step 1: Create order with real userId
  3. # Step 2: Generate QR code
  4. # Step 3: Check if saveRecharge works with real userId
  5. $realUserId = "nd7NOCmFiE"
  6. $apigId = "Vo3ROWEvDy"
  7. $ct = @{ "Content-Type" = "application/json" }
  8. Write-Host "=== Test with real userId: $realUserId ===" -ForegroundColor Cyan
  9. Write-Host ""
  10. # Step 1: Create order with real userId (using fcompany which works)
  11. $now = Get-Date
  12. $tradeNo = "CREAL" + $now.ToString("yyyyMMddHHmmssfff")
  13. Write-Host "TradeNo: $tradeNo"
  14. $orderBody = @{
  15. fcompany = $realUserId
  16. user = $realUserId
  17. type = "wxpay"
  18. authid = $apigId
  19. params = @{
  20. out_trade_no = $tradeNo
  21. total_fee = 0.01
  22. body = "test recharge"
  23. }
  24. apigid = $apigId
  25. oldCount = 99999
  26. count = 1
  27. } | ConvertTo-Json -Depth 3 -Compress
  28. Write-Host "=== Creating order ===" -ForegroundColor Cyan
  29. try {
  30. $orderResp = Invoke-RestMethod -Uri "https://server.fmode.cn/api/apig/created-apigorder" -Method POST -ContentType "application/json" -Body $orderBody -TimeoutSec 60
  31. Write-Host "Order response:" -ForegroundColor Green
  32. $orderResp | ConvertTo-Json -Depth 8
  33. $orderId = $orderResp.data.objectId
  34. $apigAuthId = $orderResp.data.detail.apigAuth.objectId
  35. Write-Host ""
  36. Write-Host "orderId: $orderId" -ForegroundColor Yellow
  37. Write-Host "apigAuthId: $apigAuthId" -ForegroundColor Yellow
  38. } catch {
  39. Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
  40. $orderId = ""
  41. $apigAuthId = ""
  42. }
  43. Write-Host ""
  44. # Step 2: Test saveRecharge with real userId and order
  45. if ($orderId) {
  46. Write-Host "=== Testing saveRecharge ===" -ForegroundColor Cyan
  47. $rechargeBody = @{
  48. user = $realUserId
  49. authComp = $realUserId
  50. fcompany = $realUserId
  51. authid = $apigId
  52. apigid = $apigAuthId
  53. oldCount = 99999
  54. count = 1
  55. orderid = $orderId
  56. } | ConvertTo-Json -Compress
  57. Write-Host "Recharge body: $rechargeBody"
  58. try {
  59. $rechargeResp = Invoke-RestMethod -Uri "https://server.fmode.cn/api/apig/saveRecharge" -Method POST -ContentType "application/json" -Body $rechargeBody -TimeoutSec 60
  60. Write-Host "Recharge response:" -ForegroundColor Green
  61. $rechargeResp | ConvertTo-Json -Depth 5
  62. } catch {
  63. Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
  64. if ($_.Exception.Response) {
  65. $reader = New-Object System.IO.StreamReader($_.Exception.Response.GetResponseStream())
  66. Write-Host "Body: $($reader.ReadToEnd())" -ForegroundColor Yellow
  67. }
  68. }
  69. }
  70. Write-Host ""
  71. # Step 3: Check if getApig now returns data (APIGAuth might have been created)
  72. Write-Host "=== Check getApig after order ===" -ForegroundColor Cyan
  73. $body3 = @{ authid = $apigId } | ConvertTo-Json -Compress
  74. try {
  75. $r3 = Invoke-WebRequest -Uri "https://server.fmode.cn/api/apig/getApig" -Method POST -ContentType "application/json" -Body $body3 -TimeoutSec 15
  76. Write-Host "getApig response: $($r3.Content)" -ForegroundColor Green
  77. } catch {
  78. Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
  79. }