This commit is contained in:
sjk
2026-01-23 16:27:47 +08:00
parent 213229953b
commit e8e6d913df
26 changed files with 4294 additions and 431 deletions

View File

@@ -31,7 +31,7 @@ wechat:
app_secret: "69d2a3ddc902b26f82f4b56a6e277f7a"
xhs:
python_service_url: "http://127.0.0.1:8020" # Python FastAPI服务地址用于登录和发布享受浏览器池+预热加速)
python_service_url: "http://127.0.0.1:8080" # Python FastAPI服务地址用于登录和发布享受浏览器池+预热加速)
scheduler:
enabled: false # 生产环境启用定时任务

View File

@@ -2351,25 +2351,35 @@ func (s *EmployeeService) SaveLogin(employeeID int, cookiesFull []interface{}, s
return fmt.Errorf("获取用户信息失败: %w", err)
}
// 优先使用 storage_state如果没有则降级使用 cookies_full
// 优先使用 cookies_full如果没有则降级使用 storage_state
var loginStateJSON string
if len(storageState) > 0 {
// 新版:使用 Playwright 的 storage_state
storageStateBytes, err := json.Marshal(storageState)
if err == nil {
loginStateJSON = string(storageStateBytes)
log.Printf("验证码登录 - 用户%d - StorageState长度: %d", employeeID, len(loginStateJSON))
} else {
log.Printf("验证码登录 - 用户%d - 序列化storage_state失败: %v", employeeID, err)
}
} else if len(cookiesFull) > 0 {
// 降级:使用旧版本的 cookies_full
log.Printf("验证码登录 - 用户%d - 警告: 未找到storage_state降级使用cookies", employeeID)
if len(cookiesFull) > 0 {
// 优先:直接使用 cookies_fullAdsPower Cookie
cookiesBytes, err := json.Marshal(cookiesFull)
if err == nil {
loginStateJSON = string(cookiesBytes)
log.Printf("验证码登录 - 用户%d - Cookie长度: %d", employeeID, len(loginStateJSON))
log.Printf("验证码登录 - 用户%d - 使用cookies_fullCookie长度: %d", employeeID, len(loginStateJSON))
} else {
log.Printf("验证码登录 - 用户%d - 序列化cookies_full失败: %v", employeeID, err)
}
} else if len(storageState) > 0 {
// 降级:从 storage_state 中提取 cookies
log.Printf("验证码登录 - 用户%d - 警告: 未找到cookies_full从storage_state提取cookies", employeeID)
if cookies, ok := storageState["cookies"].([]interface{}); ok && len(cookies) > 0 {
cookiesBytes, err := json.Marshal(cookies)
if err == nil {
loginStateJSON = string(cookiesBytes)
log.Printf("验证码登录 - 用户%d - 从storage_state提取的Cookie长度: %d", employeeID, len(loginStateJSON))
}
} else {
// 最终降级:保存整个 storage_state
log.Printf("验证码登录 - 用户%d - 无法提取cookies保存整个storage_state", employeeID)
storageStateBytes, err := json.Marshal(storageState)
if err == nil {
loginStateJSON = string(storageStateBytes)
log.Printf("验证码登录 - 用户%d - StorageState长度: %d", employeeID, len(loginStateJSON))
}
}
}