update
This commit is contained in:
parent
5686596a00
commit
6ba71baf1f
5
main.go
5
main.go
@ -55,7 +55,10 @@ func main() {
|
||||
app.Get("/user", middleware.AuthMiddleware(redisClient), handlers.GetCurrentUser(db))
|
||||
app.Put("/user", middleware.AuthMiddleware(redisClient), handlers.UpdateCurrentUser(db))
|
||||
app.Get("/users/:id", middleware.AuthMiddleware(redisClient), handlers.GetUserByID(db))
|
||||
app.Post("/getuser", middleware.GetUserInfo(true, redisClient))
|
||||
app.Post("/getuser", middleware.GetUserInfo(false, redisClient))
|
||||
app.Post("/getstudent", middleware.GetUserInfo(true, redisClient))
|
||||
app.Post("/getstudentsbynumber", middleware.GetStudentInfoByParent(redisClient))
|
||||
|
||||
// Start server
|
||||
log.Fatal(app.Listen(":7777"))
|
||||
}
|
||||
|
||||
@ -78,9 +78,16 @@ func GetUserInfo(isStudent bool, redisClient *redis.Storage) fiber.Handler {
|
||||
func GetStudentInfoByParent(redisClient *redis.Storage) fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
// 获取POST 请求参数
|
||||
nationalId := c.Params("nationalId")
|
||||
mobile := c.Params("mobile")
|
||||
if nationalId == "" && mobile == "" {
|
||||
var apiUser models.ReqApi
|
||||
if err := c.BodyParser(&apiUser); err != nil {
|
||||
return c.Status(http.StatusUnauthorized).JSON(fiber.Map{
|
||||
"message": "获取信息失败,参数错误",
|
||||
"error": err.Error(),
|
||||
})
|
||||
}
|
||||
nationalId := apiUser.NationalId
|
||||
phone := apiUser.Phone
|
||||
if nationalId == "" && phone == "" {
|
||||
return c.Status(http.StatusUnauthorized).JSON(fiber.Map{
|
||||
"message": "获取学生信息失败,身份证或手机号不能为空",
|
||||
"error": "身份证或手机号不能为空",
|
||||
@ -97,21 +104,10 @@ func GetStudentInfoByParent(redisClient *redis.Storage) fiber.Handler {
|
||||
// 验证身份证有效性
|
||||
url := cfg.APIParentUrl
|
||||
var reqBody map[string]string
|
||||
if nationalId != "" {
|
||||
reqBody = map[string]string{
|
||||
"token": token,
|
||||
"nationalId": nationalId,
|
||||
}
|
||||
} else if mobile != "" {
|
||||
reqBody = map[string]string{
|
||||
"token": token,
|
||||
"mobile": mobile,
|
||||
}
|
||||
} else {
|
||||
return c.Status(http.StatusUnauthorized).JSON(fiber.Map{
|
||||
"message": "获取学生信息失败,身份证或手机号不能为空",
|
||||
"error": "身份证或手机号不能为空",
|
||||
})
|
||||
"phone": phone,
|
||||
}
|
||||
reqBodyJson, _ := json.Marshal(reqBody)
|
||||
req, err := http.Post(url, "application/json", bytes.NewBuffer(reqBodyJson))
|
||||
@ -126,7 +122,7 @@ func GetStudentInfoByParent(redisClient *redis.Storage) fiber.Handler {
|
||||
// 解析返回的json数据,判断是否有code字段并且code是否为1,如果是,则获取并返回token
|
||||
var result map[string]interface{}
|
||||
json.Unmarshal(body, &result)
|
||||
if _, ok := result["code"]; !ok || result["code"] != 1 {
|
||||
if _, ok := result["code"]; !ok || int(result["code"].(float64)) != 1 {
|
||||
return c.Status(http.StatusUnauthorized).JSON(fiber.Map{
|
||||
"message": "获取学生信息失败,身份证或手机号无效",
|
||||
"error": "身份证或手机号无效",
|
||||
|
||||
@ -22,7 +22,7 @@ type ReqApi struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
NationalId string `json:"nationalId"`
|
||||
Phtone string `json:"phone"`
|
||||
Phone string `json:"phone"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user