diff --git a/middleware/student.go b/middleware/student.go index 63cd90b..0cc8d8d 100644 --- a/middleware/student.go +++ b/middleware/student.go @@ -7,7 +7,7 @@ import ( "io" "net/http" "testfb/config" - + "testfb/models" "github.com/gofiber/fiber/v2" "github.com/gofiber/storage/redis/v3" ) @@ -16,7 +16,14 @@ import ( func GetUserInfo(redisClient *redis.Storage) fiber.Handler { return func(c *fiber.Ctx) error { // 获取POST 请求参数 - nationalId := c.FormValue("nationalId") + apiUser models.APIUser + if err := c.BodyParser(&apiUser); err != nil { + return c.Status(http.StatusUnauthorized).JSON(fiber.Map{ + "message": "获取信息失败,参数错误", + "error": err.Error(), + }) + } + nationalId := apiUser.NationalId if nationalId == "" { return c.Status(http.StatusUnauthorized).JSON(fiber.Map{ "message": "获取信息失败,身份证不能为空", diff --git a/models/user.go b/models/user.go index 2fcb5b7..d81b62d 100644 --- a/models/user.go +++ b/models/user.go @@ -18,6 +18,14 @@ type User struct { UpdatedAt time.Time `json:"updated_at"` } +type ReqApi struct { + Code string `json:"code"` + Message string `json:"message"` + NationalId string `json:"nationalId"` + Phtone string `json:"phone"` + Token string `json:"token"` +} + func (u *User) BeforeCreate(tx *gorm.DB) error { hashedPassword, err := bcrypt.GenerateFromPassword([]byte(u.Password), bcrypt.DefaultCost) if err != nil {