update-payment-urls.ps1 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # update-payment-urls.ps1
  2. # Batch update all api-config.json files to fill in payment page URLs
  3. # Run with -DryRun to preview changes
  4. param(
  5. [string]$SkillsRoot = (Split-Path $PSScriptRoot -Parent),
  6. [string]$PaymentDomain = "DEPLOY_DOMAIN_HERE",
  7. [string]$AuthId = "T0iOotHcDX",
  8. [switch]$DryRun
  9. )
  10. $utf8NoBom = New-Object System.Text.UTF8Encoding($false)
  11. $paymentBaseUrl = "https://$PaymentDomain/apig-pay.html?authid=$AuthId"
  12. $balanceCheckUrl = "https://server.fmode.cn/api/apig/getApig"
  13. Write-Host "Payment URL: $paymentBaseUrl" -ForegroundColor Cyan
  14. Write-Host "Balance Check: $balanceCheckUrl" -ForegroundColor Cyan
  15. Write-Host ""
  16. $categories = @("voc","social-media","competitor-analysis","review-analysis","synthesis","social-voc","douyin","video-creation")
  17. $updated = 0
  18. $skipped = 0
  19. foreach ($cat in $categories) {
  20. $catPath = Join-Path $SkillsRoot $cat
  21. if (-not (Test-Path $catPath)) { continue }
  22. Get-ChildItem -Recurse -Filter "api-config.json" -Path $catPath | ForEach-Object {
  23. $filePath = $_.FullName
  24. $content = [System.IO.File]::ReadAllText($filePath, [System.Text.Encoding]::UTF8)
  25. # Skip files without tokenConfig
  26. if ($content -notmatch '"tokenConfig"') {
  27. Write-Host " [SKIP] no tokenConfig: $($filePath.Replace($SkillsRoot+'\',''))" -ForegroundColor DarkGray
  28. $skipped++
  29. return
  30. }
  31. # Skip files already with payment URL filled
  32. if ($content -match '"qrCodeUrl":\s*"https://') {
  33. Write-Host " [SKIP] already has URL: $($filePath.Replace($SkillsRoot+'\',''))" -ForegroundColor DarkGray
  34. $skipped++
  35. return
  36. }
  37. $changed = $false
  38. # Replace empty qrCodeUrl with payment page URL
  39. if ($content -match '"qrCodeUrl":\s*""') {
  40. $content = $content -replace '"qrCodeUrl":\s*""', "`"qrCodeUrl`": `"$paymentBaseUrl`""
  41. $changed = $true
  42. }
  43. # Replace empty paymentCheckEndpoint with getApig balance check
  44. if ($content -match '"paymentCheckEndpoint":\s*""') {
  45. $content = $content -replace '"paymentCheckEndpoint":\s*""', "`"paymentCheckEndpoint`": `"$balanceCheckUrl`""
  46. $changed = $true
  47. }
  48. # Replace empty paymentUrl if present
  49. if ($content -match '"paymentUrl":\s*""') {
  50. $content = $content -replace '"paymentUrl":\s*""', "`"paymentUrl`": `"$paymentBaseUrl`""
  51. $changed = $true
  52. }
  53. if ($changed) {
  54. if ($DryRun) {
  55. Write-Host " [DRY] $($filePath.Replace($SkillsRoot+'\',''))" -ForegroundColor Yellow
  56. } else {
  57. [System.IO.File]::WriteAllText($filePath, $content, $utf8NoBom)
  58. Write-Host " [OK] $($filePath.Replace($SkillsRoot+'\',''))" -ForegroundColor Green
  59. }
  60. $updated++
  61. } else {
  62. Write-Host " [SKIP] nothing to update: $($filePath.Replace($SkillsRoot+'\',''))" -ForegroundColor DarkGray
  63. $skipped++
  64. }
  65. }
  66. }
  67. Write-Host ""
  68. Write-Host "Done: $updated updated, $skipped skipped"
  69. if ($DryRun) { Write-Host "Remove -DryRun to apply." -ForegroundColor Yellow }