1. 支持转账、通话、链接消息的显示

2. 支持名片、视频号、QQ音乐、小程序、定位等消息的显示
3. 支持直播、游戏消息、语音通话、视频通话等消息的显示
4. 解密前判断对数据库是否有读权限
5. system消息html格式转文本
This commit is contained in:
HAL
2025-01-13 23:42:02 +08:00
parent f1a32a3f9a
commit c13e680b3d
18 changed files with 835 additions and 563 deletions
+80
View File
@@ -1,6 +1,8 @@
package utils
import (
"crypto/md5"
"encoding/hex"
"errors"
"fmt"
"io"
@@ -8,10 +10,12 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"github.com/pkg/browser"
"github.com/shirou/gopsutil/v3/disk"
"golang.org/x/net/html"
"golang.org/x/sys/windows/registry"
)
@@ -150,3 +154,79 @@ func CopyFile(src, dst string) (int64, error) {
return bytesWritten, nil
}
func extractTextFromHTML(htmlStr string) string {
doc, err := html.Parse(strings.NewReader(htmlStr))
if err != nil {
fmt.Println("Error parsing HTML:", err)
return ""
}
var extractText func(*html.Node) string
extractText = func(n *html.Node) string {
if n.Type == html.TextNode {
return n.Data
}
var text string
for c := n.FirstChild; c != nil; c = c.NextSibling {
text += extractText(c)
}
return text
}
return extractText(doc)
}
func removeCustomTags(input string) string {
re := regexp.MustCompile(`<(_wc_custom_link_)[^>]*?>`)
return re.ReplaceAllString(input, `$2`)
}
func Html2Text(htmlStr string) string {
if htmlStr[0] != '<' {
return htmlStr
}
text := extractTextFromHTML(htmlStr)
if strings.Contains(text, `<_wc_custom_link_`) {
text = "\U0001F9E7" + removeCustomTags(text)
}
return text
}
func HtmlMsgGetAttr(htmlStr, tag string) map[string]string {
doc, err := html.Parse(strings.NewReader(htmlStr))
if err != nil {
fmt.Println("Error parsing HTML:", err)
return nil
}
var attributes map[string]string
var findAttributes func(*html.Node)
findAttributes = func(n *html.Node) {
if n.Type == html.ElementNode && n.Data == tag {
attributes = make(map[string]string)
for _, attr := range n.Attr {
attributes[attr.Key] = attr.Val
}
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
findAttributes(c)
}
}
findAttributes(doc)
return attributes
}
func Hash256Sum(data []byte) string {
hash := md5.New()
hash.Write([]byte(data))
hashSum := hash.Sum(nil)
return hex.EncodeToString(hashSum)
}