Parcourir la source

新增微信emoji

dcsunny il y a 3 ans
Parent
commit
0f6e984cf8
1 fichiers modifiés avec 15 ajouts et 0 suppressions
  1. 15 0
      common/emoji.go

+ 15 - 0
common/emoji.go

@@ -9,3 +9,18 @@ var WxEmojiMap = make(map[string]string)
 func init() {
 	json.Unmarshal([]byte(wxEmojiStr), &WxEmojiMap)
 }
+
+func EmojiConvert(str string) string {
+	arr := []rune(str)
+
+	text := ""
+	for _, _v := range arr {
+		v := string(_v)
+		if _, ok := WxEmojiMap[v]; ok {
+			text = text + WxEmojiMap[v]
+		} else {
+			text = text + v
+		}
+	}
+	return text
+}