This commit is contained in:
macbook-maxwell 2024-10-08 20:43:41 +08:00
parent 7b2333e3a8
commit 4775c1aa5b

View File

@ -220,10 +220,11 @@ func fetchTokenFromAPI(username, password string) (string, error) {
fmt.Println(string(reqBodyJson))
returnValue, err := http.Post(url, "application/json", bytes.NewBuffer(reqBodyJson))
if err != nil {
return "", errors.New("获取token失败")
return "", errors.New("获取token失败,无法解析 token URL")
}
defer returnValue.Body.Close()
body, _ := io.ReadAll(returnValue.Body)
fmt.Println(string(body))
// 解析返回的json数据判断是否有code字段并且code是否为1如果是则获取并返回token
var result map[string]interface{}
json.Unmarshal(body, &result)