Files
douyin_cookie_yunsya/README.md
T
travel 9e0644095f 重构为 HTTP SSO 扫码方案并引入 Vue3 前端
移除 Playwright 浏览器自动化,改用 passport/SSO HTTP 接口获取二维码与轮询登录;后端模块化拆分,前端替换为 Vue3 SPA。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-25 10:47:55 +08:00

77 lines
1.8 KiB
Markdown
Raw 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 一键提取
扫码登录抖音后,自动导出 JSON 格式 Cookie。
## 原理
采用 **HTTP SSO 接口**(无需 Playwright / 浏览器):
1. 注册 `ttwid` 设备标识
2. 调用 `passport/web/get_qrcode``sso.douyin.com/get_qrcode` 获取二维码
3. 轮询 `check_qrconnect` 检测扫码状态
4. 确认后跟随 `redirect_url` 完成会话,导出 Cookie
> 若服务器 IP 被抖音风控(错误码 4031),请配置**住宅代理 API**。
### 与其他方案对比
| 方案 | 说明 | 本项目 |
|------|------|--------|
| HTTP SSO | 逆向 passport 接口,轻量快速 | **当前采用** |
| Playwright | 模拟浏览器,重、易碎 | 已移除 |
| 开放平台 OAuth | 需注册应用,返回 access_token 非网页 Cookie | 不适用 |
## 环境要求
- Python 3.9+
- Node.js 18+(仅构建前端时需要)
## 安装
```bash
pip install -r requirements.txt
cd frontend
npm install
npm run build
```
## 运行
```bash
py -3 app.py
```
访问:http://127.0.0.1:5001
## 环境变量
| 变量 | 默认值 | 说明 |
|------|--------|------|
| `PORT` | `5001` | 服务端口 |
| `LOGIN_TIMEOUT` | `600` | 登录超时(秒) |
| `QR_POLL_INTERVAL` | `2` | 建议前端轮询间隔 |
| `DOUYIN_AID` | `6383` | 抖音 Web 应用 ID |
| `DOUYIN_SERVICE` | `https://www.douyin.com` | SSO service 参数 |
## API
| 接口 | 说明 |
|------|------|
| `POST /api/start_qr` | 获取二维码(HTTP SSO |
| `GET /api/check_login` | 轮询扫码/登录状态 |
| `POST /api/reset` | 重置会话 |
| `GET /api/debug` | SSO 轮询调试信息 |
| `POST /api/test_proxy` | 测试代理 |
## 项目结构
```
app.py
backend/
sso/qr_login.py # HTTP 扫码登录核心
cookies.py # Cookie 检测
routes/ # API + SPA
frontend/ # Vue 3 前端
```