commit
This commit is contained in:
@@ -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 # 生产环境启用定时任务
|
||||
|
||||
@@ -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_full(AdsPower Cookie)
|
||||
cookiesBytes, err := json.Marshal(cookiesFull)
|
||||
if err == nil {
|
||||
loginStateJSON = string(cookiesBytes)
|
||||
log.Printf("验证码登录 - 用户%d - Cookie长度: %d", employeeID, len(loginStateJSON))
|
||||
log.Printf("验证码登录 - 用户%d - 使用cookies_full,Cookie长度: %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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user