Sfoglia il codice sorgente

模板消息跳转

hsun 2 anni fa
parent
commit
fda3da1326
2 ha cambiato i file con 24 aggiunte e 10 eliminazioni
  1. 13 2
      services/wechat/template_msg.go
  2. 11 8
      services/wx_app/wx_app.go

+ 13 - 2
services/wechat/template_msg.go

@@ -295,6 +295,11 @@ func SendQuestionReplyWxMsg(questionId, userId int, questionTitle string) (err e
 	for i, v := range openIdList {
 		openIdArr[i] = v.OpenId
 	}
+	// 获取小程序配置
+	appConf, err := wx_app.GetWxAppConf()
+	if err != nil {
+		return
+	}
 
 	sendInfo := new(SendWxTemplate)
 	sendInfo.First = first
@@ -303,7 +308,7 @@ func SendQuestionReplyWxMsg(questionId, userId int, questionTitle string) (err e
 	sendInfo.Remark = remark
 	sendInfo.RedirectUrl = wxAppPath
 	sendInfo.TemplateId = TemplateIdWithCommunityQuestion
-	sendInfo.RedirectTarget = 1
+	sendInfo.RedirectTarget = appConf.MsgRedirectTarget
 	sendInfo.Resource = wxAppPath
 	sendInfo.SendType = utils.TEMPLATE_MSG_YB_COMMUNITY_QUESTION
 	sendInfo.OpenIdArr = openIdArr
@@ -369,6 +374,12 @@ func SendVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName string)
 		openIdArr[i] = v.OpenId
 	}
 
+	// 获取小程序配置
+	appConf, err := wx_app.GetWxAppConf()
+	if err != nil {
+		return
+	}
+
 	sendInfo := new(SendWxTemplate)
 	sendInfo.First = first
 	sendInfo.Keyword1 = keyword1
@@ -376,7 +387,7 @@ func SendVoiceBroadcastWxMsg(broadcastId int, sectionName, broadcastName string)
 	sendInfo.Remark = remark
 	sendInfo.RedirectUrl = wxAppPath
 	sendInfo.TemplateId = TemplateIdWithCommunityQuestion
-	sendInfo.RedirectTarget = 1
+	sendInfo.RedirectTarget = appConf.MsgRedirectTarget
 	sendInfo.Resource = wxAppPath
 	sendInfo.SendType = utils.TEMPLATE_MSG_YB_VOICE_BROADCAST
 	sendInfo.OpenIdArr = openIdArr

+ 11 - 8
services/wx_app/wx_app.go

@@ -113,10 +113,11 @@ func MsgSecCheck(openid string, content string) (result security.Result, err err
 }
 
 type WxAppConf struct {
-	WxId        string `description:"微信原始ID"`
-	WxAppId     string
-	WxAppSecret string
-	WxPlatform  int `description:"app来源: 6-研报小程序; 9-研报备用小程序"`
+	WxId              string `description:"微信原始ID"`
+	WxAppId           string
+	WxAppSecret       string
+	WxPlatform        int `description:"app来源: 6-研报小程序; 9-研报备用小程序"`
+	MsgRedirectTarget int `description:"公共模板消息跳转类型:1-研报小程序; 4-备用研报小程序"`
 }
 
 // GetWxAppConf 获取小程序配置
@@ -128,16 +129,18 @@ func GetWxAppConf() (appConf *WxAppConf, err error) {
 		return
 	}
 	appConf = &WxAppConf{
-		WxId:        `gh_75abb562a946`,
-		WxAppId:     `wxb059c872d79b9967`,
-		WxAppSecret: `1737c73e9f69a21de1a345b8f0800258`,
-		WxPlatform:  utils.USER_RECORD_PLATFORM_YB,
+		WxId:              `gh_75abb562a946`,
+		WxAppId:           `wxb059c872d79b9967`,
+		WxAppSecret:       `1737c73e9f69a21de1a345b8f0800258`,
+		WxPlatform:        utils.USER_RECORD_PLATFORM_YB,
+		MsgRedirectTarget: 1,
 	}
 	if conf.ConfigValue == "true" {
 		// 备用小程序
 		appConf.WxAppId = `wx9a2a9b49a00513a0`
 		appConf.WxAppSecret = `9feb793bd0a8756990a36ac2ade6978c`
 		appConf.WxPlatform = utils.USER_RECORD_PLATFORM_COPY_YB
+		appConf.MsgRedirectTarget = 4
 	}
 	return
 }