Merge pull request 'hotfix' (#67) from hotfix into main
All checks were successful
BuildImage / build-image (push) Successful in 1m31s

Reviewed-on: #67
This commit is contained in:
李寻欢 2024-07-05 09:17:03 +08:00
commit f396a7f674
4 changed files with 75 additions and 1 deletions

View File

@ -32,6 +32,39 @@ type systemMsgDataXml struct {
Type string `xml:"type,attr"`
}
// appMsgDataXml
// @description: 微信app消息的xml结构
type appMsgDataXml struct {
XMLName xml.Name `xml:"msg"`
Text string `xml:",chardata"`
AppMsg struct {
Text string `xml:",chardata"`
Appid string `xml:"appid,attr"`
SdkVer string `xml:"sdkver,attr"`
Title string `xml:"title"`
Des string `xml:"des"`
Action string `xml:"action"`
Type string `xml:"type"`
ShowType string `xml:"showtype"`
Content string `xml:"content"`
URL string `xml:"url"`
ThumbUrl string `xml:"thumburl"`
LowUrl string `xml:"lowurl"`
AppAttach struct {
Text string `xml:",chardata"`
TotalLen string `xml:"totallen"`
AttachId string `xml:"attachid"`
FileExt string `xml:"fileext"`
} `xml:"appattach"`
ExtInfo string `xml:"extinfo"`
} `xml:"appmsg"`
AppInfo struct {
Text string `xml:",chardata"`
Version string `xml:"version"`
AppName string `xml:"appname"`
} `xml:"appinfo"`
}
// atMsgDataXml
// @description: 微信@消息的xml结构
type atMsgDataXml struct {
@ -163,3 +196,20 @@ func (m Message) CleanContentStartWith(prefix string) bool {
return strings.HasPrefix(content, prefix)
}
// IsInvitationJoinGroup
// @description: 是否是邀请入群消息
// @receiver m
// @return bool 是否是邀请入群消息
// @return string 邀请入群消息内容
func (m Message) IsInvitationJoinGroup() (flag bool, str string) {
if m.Type == types.MsgTypeApp {
// 解析xml
var md appMsgDataXml
if err := xml.Unmarshal([]byte(m.Content), &md); err != nil {
return
}
return md.AppMsg.Type == "5" && strings.Contains(md.AppMsg.Content, "邀请你加入群聊"), md.AppMsg.Des
}
return
}

View File

@ -3,8 +3,10 @@ package mq
import (
"encoding/json"
"go-wechat/common/current"
"go-wechat/config"
"go-wechat/model"
"go-wechat/types"
"go-wechat/utils"
"log"
"strings"
)
@ -37,6 +39,16 @@ func parse(msg []byte) {
}
log.Printf("收到新微信消息\n消息来源: %s\n群成员: %s\n消息类型: %v\n消息内容: %s", m.FromUser, m.GroupUser, m.Type, m.Content)
// 如果是邀请进群,推送到配置的用户
if flag, dec := m.IsInvitationJoinGroup(); flag {
for _, user := range config.Conf.System.NewFriendNotify.ToUser {
if user != "" {
// 发送一条新消息
utils.SendMessage(user, "", dec, 0)
}
}
}
// 插件不为空,开始执行
if p := current.GetRobotMessageHandler(); p != nil {
p(&m)

View File

@ -24,7 +24,7 @@ func DailyNews() {
return
}
newsStr := fmt.Sprintf("#每日早报\n\n又是新的一天了让我们康康一觉醒来世界又发生了哪些变化~\n\n%s", strings.Join(news, "\n"))
newsStr := fmt.Sprintf("#每日早报\n\n又是新的一天了让我们康康一觉醒来世界又发生了哪些变化~\n\n%s", strings.Join(news, "\n \n"))
// 循环发送新闻
for _, group := range groups {

View File

@ -3,8 +3,10 @@ package tcpserver
import (
"encoding/json"
"go-wechat/common/current"
"go-wechat/config"
"go-wechat/model"
"go-wechat/types"
"go-wechat/utils"
"log"
"net"
"strings"
@ -38,6 +40,16 @@ func parse(remoteAddr net.Addr, msg []byte) {
}
log.Printf("%s\n消息来源: %s\n群成员: %s\n消息类型: %v\n消息内容: %s", remoteAddr, m.FromUser, m.GroupUser, m.Type, m.Content)
// 如果是邀请进群,推送到配置的用户
if flag, dec := m.IsInvitationJoinGroup(); flag {
for _, user := range config.Conf.System.NewFriendNotify.ToUser {
if user != "" {
// 发送一条新消息
utils.SendMessage(user, "", dec, 0)
}
}
}
// 插件不为空,开始执行
if p := current.GetRobotMessageHandler(); p != nil {
p(&m)