浏览代码

微信修复

kobe6258 4 月之前
父节点
当前提交
420c6ebb48
共有 2 个文件被更改,包括 10 次插入7 次删除
  1. 9 5
      common/component/wechat/wechat_client.go
  2. 1 2
      common/utils/client/http_client.go

+ 9 - 5
common/component/wechat/wechat_client.go

@@ -15,7 +15,7 @@ import (
 )
 
 const (
-	baseURL = "https://api.weixin.qq.com"
+	baseURL = "https://api.weixin.qq.com1"
 	codeAPI = "/sns/jscode2session"
 )
 const (
@@ -92,14 +92,18 @@ func (cli *Client) Login(code string) (wxUser WxUser, err error) {
 	}
 	//请求微信接口
 	res, err := cli.client.Get(api)
-	defer func(Body io.ReadCloser) {
-		Body.Close()
-	}(res.Body)
 	if err != nil || res.StatusCode != 200 {
-		logger.Error("获取微信用户信息失败:%v", res.Status)
+		if res != nil {
+			logger.Error("获取微信用户信息失败:%v", res.Status)
+		} else {
+			logger.Error("获取微信用户信息失败:%v", err)
+		}
 		err = exception.New(exception.WeChatServerError)
 		return
 	}
+	defer func(Body io.ReadCloser) {
+		Body.Close()
+	}(res.Body)
 	var data loginResponse
 	err = json.NewDecoder(res.Body).Decode(&data)
 	if err != nil {

+ 1 - 2
common/utils/client/http_client.go

@@ -7,7 +7,6 @@ import (
 	logger "eta/eta_mini_ht_api/common/component/log"
 	"fmt"
 	"io"
-	"log"
 	"net/http"
 	"strings"
 	"time"
@@ -136,7 +135,7 @@ func (hc *HttpClient) PostWithAuth(url string, data interface{}, token string) (
 func (hc *HttpClient) Get(url string) (resp *http.Response, err error) {
 	req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
 	if err != nil {
-		log.Fatalf("创建请求失败: %v", err)
+		logger.Error("创建请求失败: %v", err)
 	}
 	resp, err = hc.DoWithRetry(req.Context(), req)
 	return