Преглед изворни кода

Merge branch 'feature/fix_wx_token' into debug

xyxie пре 1 година
родитељ
комит
a1348747bd
1 измењених фајлова са 13 додато и 5 уклоњено
  1. 13 5
      services/wechat/token.go

+ 13 - 5
services/wechat/token.go

@@ -4,7 +4,6 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
-	"hongze/hongze_api/models"
 	"hongze/hongze_api/services/alarm_msg"
 	"hongze/hongze_api/utils"
 	"io/ioutil"
@@ -12,12 +11,22 @@ import (
 	"strings"
 )
 
+type WxTokenResp struct {
+	Ret         int
+	Msg         string
+	ErrMsg      string
+	ErrCode     string
+	Data        WxTokenData
+	Success     bool `description:"true 执行成功,false 执行失败"`
+	IsSendEmail bool `json:"-"`
+}
+
 type WxTokenReq struct {
 	WxAppId     string `description:"公众号appId"`
 	WxAppSecret string `description:"公众号appSecret"`
 }
 
-type WxTokenResp struct {
+type WxTokenData struct {
 	AccessToken string `description:"微信token"`
 }
 
@@ -59,7 +68,7 @@ func GetAccessToken(tokenReq WxTokenReq) (accessToken string, err error, errMsg
 		errMsg = "ioutil.ReadAll Err:" + err.Error()
 		return
 	}
-	result := new(models.BaseResponse)
+	result := new(WxTokenResp)
 	err = json.Unmarshal(b, &result)
 	if err != nil {
 		errMsg = "json.Unmarshal Err:" + err.Error()
@@ -70,8 +79,7 @@ func GetAccessToken(tokenReq WxTokenReq) (accessToken string, err error, errMsg
 		errMsg = "请求失败:" + err.Error()
 		return
 	}
-	data := result.Data.(WxTokenResp)
-	accessToken = data.AccessToken
+	accessToken = result.Data.AccessToken
 	if accessToken == "" {
 		err = errors.New("请求accessToken失败")
 		errMsg = "请求accessToken失败"