commit
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -218,8 +219,9 @@ func (ctrl *EmployeeController) BindXHS(c *gin.Context) {
|
||||
employeeID := c.GetInt("employee_id")
|
||||
|
||||
var req struct {
|
||||
XHSPhone string `json:"xhs_phone" binding:"required"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
XHSPhone string `json:"xhs_phone" binding:"required"`
|
||||
Code string `json:"code" binding:"required"`
|
||||
SessionID string `json:"session_id"` // 发送验证码时返回的session_id,用于复用浏览器
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -227,7 +229,7 @@ func (ctrl *EmployeeController) BindXHS(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := ctrl.service.BindXHS(employeeID, req.XHSPhone, req.Code)
|
||||
_, err := ctrl.service.BindXHS(employeeID, req.XHSPhone, req.Code, req.SessionID)
|
||||
if err != nil {
|
||||
common.Error(c, common.CodeBindXHSFailed, err.Error())
|
||||
return
|
||||
@@ -746,3 +748,109 @@ func (ctrl *EmployeeController) RevokeUserToken(c *gin.Context) {
|
||||
|
||||
common.SuccessWithMessage(c, fmt.Sprintf("已禁用用户 %s (手机号: %s),该用户需要重新登录", targetUser.Username, targetUser.Phone), nil)
|
||||
}
|
||||
|
||||
// SaveQRCodeLogin 保存扫码登录的绑定信息
|
||||
// 由Python后端调用,不需要认证
|
||||
func (ctrl *EmployeeController) SaveQRCodeLogin(c *gin.Context) {
|
||||
var req struct {
|
||||
EmployeeID int `json:"employee_id" binding:"required"`
|
||||
CookiesFull []interface{} `json:"cookies_full"`
|
||||
UserInfo map[string]interface{} `json:"user_info"`
|
||||
LoginState map[string]interface{} `json:"login_state"`
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.Error(c, common.CodeInvalidParams, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
// 调用service层直接保存,与验证码登录相同的逻辑
|
||||
err := ctrl.service.SaveQRCodeLogin(req.EmployeeID, req.CookiesFull, req.UserInfo, req.LoginState)
|
||||
if err != nil {
|
||||
common.Error(c, common.CodeInternalError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
common.SuccessWithMessage(c, "绑定成功", nil)
|
||||
}
|
||||
|
||||
// StartQRCodeLogin 启动扫码登录,转发到Python服务
|
||||
func (ctrl *EmployeeController) StartQRCodeLogin(c *gin.Context) {
|
||||
employeeID := c.GetInt("employee_id")
|
||||
|
||||
data, err := ctrl.service.StartQRCodeLogin(employeeID)
|
||||
if err != nil {
|
||||
common.Error(c, common.CodeInternalError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 直接返回Python的响应格式,保持code=0
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
// GetQRCodeStatus 获取扫码状态,转发到Python服务
|
||||
func (ctrl *EmployeeController) GetQRCodeStatus(c *gin.Context) {
|
||||
employeeID := c.GetInt("employee_id")
|
||||
|
||||
var req struct {
|
||||
SessionID string `json:"session_id" binding:"required"`
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.Error(c, common.CodeInvalidParams, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
data, err := ctrl.service.GetQRCodeStatus(employeeID, req.SessionID)
|
||||
if err != nil {
|
||||
common.Error(c, common.CodeInternalError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 直接返回Python的响应格式,保持code=0或code=2
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
// RefreshQRCode 刷新二维码,转发到Python服务
|
||||
func (ctrl *EmployeeController) RefreshQRCode(c *gin.Context) {
|
||||
employeeID := c.GetInt("employee_id")
|
||||
|
||||
var req struct {
|
||||
SessionID string `json:"session_id" binding:"required"`
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.Error(c, common.CodeInvalidParams, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
data, err := ctrl.service.RefreshQRCode(employeeID, req.SessionID)
|
||||
if err != nil {
|
||||
common.Error(c, common.CodeInternalError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 直接返回Python的响应格式,保持code=0或code=3
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
// CancelQRCodeLogin 取消扫码登录,释放浏览器资源
|
||||
func (ctrl *EmployeeController) CancelQRCodeLogin(c *gin.Context) {
|
||||
var req struct {
|
||||
SessionID string `json:"session_id" binding:"required"`
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
common.Error(c, common.CodeInvalidParams, "参数错误")
|
||||
return
|
||||
}
|
||||
|
||||
data, err := ctrl.service.CancelQRCodeLogin(req.SessionID)
|
||||
if err != nil {
|
||||
common.Error(c, common.CodeInternalError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 直接返回Python的响应格式
|
||||
c.JSON(http.StatusOK, data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user