Bläddra i källkod

fix:token刷新逻辑

Roc 2 år sedan
förälder
incheckning
9a9939d56d
4 ändrade filer med 40 tillägg och 3 borttagningar
  1. 19 0
      controllers/wechat.go
  2. 9 0
      routers/commentsRouter.go
  3. 7 1
      services/wechat_send_msg.go
  4. 5 2
      services/wechat_send_msg_cygx.go

+ 19 - 0
controllers/wechat.go

@@ -59,3 +59,22 @@ func (this *WechatController) SendTemplateMsg() {
 	br.Msg = "推送成功"
 	return
 }
+
+// RefreshWxAccessToken
+// @Title 强制刷新token
+// @Description 推送模板消息
+// @Success 200 新增成功
+// @router /test/refresh [post]
+func (this *WechatController) RefreshWxAccessToken() {
+	br := new(models.BaseResponse).Init()
+
+	token,err,errMsg:=services.RefreshWxAccessToken()
+	br.Data = token
+	if err != nil{
+		br.Msg = errMsg
+		br.ErrMsg = err.Error()
+	}
+	br.Ret = 200
+	br.Msg = "推送成功"
+	return
+}

+ 9 - 0
routers/commentsRouter.go

@@ -34,4 +34,13 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_public_api/controllers:WechatController"] = append(beego.GlobalControllerRouter["hongze/hongze_public_api/controllers:WechatController"],
+        beego.ControllerComments{
+            Method: "RefreshWxAccessToken",
+            Router: `/test/refresh`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
 }

+ 7 - 1
services/wechat_send_msg.go

@@ -316,9 +316,15 @@ func getWxAccessToken()(accessToken string,err error,errMsg string){
 	return refreshWxAccessToken()
 }
 
+func RefreshWxAccessToken()(accessToken string,err error,errMsg string){
+	return refreshWxAccessToken()
+}
 // refreshWxAccessToken 强制刷新微信token
 func refreshWxAccessToken()(accessToken string,err error,errMsg string){
-	fmt.Println("强制刷新微信token")
+	fmt.Println("强制刷新"+utils.WxAppId+"微信token")
+	if errMsg !=``{
+		utils.FileLog.Info(fmt.Sprintf("强制刷新%s微信token异常:%s", utils.WxAppId,errMsg))
+	}
 	//调用微信官方接口获取新的accessToken
 	wxAccessToken, tmpErr := models.GetWxToken(utils.WxAppId, utils.WxAppSecret)
 	if tmpErr != nil {

+ 5 - 2
services/wechat_send_msg_cygx.go

@@ -219,7 +219,7 @@ func toSendTemplateMsgCygx(data []byte, resource string, sendType int, openId, u
 	return
 }
 
-// getWxAccessToken 获取微信token
+// getWxAccessTokenCygx 获取微信token
 func getWxAccessTokenCygx()(accessToken string,err error,errMsg string){
 	var tokenKey string
 	if utils.RunMode == "debug"{
@@ -238,7 +238,10 @@ func getWxAccessTokenCygx()(accessToken string,err error,errMsg string){
 
 // refreshWxAccessToken 强制刷新微信token
 func refreshWxAccessTokenCygx()(accessToken string,err error,errMsg string){
-	fmt.Println("强制刷新微信token")
+	fmt.Println("强制刷新"+utils.WxAppIdCygx+"微信token")
+	if errMsg !=``{
+		utils.FileLog.Info(fmt.Sprintf("强制刷新%s微信token异常:%s", utils.WxAppIdCygx,errMsg))
+	}
 	//调用微信官方接口获取新的accessToken
 	wxAccessToken, tmpErr := models.GetWxTokenCygx()
 	if tmpErr != nil {