This commit is contained in:
sjk
2026-01-07 12:18:55 +08:00
parent a7305908de
commit cb267e8d5e
18 changed files with 411 additions and 133 deletions

View File

@@ -346,8 +346,30 @@ func (s *EmployeeService) asyncBindXHS(employeeID int, xhsPhone, code string) {
return fmt.Errorf("小红书登录失败: %w", err)
}
// 检Python服务返回结果
// 检Python服务返回结果
if loginResult.Code != 0 {
// 检查是否需要扫码验证
if needCaptcha, ok := loginResult.Data["need_captcha"].(bool); ok && needCaptcha {
// 出现验证码,更新绑定状态为"need_captcha"
captchaData := map[string]interface{}{
"status": "need_captcha",
"captcha_type": loginResult.Data["captcha_type"],
"message": loginResult.Data["message"],
}
// 如果有二维码图片,也一并返回
if qrcodeImage, ok := loginResult.Data["qrcode_image"].(string); ok {
captchaData["qrcode_image"] = qrcodeImage
}
// 将captchaData序列化并存入Redis
captchaJSON, _ := json.Marshal(captchaData)
if err := database.RDB.Set(ctx, bindStatusKey, string(captchaJSON), 180*time.Second).Err(); err != nil {
log.Printf("绑定小红书 - 用户%d - 更新验证状态失败: %v", employeeID, err)
}
log.Printf("绑定小红书 - 用户%d - 需要验证码验证: %s", employeeID, loginResult.Data["captcha_type"])
return fmt.Errorf("需要验证码验证")
}
return fmt.Errorf("小红书登录失败: %s", loginResult.Message)
}
@@ -534,7 +556,7 @@ func (s *EmployeeService) GetBindXHSStatus(employeeID int) (map[string]interface
}
// 尝试解析JSON状态
var statusData map[string]string
var statusData map[string]interface{}
if err := json.Unmarshal([]byte(statusJSON), &statusData); err != nil {
log.Printf("获取绑定状态 - 用户%d - JSON解析失败: %v, 原始数据: %s", employeeID, err, statusJSON)
// 如果不是JSON可能是纯字符串状态
@@ -550,17 +572,36 @@ func (s *EmployeeService) GetBindXHSStatus(employeeID int) (map[string]interface
"status": statusData["status"],
}
if statusData["status"] == "success" {
result["xhs_account"] = statusData["xhs_account"]
result["message"] = "绑定成功"
log.Printf("获取绑定状态 - 用户%d - 绑定成功: %s", employeeID, statusData["xhs_account"])
} else if statusData["status"] == "failed" {
result["error"] = statusData["error"]
log.Printf("获取绑定状态 - 用户%d - 绑定失败: %s", employeeID, statusData["error"])
} else if statusData["status"] == "processing" {
// JSON格式的processing状态
result["message"] = "正在登录小红书,请稍候..."
log.Printf("获取绑定状态 - 用户%d - 状态: processing (JSON格式)", employeeID)
if status, ok := statusData["status"].(string); ok {
switch status {
case "success":
if xhsAccount, ok := statusData["xhs_account"].(string); ok {
result["xhs_account"] = xhsAccount
}
result["message"] = "绑定成功"
log.Printf("获取绑定状态 - 用户%d - 绑定成功", employeeID)
case "failed":
if errorMsg, ok := statusData["error"].(string); ok {
result["error"] = errorMsg
}
log.Printf("获取绑定状态 - 用户%d - 绑定失败", employeeID)
case "processing":
result["message"] = "正在登录小红书,请稍候..."
log.Printf("获取绑定状态 - 用户%d - 状态: processing", employeeID)
case "need_captcha":
// 需要验证码验证
if message, ok := statusData["message"].(string); ok {
result["message"] = message
}
if captchaType, ok := statusData["captcha_type"].(string); ok {
result["captcha_type"] = captchaType
}
// 如果有二维码图片,也返回
if qrcodeImage, ok := statusData["qrcode_image"].(string); ok {
result["qrcode_image"] = qrcodeImage
}
log.Printf("获取绑定状态 - 用户%d - 需要验证码: %s", employeeID, statusData["captcha_type"])
}
}
return result, nil