Эх сурвалжийг харах

Merge branch 'feature/v1.2.7_wky' of moapp/MessageCenter into feature/v1.2.7

wangkaiyue 2 жил өмнө
parent
commit
affe1c73eb

+ 16 - 5
rpc/internal/common/sendWxTmplMsg.go

@@ -12,6 +12,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"net/url"
+	"regexp"
 	"strings"
 	"time"
 )
@@ -96,24 +97,34 @@ func (stm *WxTmplPush) SendMsg(link, title, detail, date string) error {
 	return nil
 }
 
+var (
+	regSpecial = regexp.MustCompile(`\\n|\\t|\\'|\\"|\n|\t|\'|\"`)
+)
+
 // getMessage 获取消息内容
 func (stm *WxTmplPush) getMessage(title, detail, date string) (map[string]*qrpc.TmplItem, error) {
 	var formatValue string = stm.Config.TmplValue
 	for _, key := range allMsgValueKeys {
 		switch key {
 		case "$class":
-			formatValue = strings.ReplaceAll(formatValue, key, stm.Config.Name)
+			formatValue = strings.ReplaceAll(formatValue, key, regSpecial.ReplaceAllString(stm.Config.Name, ""))
 		case "$title":
-			formatValue = strings.ReplaceAll(formatValue, key, title)
+			formatValue = strings.ReplaceAll(formatValue, key, regSpecial.ReplaceAllString(title, ""))
+
 		case "$detail":
-			formatValue = strings.ReplaceAll(formatValue, key, detail)
+			formatValue = strings.ReplaceAll(formatValue, key, regSpecial.ReplaceAllString(detail, ""))
+			fmt.Println("1", regSpecial.ReplaceAllString(detail, ""))
+			fmt.Println("2", regSpecial.ReplaceAllString("这是推送\\n信\\t息的\\n内容", ""))
+			fmt.Println("3", detail, "这是推送\\n信\\t息的\\n内容", detail == "这是推送\\n信\\t息的\\n内容")
+			fmt.Println(strings.ReplaceAll(formatValue, key, regSpecial.ReplaceAllString(detail, "")))
 		case "$date":
-			formatValue = strings.ReplaceAll(formatValue, key, date)
+			formatValue = strings.ReplaceAll(formatValue, key, regSpecial.ReplaceAllString(date, ""))
 		case "$note":
-			formatValue = strings.ReplaceAll(formatValue, key, config.ConfigJson.WxTmplConfig.CloseNotice)
+			formatValue = strings.ReplaceAll(formatValue, key, regSpecial.ReplaceAllString(config.ConfigJson.WxTmplConfig.CloseNotice, ""))
 		}
 	}
 	bValue := map[string]*qrpc.TmplItem{}
+	fmt.Println("formatValue", formatValue)
 	if err := json.Unmarshal([]byte(formatValue), &bValue); err != nil {
 		return nil, fmt.Errorf("格式化信息内容异常 %s", err.Error())
 	}