refactor: adjust project structure
This commit is contained in:
52
service/sms/ValidateHandler.go
Normal file
52
service/sms/ValidateHandler.go
Normal file
@ -0,0 +1,52 @@
|
||||
package sms
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"health-go/config"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Validate(c *gin.Context) {
|
||||
var user struct {
|
||||
Tel string `json:"tel"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&user); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": 400,
|
||||
"msg": "无效的请求参数",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
storageCode, err := config.RDC.Get(config.CTX, user.Tel).Result()
|
||||
fmt.Println("storageCode:", storageCode)
|
||||
|
||||
if errors.Is(err, redis.Nil) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"msg": "验证码已过期",
|
||||
"data": nil,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if user.Code != storageCode {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"msg": "验证码错误",
|
||||
"data": nil,
|
||||
})
|
||||
} else {
|
||||
fmt.Println("验证码正确,删除redis中的验证码")
|
||||
config.RDC.Del(config.CTX, user.Tel)
|
||||
c.JSON(http.StatusOK, gin.H{"code": 200,
|
||||
"msg": "验证码正确",
|
||||
"data": nil,
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user