Files
ai_wht_wechat/backend/LOGIN_PAGE_CONFIG.md
2026-01-06 19:36:42 +08:00

109 lines
2.6 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的来源页面支持两种选项
- **creator**: 创作者中心 (https://creator.xiaohongshu.com/login)
- **home**: 小红书首页 (https://www.xiaohongshu.com)
## 配置方法
### 1. 修改配置文件
`config.dev.yaml``config.prod.yaml` 中找到 `login` 配置节:
```yaml
# ========== 登录/绑定功能配置 ==========
login:
headless: false # 登录/绑定时的浏览器模式
page: "creator" # 登录页面类型: creator 或 home
```
`page` 的值修改为你想要的登录页面:
- `"creator"`: 使用创作者中心登录页
- `"home"`: 使用小红书首页登录
### 2. 重启服务
修改配置后需要重启Python后端服务使配置生效
```bash
# Windows
cd backend
.\start.bat
# Linux
cd backend
./start.sh
```
## API参数覆盖
即使配置了默认值API请求仍然可以通过 `login_page` 参数临时覆盖配置:
```javascript
// 发送验证码
POST /api/xhs/send-code
{
"phone": "13800138000",
"country_code": "+86",
"login_page": "home" // 可选,不传则使用配置文件默认值
}
// 登录
POST /api/xhs/login
{
"phone": "13800138000",
"code": "123456",
"country_code": "+86",
"login_page": "home", // 可选,不传则使用配置文件默认值
"session_id": "xxx"
}
```
## 优先级说明
1. **最高优先级**: API请求中的 `login_page` 参数
2. **默认值**: 配置文件中的 `login.page` 配置
3. **兜底值**: 如果都未配置,默认使用 `creator`
## 测试验证
运行测试脚本验证配置是否正确:
```bash
cd backend
python test_login_page_config.py
```
## 配置影响范围
修改 `login.page` 配置会影响以下功能:
1. **发送验证码接口** (`/api/xhs/send-code`)
2. **登录接口** (`/api/xhs/login`)
3. **浏览器池预热URL** (根据配置自动调整)
## 注意事项
1. 两个登录页面的HTML结构可能略有不同如遇到问题请切换尝试
2. 建议在开发环境先测试再应用到生产环境
3. 配置修改后需要重启服务才能生效
4. 如果API明确传入了 `login_page` 参数会优先使用API参数而不是配置文件
## 示例场景
### 场景1全局使用创作者中心
```yaml
login:
page: "creator"
```
不传API参数时所有请求都使用创作者中心登录。
### 场景2全局使用首页但个别请求使用创作者中心
```yaml
login:
page: "home"
```
大部分请求使用首页但特殊情况下API可以传 `"login_page": "creator"` 临时切换。