Browse Source

wip:清除html标签

wangshan 8 tháng trước cách đây
mục cha
commit
2617ed621d

+ 21 - 14
src/jfw/modules/weixin/src/wx/reply.go

@@ -55,20 +55,8 @@ WHERE
 		switch reply_type {
 		case ReplyContentTEXT:
 			//编码及换行处理
-			title = html.UnescapeString(title)
-			title = strings.ReplaceAll(strings.ReplaceAll(title, "<br />", "\n"), "\\n", "\n")
-			// 移除a标签中 title
-			reTitle, _ := regexp.Compile("title=\"[^\"]*\"")
-			title = reTitle.ReplaceAllString(title, "")
-			// 使用正则表达式匹配HTML标签
-			re, err := regexp.Compile("\\<[^a]+?\\>")
-			if err != nil {
-				fmt.Println("Error compiling regex:", err)
-			} else {
-				log.Println("---1---:", title)
-				// 使用正则表达式的ReplaceAllString函数移除HTML标签
-				title = re.ReplaceAllString(title, "")
-				log.Println("---2---:", title)
+			title = ClearHtml(title)
+			if title != "" {
 				err := w.PostText(title)
 				if err != nil {
 					log.Println("文字 发送失败", err)
@@ -123,3 +111,22 @@ WHERE
 	}
 	return true
 }
+
+func ClearHtml(text string) string {
+	//编码及换行处理
+	text = html.UnescapeString(text)
+	text = strings.ReplaceAll(strings.ReplaceAll(text, "<br />", "\n"), "\\n", "\n")
+	// 移除a标签中 title
+	reTitle, _ := regexp.Compile("title=\"[^\"]*\"")
+	text = reTitle.ReplaceAllString(text, "")
+	// 使用正则表达式匹配HTML标签
+	re, err := regexp.Compile("\\<[^a]+?\\>")
+	if err != nil {
+		fmt.Println("Error compiling regex:", err)
+		return ""
+	} else {
+		// 使用正则表达式的ReplaceAllString函数移除HTML标签
+		text = re.ReplaceAllString(text, "")
+	}
+	return text
+}

+ 1 - 2
src/jfw/modules/weixin/src/wx/scanReplayStream.go

@@ -26,8 +26,6 @@ const (
 // action 1:关注 2:扫码
 func ScanReplayStream(w ResponseWriter, openId, code string, action int) error {
 	var arr = tools.QRCodeContent(code)
-	if len(arr) > 0 {
-	}
 	for _, task := range arr {
 		//校验类型
 		if !(task.Action == 0 || task.Action == action) {
@@ -59,6 +57,7 @@ func ScanReplayStream(w ResponseWriter, openId, code string, action int) error {
 				sendErr = w.PostImage(mid)
 			}
 		case "TEXT":
+			task.Title = ClearHtml(task.Title)
 			if task.Title != "" {
 				sendErr = w.PostText(task.Title)
 			}