# update-payment-urls.ps1 # Batch update all api-config.json files to fill in payment page URLs # Run with -DryRun to preview changes param( [string]$SkillsRoot = (Split-Path $PSScriptRoot -Parent), [string]$PaymentDomain = "DEPLOY_DOMAIN_HERE", [string]$AuthId = "T0iOotHcDX", [switch]$DryRun ) $utf8NoBom = New-Object System.Text.UTF8Encoding($false) $paymentBaseUrl = "https://$PaymentDomain/apig-pay.html?authid=$AuthId" $balanceCheckUrl = "https://server.fmode.cn/api/apig/getApig" Write-Host "Payment URL: $paymentBaseUrl" -ForegroundColor Cyan Write-Host "Balance Check: $balanceCheckUrl" -ForegroundColor Cyan Write-Host "" $categories = @("voc","social-media","competitor-analysis","review-analysis","synthesis","social-voc","douyin","video-creation") $updated = 0 $skipped = 0 foreach ($cat in $categories) { $catPath = Join-Path $SkillsRoot $cat if (-not (Test-Path $catPath)) { continue } Get-ChildItem -Recurse -Filter "api-config.json" -Path $catPath | ForEach-Object { $filePath = $_.FullName $content = [System.IO.File]::ReadAllText($filePath, [System.Text.Encoding]::UTF8) # Skip files without tokenConfig if ($content -notmatch '"tokenConfig"') { Write-Host " [SKIP] no tokenConfig: $($filePath.Replace($SkillsRoot+'\',''))" -ForegroundColor DarkGray $skipped++ return } # Skip files already with payment URL filled if ($content -match '"qrCodeUrl":\s*"https://') { Write-Host " [SKIP] already has URL: $($filePath.Replace($SkillsRoot+'\',''))" -ForegroundColor DarkGray $skipped++ return } $changed = $false # Replace empty qrCodeUrl with payment page URL if ($content -match '"qrCodeUrl":\s*""') { $content = $content -replace '"qrCodeUrl":\s*""', "`"qrCodeUrl`": `"$paymentBaseUrl`"" $changed = $true } # Replace empty paymentCheckEndpoint with getApig balance check if ($content -match '"paymentCheckEndpoint":\s*""') { $content = $content -replace '"paymentCheckEndpoint":\s*""', "`"paymentCheckEndpoint`": `"$balanceCheckUrl`"" $changed = $true } # Replace empty paymentUrl if present if ($content -match '"paymentUrl":\s*""') { $content = $content -replace '"paymentUrl":\s*""', "`"paymentUrl`": `"$paymentBaseUrl`"" $changed = $true } if ($changed) { if ($DryRun) { Write-Host " [DRY] $($filePath.Replace($SkillsRoot+'\',''))" -ForegroundColor Yellow } else { [System.IO.File]::WriteAllText($filePath, $content, $utf8NoBom) Write-Host " [OK] $($filePath.Replace($SkillsRoot+'\',''))" -ForegroundColor Green } $updated++ } else { Write-Host " [SKIP] nothing to update: $($filePath.Replace($SkillsRoot+'\',''))" -ForegroundColor DarkGray $skipped++ } } } Write-Host "" Write-Host "Done: $updated updated, $skipped skipped" if ($DryRun) { Write-Host "Remove -DryRun to apply." -ForegroundColor Yellow }