# Conflicts: # utils/common.go
@@ -296,6 +296,7 @@ func SendCommentWxCategoryTemplateMsg(req models.AddCygxArticleCommentReq, user
keyword3 = companyItem.SellerName
keyword4 = time.Now().Format(utils.FormatDateTimeMinute2)
keyword5 = "报告留言:" + req.Content
+ keyword5 = utils.TruncateActivityNameString(keyword5)
keywords = append(keywords, keyword1, keyword2, keyword3, keyword4, keyword5)
if articleInfo.ArticleTypeId > 0 {
@@ -982,3 +982,25 @@ func GetArabicNumbers(str string) string {
}
return string(numbers)
+
+// 处理活动名称
+func TruncateActivityNameString(s string) string {
+ // 计算字符串总字数(按汉字、数字、字母和特殊符号计算)
+ totalCharCount := utf8.RuneCountInString(s)
+ // 如果总字数不超过18,则直接返回整个字符串
+ if totalCharCount <= 18 {
+ return s
+ }
+ // 计算前15个汉字所需的字节位置
+ hanziCount := 0
+ byteIndex := 0
+ for byteIndex < len(s) && hanziCount < 15 {
+ r, size := utf8.DecodeRuneInString(s[byteIndex:])
+ if r != utf8.RuneError {
+ hanziCount++
+ byteIndex += size
+ // 截取前15个汉字,并添加省略号
+ return s[:byteIndex] + "…"
+}