From 08bdda001a72f5fa4df1f563093afe93a038574f Mon Sep 17 00:00:00 2001 From: dhy <1452562016@qq.com> Date: Wed, 18 Dec 2024 21:01:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6dhy=E5=88=86=E6=94=AF?= =?UTF-8?q?=E5=86=85=E5=AE=B9=20=E4=BF=AE=E6=94=B9jwcode=E4=B8=BAint?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- link_homework/utility/utility.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/link_homework/utility/utility.go b/link_homework/utility/utility.go index 513bfc1..17fba55 100644 --- a/link_homework/utility/utility.go +++ b/link_homework/utility/utility.go @@ -60,11 +60,11 @@ func selectBaseUrl(hashKey string) *dto.Result { } // 获取 jwcode -func GetJwcodeJSON(token string) (string, error) { +func GetJwcodeJSON(token string) (int, error) { // 返回类型改为 int // 1. 获取基础 URL urlResult := getUrl(consts.URL_KEY, consts.URL_HASH_KEY) if urlResult.Code != 200 { - return "", errors.New("获取基础 URL 失败: " + urlResult.Message) + return 0, errors.New("获取基础 URL 失败: " + urlResult.Message) } baseUrl := urlResult.Data.(string) @@ -75,7 +75,7 @@ func GetJwcodeJSON(token string) (string, error) { // 3. 创建 HTTP 请求 req, err := http.NewRequest("POST", url, requestBody) if err != nil { - return "", fmt.Errorf("HTTP 请求创建失败: %v", err) + return 0, fmt.Errorf("HTTP 请求创建失败: %v", err) } req.Header.Set("Content-Type", "application/json") @@ -83,33 +83,33 @@ func GetJwcodeJSON(token string) (string, error) { client := &http.Client{} resp, err := client.Do(req) if err != nil { - return "", fmt.Errorf("HTTP 请求失败: %v", err) + return 0, fmt.Errorf("HTTP 请求失败: %v", err) } defer resp.Body.Close() // 5. 检查 HTTP 状态码 if resp.StatusCode != http.StatusOK { - return "", fmt.Errorf("HTTP 状态码错误: %v", resp.Status) + return 0, fmt.Errorf("HTTP 状态码错误: %v", resp.Status) } // 6. 读取并解析响应体 body, err := ioutil.ReadAll(resp.Body) if err != nil { - return "", fmt.Errorf("读取响应失败: %v", err) + return 0, fmt.Errorf("读取响应失败: %v", err) } // 7. 解析 JSON 数据 var jsonResponse map[string]interface{} if err = json.Unmarshal(body, &jsonResponse); err != nil { - return "", fmt.Errorf("解析 JSON 失败: %v", err) + return 0, fmt.Errorf("解析 JSON 失败: %v", err) } // 8. 提取并直接返回 jwcode if data, ok := jsonResponse["data"].(map[string]interface{}); ok { - if jwcode, exists := data["jwcode"].(string); exists { - return jwcode, nil // 直接返回 jwcode + if jwcode, exists := data["jwcode"].(float64); exists { // 确保将 jwcode 作为数字解析 + return int(jwcode), nil // 转换为整数并返回 } } - return "", errors.New("响应体中没有 jwcode") + return 0, errors.New("响应体中没有 jwcode") }