修改了登录接口

This commit is contained in:
wucongxing8150 2025-06-18 17:08:12 +08:00
parent ec7df630f8
commit dc84dbbb44

View File

@ -245,7 +245,7 @@ func (b *Public) LoginProgram(c *gin.Context) {
req := publicRequest.LoginProgram req := publicRequest.LoginProgram
if err := c.ShouldBind(&req); err != nil { if err := c.ShouldBind(&req); err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "登录失败", "message": "登录失败1",
"code": -2, "code": -2,
"data": gin.H{ "data": gin.H{
"source": 2, "source": 2,
@ -258,7 +258,7 @@ func (b *Public) LoginProgram(c *gin.Context) {
// 参数验证 // 参数验证
if err := global.Validate.Struct(req); err != nil { if err := global.Validate.Struct(req); err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "登录失败", "message": "登录失败2",
"code": -2, "code": -2,
"data": gin.H{ "data": gin.H{
"source": 2, "source": 2,
@ -272,7 +272,7 @@ func (b *Public) LoginProgram(c *gin.Context) {
t, err := utils.ParseJwt(req.Token) t, err := utils.ParseJwt(req.Token)
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "登录失败", "message": "登录失败3",
"code": -2, "code": -2,
"data": gin.H{ "data": gin.H{
"source": 2, "source": 2,
@ -286,7 +286,7 @@ func (b *Public) LoginProgram(c *gin.Context) {
userId, err := strconv.ParseInt(t.UserId, 10, 64) userId, err := strconv.ParseInt(t.UserId, 10, 64)
if err != nil { if err != nil {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "登录失败", "message": "登录失败4",
"code": -2, "code": -2,
"data": gin.H{ "data": gin.H{
"source": 2, "source": 2,
@ -313,17 +313,36 @@ func (b *Public) LoginProgram(c *gin.Context) {
return return
} }
var platformId int
if user.RegisterSource == 2 {
platformId = 1
} else if user.RegisterSource == 3 {
platformId = 2
}
if platformId == 0 {
c.JSON(http.StatusOK, gin.H{
"message": "登录失败",
"code": -2,
"data": gin.H{
"source": 2,
},
})
return
}
// 下发token // 下发token
token := &utils.Token{ token := &utils.Token{
UserId: fmt.Sprintf("%d", user.UserId), UserId: fmt.Sprintf("%d", user.UserId),
PlatformId: fmt.Sprintf("%d", 2), PlatformId: fmt.Sprintf("%d", platformId),
} }
// 生成jwt // 生成jwt
jwt, err := token.NewJWT() jwt, err := token.NewJWT()
if err != nil || jwt == "" { if err != nil || jwt == "" {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"message": "登陆失败", "message": "登陆失败6",
"code": -1, "code": -1,
"data": gin.H{ "data": gin.H{
"source": 2, "source": 2,