This commit is contained in:
maxwell 2024-10-09 08:02:58 +08:00
parent 43f5b14de9
commit c8eedf5a8f

View File

@ -4,13 +4,14 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"testfb/config"
"testfb/models"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/storage/redis/v3"
"fmt"
)
// POST 根据身份证和token来获取家长或老师的基本信息
@ -58,6 +59,7 @@ func GetUserInfo(redisClient *redis.Storage) fiber.Handler {
// 解析返回的json数据判断是否有code字段并且code是否为1如果是则获取并返回token
var result map[string]interface{}
json.Unmarshal(body, &result)
fmt.Println(result)
if _, ok := result["code"]; !ok || result["code"] != 1 {
return c.Status(http.StatusUnauthorized).JSON(fiber.Map{
"message": "获取学生信息失败,身份证无效",
@ -234,7 +236,7 @@ func fetchTokenFromAPI(username, password string) (string, error) {
}
code := int(result["code"].(float64))
if code != 1 {
return "", errors.New("fetchTokenFromAPI:获取token失败,token无效,code:"+fmt.Sprintf("%d", code)+" message:"+result["message"].(string))
return "", errors.New("fetchTokenFromAPI:获取token失败,token无效,code:" + fmt.Sprintf("%d", code) + " message:" + result["message"].(string))
}
// 如果不存在result字段或result字段的值为空则token为空
if _, ok := result["result"]; !ok || result["result"] == "" {