update
This commit is contained in:
parent
43f5b14de9
commit
c8eedf5a8f
@ -4,13 +4,14 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testfb/config"
|
"testfb/config"
|
||||||
"testfb/models"
|
"testfb/models"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/storage/redis/v3"
|
"github.com/gofiber/storage/redis/v3"
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// POST 根据身份证和token,来获取家长或老师的基本信息
|
// POST 根据身份证和token,来获取家长或老师的基本信息
|
||||||
@ -58,6 +59,7 @@ func GetUserInfo(redisClient *redis.Storage) fiber.Handler {
|
|||||||
// 解析返回的json数据,判断是否有code字段并且code是否为1,如果是,则获取并返回token
|
// 解析返回的json数据,判断是否有code字段并且code是否为1,如果是,则获取并返回token
|
||||||
var result map[string]interface{}
|
var result map[string]interface{}
|
||||||
json.Unmarshal(body, &result)
|
json.Unmarshal(body, &result)
|
||||||
|
fmt.Println(result)
|
||||||
if _, ok := result["code"]; !ok || result["code"] != 1 {
|
if _, ok := result["code"]; !ok || result["code"] != 1 {
|
||||||
return c.Status(http.StatusUnauthorized).JSON(fiber.Map{
|
return c.Status(http.StatusUnauthorized).JSON(fiber.Map{
|
||||||
"message": "获取学生信息失败,身份证无效",
|
"message": "获取学生信息失败,身份证无效",
|
||||||
@ -213,7 +215,7 @@ func fetchTokenFromAPI(username, password string) (string, error) {
|
|||||||
|
|
||||||
url := cfg.APITokenUrl
|
url := cfg.APITokenUrl
|
||||||
reqBody := map[string]string{
|
reqBody := map[string]string{
|
||||||
"name": username,
|
"name": username,
|
||||||
"password": password,
|
"password": password,
|
||||||
}
|
}
|
||||||
reqBodyJson, _ := json.Marshal(reqBody)
|
reqBodyJson, _ := json.Marshal(reqBody)
|
||||||
@ -234,7 +236,7 @@ func fetchTokenFromAPI(username, password string) (string, error) {
|
|||||||
}
|
}
|
||||||
code := int(result["code"].(float64))
|
code := int(result["code"].(float64))
|
||||||
if code != 1 {
|
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为空
|
// 如果不存在result字段,或result字段的值为空,则token为空
|
||||||
if _, ok := result["result"]; !ok || result["result"] == "" {
|
if _, ok := result["result"]; !ok || result["result"] == "" {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user