# Cloudflare Tunnel 安装和启动脚本 Write-Host "=== Cloudflare Tunnel 设置 ===" -ForegroundColor Cyan # 检查是否已安装 $cloudflaredPath = Get-Command cloudflared -ErrorAction SilentlyContinue if (-not $cloudflaredPath) { Write-Host "`n[1/4] cloudflared 未安装,开始安装..." -ForegroundColor Yellow # 检查是否有 Scoop $scoopPath = Get-Command scoop -ErrorAction SilentlyContinue if ($scoopPath) { Write-Host "检测到 Scoop,使用 Scoop 安装..." -ForegroundColor Green scoop install cloudflared } else { Write-Host "未检测到 Scoop,请手动安装 cloudflared:" -ForegroundColor Yellow Write-Host "1. 下载:https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.msi" -ForegroundColor Cyan Write-Host "2. 双击安装 MSI 文件" -ForegroundColor Cyan Write-Host "3. 重新运行此脚本" -ForegroundColor Cyan exit 1 } } else { Write-Host "`n[1/4] ✓ cloudflared 已安装" -ForegroundColor Green cloudflared --version } # 检查 Docker 服务 Write-Host "`n[2/4] 检查 Docker 服务..." -ForegroundColor Yellow $backendStatus = docker compose ps backend --format json | ConvertFrom-Json | Select-Object -ExpandProperty State if ($backendStatus -ne "running") { Write-Host "后端服务未运行,正在启动..." -ForegroundColor Yellow docker compose up -d backend Start-Sleep -Seconds 5 } Write-Host "✓ Docker 服务运行正常" -ForegroundColor Green # 测试本地服务 Write-Host "`n[3/4] 测试本地服务..." -ForegroundColor Yellow try { $response = Invoke-WebRequest -Uri "http://localhost:8000/api/health" -UseBasicParsing -TimeoutSec 5 if ($response.StatusCode -eq 200) { Write-Host "✓ 本地服务正常 (http://localhost:8000)" -ForegroundColor Green } } catch { Write-Host "✗ 本地服务无法访问,请检查后端服务" -ForegroundColor Red Write-Host "运行: docker compose logs backend" -ForegroundColor Yellow exit 1 } # 启动 cloudflared Write-Host "`n[4/4] 启动 Cloudflare Tunnel..." -ForegroundColor Yellow Write-Host "正在启动 tunnel,请稍候..." -ForegroundColor Cyan Write-Host "`n=== 重要提示 ===" -ForegroundColor Yellow Write-Host "1. 下方会显示公网 URL(例如:https://xxx.trycloudflare.com)" -ForegroundColor White Write-Host "2. 复制这个 URL,用于配置企业微信回调" -ForegroundColor White Write-Host "3. 回调 URL 格式:https://你的域名.trycloudflare.com/api/wecom/callback" -ForegroundColor White Write-Host "4. 保持此窗口运行,不要关闭" -ForegroundColor White Write-Host "`n按 Ctrl+C 停止 tunnel`n" -ForegroundColor Yellow Write-Host "=" * 60 -ForegroundColor Cyan # 启动 tunnel cloudflared tunnel --url http://localhost:8000