Files
douyin/INSTALL.md
2026-07-17 09:24:47 +08:00

211 lines
4.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 本地安装说明
本文档用于在本机从零部署「抖音多账号自动回复」系统。**仅供本地使用,请勿将含 Cookie/数据库的目录提交到 GitHub。**
---
## 一、环境要求
| 组件 | 版本建议 | 用途 |
|------|----------|------|
| **Windows** | 10 / 11 | 当前脚本以 Windows 为主 |
| **Python** | 3.10 ~ 3.11 | 后端 FastAPI、Playwright、IM 签名 |
| **Node.js** | 18 LTS 或 20 LTS | `a_bogus` / `bd-ticket-guard` 签名(PyExecJS 调用) |
| **npm** | 随 Node 安装 | 前端依赖、IM 静态 JS 依赖 |
安装后可在 PowerShell 中确认:
```powershell
python --version
node --version
npm --version
```
---
## 二、一键安装(推荐)
在项目根目录 `d:\file\kefu` 双击或执行:
```powershell
.\install.bat
```
脚本会自动完成:
1. 创建 Python 虚拟环境 `backend\.venv`
2. 安装 `backend\requirements.txt` 全部 Python 包
3. 安装 Playwright Chromium 浏览器
4. 安装 IM 签名依赖(`backend\rpa_engine\douyin_im\static` 下的 `jsrsasign`
5. 安装前端依赖(`frontend\node_modules`
---
## 三、手动安装(分步)
### 1. 后端 Python 依赖
```powershell
cd backend
python -m venv .venv
.\.venv\Scripts\pip install -U pip
.\.venv\Scripts\pip install -r requirements.txt
```
### 2. Playwright 浏览器(登录 / 采集凭证必需)
```powershell
cd backend
$env:PLAYWRIGHT_BROWSERS_PATH = "$env:LOCALAPPDATA\ms-playwright"
.\.venv\Scripts\playwright install chromium
```
> 建议设置 `PLAYWRIGHT_BROWSERS_PATH`,避免浏览器被装到临时目录后找不到。`start_backend.bat` 已内置该变量。
### 3. IM 签名 Node 依赖(发送私信必需)
抖音私信 `a_bogus``bd-ticket-guard` 签名依赖 Node 与 `jsrsasign`
```powershell
cd backend\rpa_engine\douyin_im\static
npm install
```
依赖定义见:`backend\rpa_engine\douyin_im\static\package.json`(仅 `jsrsasign`)。
### 4. 前端依赖
```powershell
cd frontend
npm install
```
---
## 四、依赖清单汇总
### Python`backend/requirements.txt`
| 包 | 作用 |
|----|------|
| fastapi / uvicorn | Web API 服务 |
| sqlalchemy / aiosqlite | SQLite 异步数据库 |
| playwright | 浏览器登录、采集 Cookie / IM 凭证 |
| httpx / requests / websockets / websocket-client | IM HTTP / WebSocket |
| PyExecJS | 调用 Node 生成 a_bogus 等签名 |
| protobuf / protobuf3_to_dict | 抖音 IM Protobuf 编解码 |
| python-jose / passlib / bcrypt | 登录鉴权(JWT + 密码) |
| pydantic / python-multipart | 请求校验与表单 |
### Node(两处)
| 路径 | 依赖 | 作用 |
|------|------|------|
| `backend/rpa_engine/douyin_im/static/` | jsrsasign | IM 发送签名 |
| `frontend/` | vue, ant-design-vue, axios, pinia, vite 等 | 管理后台界面 |
### 系统级(非 pip/npm
| 组件 | 作用 |
|------|------|
| ChromiumPlaywright 安装) | 扫码登录、补全 sessionid / web_protect |
| Node.js 可执行文件 | PyExecJS 运行时 |
---
## 五、启动服务
### 后端
```powershell
# 项目根目录
.\start_backend.bat
```
或:
```powershell
cd backend
$env:PLAYWRIGHT_BROWSERS_PATH = "$env:LOCALAPPDATA\ms-playwright"
.\.venv\Scripts\uvicorn main:app --host 0.0.0.0 --port 8000
```
API 地址:`http://localhost:8000`
### 前端
```powershell
cd frontend
npm run dev
```
控制台地址:一般为 `http://localhost:5173`
默认管理员(首次启动自动创建):`admin` / `admin123`
生产环境请设置环境变量 `KEFU_SECRET_KEY``KEFU_ADMIN_PASSWORD`
---
## 六、常见问题
### 1. 启动报「找不到 uvicorn / playwright」
未执行安装步骤,请运行 `install.bat` 或第三节手动安装。
### 2. 私信发送报 7911 / 签名相关错误
- 确认 **Node.js 已安装** 且在 PATH 中:`node --version`
- 确认 IM 静态目录已 `npm install`
```powershell
dir backend\rpa_engine\douyin_im\static\node_modules\jsrsasign
```
- 在账号管理里用「浏览器模式」重新登录并打开一次私信页,刷新 `web_protect` / `keys`
### 3. 浏览器打不开 / Playwright 报错
```powershell
cd backend
.\.venv\Scripts\playwright install chromium
```
### 4. 前端 `npm run dev` 失败
```powershell
cd frontend
Remove-Item -Recurse -Force node_modules -ErrorAction SilentlyContinue
npm install
```
---
## 七、不要提交到 GitHub 的内容
以下目录/文件含运行数据或体积过大,**仅保留本地**:
- `backend/.venv/`
- `backend/kefu.db`(账号、规则、日志)
- `backend/sessions/`Cookie 等)
- `frontend/node_modules/`、`frontend/dist/`
- `backend/rpa_engine/douyin_im/static/node_modules/`
- `.env`、含密钥的配置
根目录已提供 `.gitignore` 模板,可按需使用。
---
## 八、更新依赖
```powershell
# 后端
cd backend
.\.venv\Scripts\pip install -r requirements.txt
# IM 签名
cd rpa_engine\douyin_im\static
npm install
# 前端
cd ..\..\..\frontend
npm install
```