@echo off chcp 65001 > nul :: 强制在持久cmd窗口中运行 if "%1"=="" ( cmd /k "%~f0" run exit /b ) title WeChat Article API Service echo. echo ======================================== echo WeChat Article API Service v1.0.0 echo FastAPI Edition - One-Click Startup echo ======================================== echo. :: Configuration variables set PROJECT_NAME=wechat-article-api set SERVICE_PORT=5000 set PYTHON_VERSION=3.8 set VENV_NAME=venv :: Step 1: Check Python environment echo [94m[1/6] Checking Python environment...[0m python --version >nul 2>&1 if errorlevel 1 ( echo [91mX Python is not installed or not in PATH[0m echo Please install Python %PYTHON_VERSION%+ and add to PATH echo Download from: https://www.python.org/downloads/ pause exit /b 1 ) for /f "tokens=2" %%i in ('python --version') do set INSTALLED_PYTHON=%%i echo [92m+ Python version: %INSTALLED_PYTHON%[0m :: Check pip pip --version >nul 2>&1 if errorlevel 1 ( echo [91mX pip is not installed[0m echo Please install pip pause exit /b 1 ) echo [92m+ pip is installed[0m :: Step 2: Create virtual environment echo. echo [94m[2/6] Creating Python virtual environment...[0m if exist "%VENV_NAME%" ( echo [93m! Virtual environment already exists, skipping creation[0m ) else ( python -m venv %VENV_NAME% if errorlevel 1 ( echo [91mX Virtual environment creation failed[0m pause exit /b 1 ) echo [92m+ Virtual environment created successfully[0m ) :: Activate virtual environment call %VENV_NAME%\Scripts\activate.bat if errorlevel 1 ( echo [91mX Virtual environment activation failed[0m pause exit /b 1 ) echo [92m+ Virtual environment activated[0m :: Step 3: Install dependencies echo. echo [94m[3/6] Installing Python dependencies...[0m if exist "requirements.txt" ( pip install -r requirements.txt if errorlevel 1 ( echo [91mX Dependencies installation failed[0m pause exit /b 1 ) echo [92m+ Dependencies installed successfully[0m ) else ( echo [93m! requirements.txt not found, installing core dependencies manually[0m pip install fastapi uvicorn httpx python-dotenv if errorlevel 1 ( echo [91mX Core dependencies installation failed[0m pause exit /b 1 ) echo [92m+ Core dependencies installed successfully[0m ) :: Step 4: Check .env configuration echo. echo [94m[4/6] Checking configuration file...[0m if not exist ".env" ( echo [93m! .env file not found, creating from template...[0m if exist "env.example" ( copy env.example .env >nul echo [92m+ .env file created from env.example[0m ) else ( echo [93m! env.example not found, creating basic .env file...[0m ( echo # WeChat Article API Configuration echo # Auto-generated by start.bat echo. echo # Authentication Info ^(Auto-filled after login^) echo WECHAT_TOKEN= echo WECHAT_COOKIE= echo WECHAT_FAKEID= echo WECHAT_NICKNAME= echo WECHAT_EXPIRE_TIME= echo. echo # Service Configuration echo PORT=5000 echo HOST=0.0.0.0 echo DEBUG=false echo. echo # Rate Limiting echo RATE_LIMIT_GLOBAL=10 echo RATE_LIMIT_PER_IP=5 echo RATE_LIMIT_ARTICLE_INTERVAL=3 ) > .env echo [92m+ Basic .env file created[0m ) echo. echo [93m========================================[0m echo [93m First-time Setup[0m echo [93m========================================[0m echo. echo [92mNext Steps:[0m echo 1. Service will start in a moment echo 2. Visit: http://localhost:5000/login.html echo 3. Scan QR code with WeChat echo 4. Login credentials will be saved automatically echo. echo [93m========================================[0m echo. ) else ( echo [92m+ .env configuration file found[0m :: Check required configuration items findstr /C:"WECHAT_TOKEN=" .env | findstr /V "WECHAT_TOKEN=$" | findstr /V "WECHAT_TOKEN= *$" >nul 2>nul if errorlevel 1 ( echo [93m! WeChat credentials not configured yet[0m echo [93m Please visit http://localhost:5000/login.html to login[0m ) else ( echo [92m+ WeChat login credentials configured[0m ) ) echo. :: Step 5: Detect system configuration echo [94m[5/6] Detecting system configuration...[0m :: Get CPU cores for /f "tokens=2 delims==" %%a in ('wmic cpu get NumberOfLogicalProcessors /value ^| find "="') do set CPU_CORES=%%a if not defined CPU_CORES set CPU_CORES=4 :: Get memory size (GB) for /f "tokens=2 delims==" %%a in ('wmic computersystem get TotalPhysicalMemory /value ^| find "="') do set MEMORY_BYTES=%%a if defined MEMORY_BYTES ( set /a MEMORY_GB=MEMORY_BYTES/1073741824 ) else ( set MEMORY_GB=8 ) echo [92m+ System configuration:[0m echo CPU cores: %CPU_CORES% echo Memory: %MEMORY_GB%GB echo. :: Step 6: Start service echo [94m[6/6] Starting FastAPI service...[0m echo. echo ======================================== echo [92mService Startup Information[0m echo ======================================== echo. echo [94mAccess URLs:[0m echo - Admin Panel: http://localhost:%SERVICE_PORT%/admin.html echo - Login Page: http://localhost:%SERVICE_PORT%/login.html echo - API Docs: http://localhost:%SERVICE_PORT%/api/docs echo - ReDoc: http://localhost:%SERVICE_PORT%/api/redoc echo - Health: http://localhost:%SERVICE_PORT%/api/health echo. echo [94mCore Features:[0m echo + Article Retrieval - POST /api/article echo + Article List - GET /api/public/articles echo + Article Search - GET /api/public/articles/search echo + Account Search - GET /api/public/searchbiz echo + Image Proxy - GET /api/image echo + Auto Rate Limiting echo + Webhook Notifications echo. echo [94mSystem Info:[0m echo CPU: %CPU_CORES% cores echo Memory: %MEMORY_GB%GB echo. echo ======================================== echo. echo [93mFirst time? Please visit login page to scan QR code:[0m echo =^> http://localhost:%SERVICE_PORT%/login.html echo. echo [93mTip: Press Ctrl+C to stop service[0m echo. :: Start service python app.py echo. echo [92mService stopped[0m pause