2026-02-17 13:06:23 +08:00
|
|
|
|
package wxrouter
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"bytes"
|
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
"encoding/xml"
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
"regexp"
|
|
|
|
|
|
"strconv"
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
"time"
|
|
|
|
|
|
"xiawan/wx/api/req"
|
|
|
|
|
|
"xiawan/wx/clientsdk"
|
|
|
|
|
|
"xiawan/wx/clientsdk/baseinfo"
|
|
|
|
|
|
"xiawan/wx/clientsdk/baseutils"
|
|
|
|
|
|
"xiawan/wx/db"
|
|
|
|
|
|
"xiawan/wx/db/table"
|
|
|
|
|
|
"xiawan/wx/protobuf/wechat"
|
|
|
|
|
|
"xiawan/wx/srv/srvconfig"
|
|
|
|
|
|
"xiawan/wx/srv/wxcore"
|
|
|
|
|
|
"xiawan/wx/srv/wxface"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// WXNewSyncRouter 获取二维码响应路由
|
|
|
|
|
|
type WXNewSyncRouter struct {
|
|
|
|
|
|
wxcore.WXBaseRouter
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Handle 处理conn业务的方法
|
|
|
|
|
|
func (hbr *WXNewSyncRouter) Handle(wxResp wxface.IWXResponse) error {
|
|
|
|
|
|
defer wxcore.TryE("WXNewSyncRouter Handle")
|
|
|
|
|
|
currentWXConn := wxResp.GetWXConncet()
|
|
|
|
|
|
currentWXAccount := currentWXConn.GetWXAccount()
|
|
|
|
|
|
currentUserInfo := currentWXAccount.GetUserInfo()
|
|
|
|
|
|
currentWXCache := currentWXConn.GetWXCache()
|
|
|
|
|
|
currentSyncMgr := currentWXConn.GetWXSyncMgr()
|
|
|
|
|
|
isServerRestart := currentWXAccount.GetUserInfo().GetIsServerRestart()
|
|
|
|
|
|
|
|
|
|
|
|
currentTaskMgr := currentWXConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
if !taskMgr.GetTaskStatus() {
|
|
|
|
|
|
taskMgr.Start()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 同步响应
|
|
|
|
|
|
var syncResp wechat.NewSyncResponse
|
|
|
|
|
|
err := clientsdk.ParseResponseData(currentUserInfo, wxResp.GetPackHeader(), &syncResp)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
// 请求出问题了,判断是否掉线,并重连
|
|
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
|
go currentWXConn.CheckOnLineStatusLogin()
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 异步执行,不影响消息同步
|
|
|
|
|
|
// 跟新同步 Key
|
|
|
|
|
|
syncKey := syncResp.GetKeyBuf().GetBuffer()
|
|
|
|
|
|
|
|
|
|
|
|
//保存SyncKey
|
|
|
|
|
|
if len(currentUserInfo.SyncKey) <= 0 || !bytes.Equal(currentUserInfo.SyncKey, syncResp.GetKeyBuf().GetBuffer()) {
|
|
|
|
|
|
currentUserInfo.SyncKey = syncKey
|
|
|
|
|
|
db.UpdateUserInfo(currentUserInfo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果没有同步到数据则返回bInitNewSyncFinished
|
|
|
|
|
|
cmdList := syncResp.GetCmdList()
|
|
|
|
|
|
syncCount := cmdList.GetCount()
|
2026-02-26 10:44:13 +08:00
|
|
|
|
continueFlag := syncResp.GetContinueFlag()
|
2026-02-17 13:06:23 +08:00
|
|
|
|
//log.Info(syncResp.GetContinueFlag(), syncCount)
|
|
|
|
|
|
//redis 发布结构体
|
|
|
|
|
|
messageResp := new(table.SyncMessageResponse)
|
|
|
|
|
|
// 遍历同步的信息和群
|
|
|
|
|
|
itemList := cmdList.GetItemList()
|
|
|
|
|
|
for index := uint32(0); index < syncCount; index++ {
|
|
|
|
|
|
item := itemList[index]
|
|
|
|
|
|
itemID := item.GetCmdId()
|
|
|
|
|
|
|
|
|
|
|
|
// 同步到消息
|
|
|
|
|
|
if itemID == baseinfo.CmdIDAddMsg {
|
|
|
|
|
|
// 初始化阶段跳过处理历史消息
|
|
|
|
|
|
if !currentWXCache.IsInitNewSyncFinished() {
|
|
|
|
|
|
// fmt.Println("跳过历史消息推送 - IsInitNewSyncFinished=false")
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
// fmt.Println("处理消息 - IsInitNewSyncFinished=true")
|
|
|
|
|
|
addMsg := &wechat.AddMsg{}
|
|
|
|
|
|
err := proto.Unmarshal(item.CmdBuf.Data, addMsg)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
baseutils.PrintLog(err.Error())
|
|
|
|
|
|
continue
|
|
|
|
|
|
}
|
|
|
|
|
|
// 消息同步xiaoyue命令
|
|
|
|
|
|
// fmt.Println("xiaoyue命令-------new")
|
|
|
|
|
|
go dealAddMsgRun(currentWXConn, addMsg, "new")
|
|
|
|
|
|
|
|
|
|
|
|
// ws 同步消息 - 使用任务的WebSocket状态
|
|
|
|
|
|
socketMsgTask := taskMgr.SocketMsgTask
|
|
|
|
|
|
if socketMsgTask.IsWebSocketEnabled() {
|
|
|
|
|
|
go socketMsgTask.AddMsgItem(addMsg)
|
|
|
|
|
|
}
|
|
|
|
|
|
// 重启服务 不判断过期时间和禁用
|
|
|
|
|
|
if !isServerRestart {
|
|
|
|
|
|
go dealAuth(currentWXConn)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 同步到联系人
|
|
|
|
|
|
if itemID == baseinfo.CmdIDModContact {
|
|
|
|
|
|
// 完全禁用联系人的 WebSocket 推送(等待有缘的老板来做定制)
|
|
|
|
|
|
fmt.Println("跳过所有联系人同步推送(包括历史和实时)")
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
// 如果将来需要启用实时联系人推送,使用下面的逻辑:
|
|
|
|
|
|
// if !currentWXCache.IsInitNewSyncFinished() {
|
|
|
|
|
|
// fmt.Println("跳过历史联系人同步 - IsInitNewSyncFinished=false")
|
|
|
|
|
|
// continue
|
|
|
|
|
|
// }
|
|
|
|
|
|
// contact := new(wechat.ModContact)
|
|
|
|
|
|
// err := proto.Unmarshal(item.GetCmdBuf().GetData(), contact)
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
// continue
|
|
|
|
|
|
// }
|
|
|
|
|
|
// fmt.Println("ModContact", contact)
|
|
|
|
|
|
// dealModContact(currentWXConn, contact)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果开启了http消息同步就推送到redis
|
|
|
|
|
|
// fmt.Println("httpSyncMsg", srvconfig.GlobalSetting.HttpSyncMsg)
|
|
|
|
|
|
if srvconfig.GlobalSetting.HttpSyncMsg {
|
|
|
|
|
|
messageResp.SetMessage(item.GetCmdBuf().GetData(), int32(itemID))
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断消息初始化完成
|
2026-02-26 10:44:13 +08:00
|
|
|
|
if continueFlag <= 0 || syncCount <= 0 {
|
2026-02-17 13:06:23 +08:00
|
|
|
|
if !currentWXCache.IsInitNewSyncFinished() {
|
|
|
|
|
|
currentWXCache.SetInitNewSyncFinished(true)
|
2026-02-26 10:44:13 +08:00
|
|
|
|
fmt.Println("[回调修复] 历史消息同步完成,自动激活回调功能")
|
2026-02-17 13:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 发布同步信息消息
|
|
|
|
|
|
// 每次服务重启, 已登录的微信号 都会执行到这一步来同步消息;
|
|
|
|
|
|
// 未登录的微信在登录后, 也会在 wxnewinit.go 文件内进行【发布同步信息消息】操作
|
|
|
|
|
|
//log.Info("发布同步信息消息", currentUserInfo.NickName+"-->发布同步信息消息{}-"+currentUserInfo.GetUserName())
|
|
|
|
|
|
if srvconfig.GlobalSetting.HttpSyncMsg {
|
|
|
|
|
|
go db.PublishSyncMsgWxMessage(currentWXAccount, *messageResp)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果数量超过10条则继续同步
|
|
|
|
|
|
if !currentWXCache.IsInitNewSyncFinished() {
|
|
|
|
|
|
currentSyncMgr.SendNewSyncRequest()
|
|
|
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dealModContact 处理同步到的联系人信息
|
|
|
|
|
|
func dealModContact(wxConn wxface.IWXConnect, modContact *wechat.ModContact) {
|
|
|
|
|
|
currentWXAccount := wxConn.GetWXAccount()
|
|
|
|
|
|
userName := modContact.GetUserName().GetStr()
|
|
|
|
|
|
uuid := currentWXAccount.GetUserInfo().UUID
|
|
|
|
|
|
|
|
|
|
|
|
// 发送联系人回调
|
|
|
|
|
|
go sendContactCallback(wxConn, modContact, uuid)
|
|
|
|
|
|
|
|
|
|
|
|
// 处理群
|
|
|
|
|
|
if strings.HasSuffix(userName, "@chatroom") {
|
|
|
|
|
|
memberCount := modContact.GetNewChatroomData().GetMemberCount()
|
|
|
|
|
|
if memberCount <= 0 {
|
|
|
|
|
|
// 被移除群聊
|
|
|
|
|
|
// currentWXAccount.RemoveWXGroup(userName)
|
|
|
|
|
|
db.DeleteContact(userName, uuid)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 新增群聊
|
|
|
|
|
|
// currentWXAccount.AddWXGroup(modContact)
|
|
|
|
|
|
db.SaveOrUpdateContact(modContact, uuid)
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 公众号
|
|
|
|
|
|
hasExternalInfo := false
|
|
|
|
|
|
if len(modContact.GetCustomizedInfo().GetExternalInfo()) > 0 {
|
|
|
|
|
|
hasExternalInfo = true
|
|
|
|
|
|
}
|
|
|
|
|
|
if strings.HasPrefix(userName, "gh_") || hasExternalInfo {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 好友
|
|
|
|
|
|
// currentWXAccount.AddWXFriendContact(modContact)
|
|
|
|
|
|
db.SaveOrUpdateContact(modContact, uuid)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// sendContactCallback 发送联系人回调
|
|
|
|
|
|
// decodeUnicodeEscapes 解码Unicode转义字符
|
|
|
|
|
|
func decodeUnicodeEscapes(s string) string {
|
|
|
|
|
|
// 处理JSON中的Unicode转义字符,如\u003c
|
|
|
|
|
|
re := regexp.MustCompile(`\\u([0-9a-fA-F]{4})`)
|
|
|
|
|
|
result := re.ReplaceAllStringFunc(s, func(match string) string {
|
|
|
|
|
|
// 提取十六进制数字部分
|
|
|
|
|
|
hexStr := match[2:] // 去掉\u前缀
|
|
|
|
|
|
// 将十六进制转换为整数
|
|
|
|
|
|
if codePoint, err := strconv.ParseInt(hexStr, 16, 32); err == nil {
|
|
|
|
|
|
// 转换为Unicode字符
|
|
|
|
|
|
return string(rune(codePoint))
|
|
|
|
|
|
}
|
|
|
|
|
|
return match // 如果转换失败,返回原字符串
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func sendContactCallback(wxConn wxface.IWXConnect, modContact *wechat.ModContact, uuid string) {
|
|
|
|
|
|
// 将contact转换为JSON格式
|
|
|
|
|
|
contactJSON, err := json.Marshal(modContact)
|
|
|
|
|
|
fmt.Println("contactJSON", string(contactJSON))
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Printf("联系人数据序列化失败: %v\n", err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 构建回调数据
|
|
|
|
|
|
callbackData := map[string]interface{}{
|
|
|
|
|
|
"type": "contact_sync",
|
|
|
|
|
|
"uuid": uuid,
|
|
|
|
|
|
"timestamp": time.Now().Unix(),
|
|
|
|
|
|
"contact_data": string(contactJSON),
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 转换为JSON
|
|
|
|
|
|
// callbackJSON, err := json.Marshal(callbackData)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Printf("回调数据序列化失败: %v\n", err)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解码Unicode转义字符并打印联系人回调数据
|
|
|
|
|
|
// decodedJSON := decodeUnicodeEscapes(string(callbackJSON))
|
|
|
|
|
|
// fmt.Printf("联系人回调数据: %s\n", decodedJSON)
|
|
|
|
|
|
|
|
|
|
|
|
// 发送HTTP回调 - 创建临时AddMsg来复用现有回调机制
|
|
|
|
|
|
contactDataStr := callbackData["contact_data"].(string)
|
|
|
|
|
|
// 对content内容进行Unicode解码
|
|
|
|
|
|
decodedContactData := decodeUnicodeEscapes(contactDataStr)
|
|
|
|
|
|
tempAddMsg := &wechat.AddMsg{
|
|
|
|
|
|
Content: &wechat.SKBuiltinString{Str: proto.String(decodedContactData)},
|
|
|
|
|
|
MsgType: proto.Uint32(10000), // 自定义消息类型表示联系人同步
|
|
|
|
|
|
FromUserName: &wechat.SKBuiltinString{Str: proto.String(uuid)},
|
|
|
|
|
|
ToUserName: &wechat.SKBuiltinString{Str: proto.String(uuid)},
|
|
|
|
|
|
CreateTime: proto.Uint32(uint32(time.Now().Unix())),
|
|
|
|
|
|
NewMsgId: proto.Int64(time.Now().UnixNano()),
|
|
|
|
|
|
}
|
|
|
|
|
|
go db.SendMessageCallback(tempAddMsg, uuid)
|
|
|
|
|
|
|
|
|
|
|
|
// 发送到WebSocket
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, ok := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
if ok {
|
|
|
|
|
|
socketMsgTask := taskMgr.SocketMsgTask
|
|
|
|
|
|
if socketMsgTask.IsWebSocketEnabled() {
|
|
|
|
|
|
go socketMsgTask.AddMsgItem(tempAddMsg)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 并发处理
|
|
|
|
|
|
func dealAddMsgRun(wxConn wxface.IWXConnect, addMsg *wechat.AddMsg, syncType string) {
|
|
|
|
|
|
// fmt.Println("xiaoyue命令-------dealAddMsgRun并发处理")
|
|
|
|
|
|
msgType := addMsg.GetMsgType()
|
|
|
|
|
|
msgContent := addMsg.GetContent().GetStr()
|
|
|
|
|
|
fromUserName := addMsg.GetFromUserName().GetStr()
|
|
|
|
|
|
toUserName := addMsg.GetToUserName().GetStr()
|
|
|
|
|
|
|
|
|
|
|
|
// beAtUser := addMsg.GetBeAtUser()
|
|
|
|
|
|
|
|
|
|
|
|
// 获取UUID用于消息回调
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
|
|
|
|
|
|
// 添加消息回调处理
|
|
|
|
|
|
go db.SendMessageCallback(addMsg, uuid)
|
|
|
|
|
|
|
|
|
|
|
|
// wxAccount := wxConn.GetWXAccount()
|
|
|
|
|
|
// beAtUser := addMsg.GetBeAtUser()
|
|
|
|
|
|
groupWXID := ""
|
|
|
|
|
|
toGroupWXID := ""
|
|
|
|
|
|
if strings.HasSuffix(toUserName, "@chatroom") {
|
|
|
|
|
|
groupWXID = toUserName
|
|
|
|
|
|
toGroupWXID = toUserName
|
|
|
|
|
|
}
|
|
|
|
|
|
if strings.HasSuffix(fromUserName, "@chatroom") {
|
|
|
|
|
|
groupWXID = fromUserName
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断 是否是群红包 @chatroom - @chatroom
|
|
|
|
|
|
// fmt.Print("\n" + strconv.FormatUint(uint64(msgType), 10) + "\n")
|
|
|
|
|
|
// if msgType == baseinfo.MMAddMsgTypeRefer {
|
|
|
|
|
|
// // if msgType == baseinfo.MMAddMsgTypeRefer || msgType == baseinfo.MMPayInfoSceneIDHongBao2 {
|
|
|
|
|
|
// if msgType == baseinfo.MMPayInfoSceneIDHongBao2 {
|
|
|
|
|
|
// // 处理红包
|
|
|
|
|
|
// tmpMsg := new(baseinfo.RedSysMsg)
|
|
|
|
|
|
// err := xml.Unmarshal([]byte(msgContent), tmpMsg)
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // url 解码
|
|
|
|
|
|
// // msgContent, _ = url.QueryUnescape(tmpMsg.Paymsg.AppMsgContent)
|
|
|
|
|
|
// // msgContent = tmpMsg.Paymsg.AppMsgContent
|
|
|
|
|
|
// // fmt.Print(msgContent)
|
|
|
|
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // fmt.Print(msgContent)
|
|
|
|
|
|
// if strings.HasSuffix(toUserName, "@chatroom") {
|
|
|
|
|
|
// // 红包处理
|
|
|
|
|
|
// dealGroupHB(wxConn, msgContent, toUserName)
|
|
|
|
|
|
// } else if strings.HasSuffix(fromUserName, "@chatroom") {
|
|
|
|
|
|
// // 红包处理
|
|
|
|
|
|
// dealGroupHB(wxConn, msgContent, fromUserName)
|
2026-02-26 10:44:13 +08:00
|
|
|
|
// // // 群转账给我处理
|
|
|
|
|
|
// // if toUserName == wxAccount.GetUserInfo().GetUserName() {
|
|
|
|
|
|
// // dealAutoTransfer(wxConn, msgContent, fromUserName)
|
|
|
|
|
|
// // }
|
2026-02-17 13:06:23 +08:00
|
|
|
|
// } else {
|
|
|
|
|
|
// // 判断是个人红包
|
|
|
|
|
|
// dealPersonHB(wxConn, msgContent, fromUserName)
|
2026-02-26 10:44:13 +08:00
|
|
|
|
// // // 个人转账处理
|
|
|
|
|
|
// // if toUserName == wxAccount.GetUserInfo().GetUserName() {
|
|
|
|
|
|
// // dealAutoTransfer(wxConn, msgContent, fromUserName)
|
|
|
|
|
|
// // }
|
2026-02-17 13:06:23 +08:00
|
|
|
|
// // 邀请入群处理
|
|
|
|
|
|
// // 创建一个数组,用于存储命令
|
2026-02-26 10:44:13 +08:00
|
|
|
|
// // newMsgId := strconv.FormatUint(uint64(addMsg.GetNewMsgId()), 10)
|
|
|
|
|
|
// // dealAutoJoinGroup(wxConn, msgContent, newMsgId)
|
2026-02-17 13:06:23 +08:00
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// 判断是否是命令
|
|
|
|
|
|
// if toUserName == baseinfo.FileHelperWXID {
|
|
|
|
|
|
// // 处理命令
|
|
|
|
|
|
// // if msgType == baseinfo.MMAddMsgTypeText {
|
|
|
|
|
|
// // dealCommand(wxConn, msgContent)
|
|
|
|
|
|
// // }
|
|
|
|
|
|
// // 名片类型
|
|
|
|
|
|
// if msgType == baseinfo.MMAddMsgTypeCard {
|
|
|
|
|
|
// dealPersionalCard(wxConn, addMsg)
|
|
|
|
|
|
// }
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
// 处理自动同意好友
|
|
|
|
|
|
// if msgType == baseinfo.MMAddMsgTypeFriendAdd {
|
|
|
|
|
|
// dealAutoAddFriend(wxConn, msgContent)
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// 处理关键词自动回复
|
|
|
|
|
|
// if msgType == baseinfo.MMAddMsgTypeText {
|
|
|
|
|
|
// dealKeywordAutoReply(wxConn, msgContent, fromUserName)
|
|
|
|
|
|
// // 处理关键词设置管理员
|
|
|
|
|
|
// dealAdminKeyword(wxConn, msgContent, fromUserName, beAtUser)
|
|
|
|
|
|
// // 处理关键词踢人
|
|
|
|
|
|
// dealKickKeyword(wxConn, msgContent, fromUserName, beAtUser)
|
|
|
|
|
|
// // 处理设置欢迎群关键词
|
|
|
|
|
|
// dealWelcomeGroupKeyword(wxConn, msgContent, fromUserName)
|
|
|
|
|
|
// // 处理关键词邀请入群
|
|
|
|
|
|
// dealInviteKeyword(wxConn, msgContent, fromUserName)
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// if msgType == 10002 && strings.HasSuffix(fromUserName, "@chatroom") {
|
|
|
|
|
|
// // 检查消息内容是否包含 "加入群聊" 字样
|
|
|
|
|
|
// if !strings.Contains(msgContent, "加入了群聊") {
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
// go db.SendMessageCallback(addMsg, uuid)
|
|
|
|
|
|
// // dealWelcomeMessage(wxConn, msgContent, fromUserName)
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// 防消息撤回管理器
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
currentSnsTransTask := taskMgr.GetSnsTransTask()
|
|
|
|
|
|
currentRevokeTask := taskMgr.GetRevokeTask()
|
|
|
|
|
|
//加好友自动回复
|
|
|
|
|
|
if msgType == baseinfo.MMAddMsgTypeSystemMsg {
|
|
|
|
|
|
if (currentSnsTransTask.IsAddFriendAutoReply() && msgContent == "以上是打招呼的内容" || strings.Contains(msgContent, "现在可以开始聊天了")) && currentSnsTransTask.AddFriendAutoReplyMsg != "" {
|
|
|
|
|
|
currentUserMsgMgr := wxConn.GetWXFriendMsgMgr()
|
|
|
|
|
|
addFriendAutoMsg := currentSnsTransTask.GetAddFriendAutoMsg()
|
|
|
|
|
|
// 清理首尾空格
|
|
|
|
|
|
addFriendAutoMsg = strings.TrimSpace(addFriendAutoMsg)
|
|
|
|
|
|
// 添加好友自动回复
|
|
|
|
|
|
if addFriendAutoMsg != "" {
|
|
|
|
|
|
currentUserMsgMgr.AddNewTextMsg(currentSnsTransTask.GetAddFriendAutoMsg(), fromUserName)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if msgType == baseinfo.MMAddMsgTypeText || msgType == baseinfo.MMAddMsgTypeImage {
|
|
|
|
|
|
// 如果开启了消息防撤回
|
|
|
|
|
|
if currentRevokeTask.IsAvoidRevoke() {
|
|
|
|
|
|
// fmt.Printf("增加消息:groupWXID %s\n", groupWXID)
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
currentRevokeTask.AddNewMsg(addMsg, uuid)
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 49 同时包括 57(引用消息,只可能是文本)
|
|
|
|
|
|
if msgType == baseinfo.MMAddMsgTypeRefer && strings.Contains(msgContent, "<type>57</type>") {
|
|
|
|
|
|
// 如果开启了消息防撤回
|
|
|
|
|
|
if currentRevokeTask.IsAvoidRevoke() {
|
|
|
|
|
|
// fmt.Printf("增加消息:groupWXID %s\n", groupWXID)
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
currentRevokeTask.AddNewMsg(addMsg, uuid)
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 47 表情包 包含 msg><emoji fromusername
|
|
|
|
|
|
if msgType == baseinfo.MMAddMsgTypePic && strings.Contains(msgContent, "<emoji fromusername") {
|
|
|
|
|
|
// 如果开启了消息防撤回
|
|
|
|
|
|
if currentRevokeTask.IsAvoidRevoke() {
|
|
|
|
|
|
// fmt.Printf("增加消息:groupWXID %s\n", groupWXID)
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
currentRevokeTask.AddNewMsg(addMsg, uuid)
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 撤回消息
|
|
|
|
|
|
if msgType == baseinfo.MMAddMsgTypeRevokemMsg {
|
|
|
|
|
|
tmpSysMsg := &baseinfo.SysMsg{}
|
|
|
|
|
|
err := xml.Unmarshal([]byte(msgContent), tmpSysMsg)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是撤回消息
|
|
|
|
|
|
if tmpSysMsg.Type == "revokemsg" {
|
|
|
|
|
|
if currentRevokeTask.IsAvoidRevoke() {
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
currentRevokeTask.OnRevokeMsg(tmpSysMsg.RevokeMsg, groupWXID, toGroupWXID, uuid)
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 这里要判断 该群是否有消息置顶
|
|
|
|
|
|
|
|
|
|
|
|
// 同时包含 <name>lastMessage</name>
|
|
|
|
|
|
if groupWXID != "" && msgType == baseinfo.MMAddMsgTypeStatusNotify && strings.Contains(msgContent, "<name>lastMessage</name>") {
|
|
|
|
|
|
|
|
|
|
|
|
dealTopGroup(wxConn, groupWXID)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否过期
|
|
|
|
|
|
// 判断禁用
|
|
|
|
|
|
func dealAuth(wxConn wxface.IWXConnect) {
|
|
|
|
|
|
wxAccount := wxConn.GetWXAccount()
|
|
|
|
|
|
// 防消息撤回管理器
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
currentSnsTransTask := taskMgr.GetSnsTransTask()
|
|
|
|
|
|
uuid := wxAccount.GetUserInfo().UUID
|
|
|
|
|
|
// 判断是否过期
|
|
|
|
|
|
// 判断过期
|
|
|
|
|
|
if !currentSnsTransTask.IsValidKey(uuid) {
|
|
|
|
|
|
currentReqInvoker := wxConn.GetWXReqInvoker()
|
|
|
|
|
|
currentWXFileHelperMgr := wxConn.GetWXFileHelperMgr()
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("该key已过期,请重新申请")
|
|
|
|
|
|
// 3 秒后退出
|
|
|
|
|
|
time.Sleep(time.Second * 3)
|
|
|
|
|
|
currentReqInvoker.SendLogoutRequest()
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断禁用
|
|
|
|
|
|
if currentSnsTransTask.IsDisable(uuid) {
|
|
|
|
|
|
currentReqInvoker := wxConn.GetWXReqInvoker()
|
|
|
|
|
|
currentWXFileHelperMgr := wxConn.GetWXFileHelperMgr()
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("该key已被禁用,请联系管理员")
|
|
|
|
|
|
// 3 秒后退出
|
|
|
|
|
|
time.Sleep(time.Second * 3)
|
|
|
|
|
|
currentReqInvoker.SendLogoutRequest()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理置顶群
|
|
|
|
|
|
func dealTopGroup(wxConn wxface.IWXConnect, groupWXID string) {
|
|
|
|
|
|
if groupWXID == "" {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
// 这里要判断 该群是否有消息置顶
|
|
|
|
|
|
if groupWXID != "" {
|
|
|
|
|
|
currentGrapHBMgr := taskMgr.GetGrabHBTask()
|
|
|
|
|
|
currentReqInvoker := wxConn.GetWXReqInvoker()
|
|
|
|
|
|
resp, err := currentReqInvoker.SendGetContactRequestForHB(groupWXID)
|
|
|
|
|
|
if err != nil || resp.GetBaseResponse().GetRet() != 0 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断不等于 null
|
|
|
|
|
|
if resp.GetContactList() != nil && len(resp.GetContactList()) > 0 {
|
|
|
|
|
|
contactInfo := resp.GetContactList()[0]
|
|
|
|
|
|
tmpBitVal := contactInfo.GetBitVal()
|
|
|
|
|
|
nickName := contactInfo.GetNickName()
|
|
|
|
|
|
if tmpBitVal&baseinfo.MMBitValChatOnTop != 0 {
|
|
|
|
|
|
currentGrapHBMgr.RecordTopGroup(groupWXID, nickName.GetStr())
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentGrapHBMgr.DelTopGroup(groupWXID)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dealCommand 处理收到的命令
|
|
|
|
|
|
func dealCommand(wxConn wxface.IWXConnect, cmdText string) {
|
|
|
|
|
|
currentReqInvoker := wxConn.GetWXReqInvoker()
|
|
|
|
|
|
currentWXCache := wxConn.GetWXCache()
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
currentGrapHBTask := taskMgr.GetGrabHBTask()
|
|
|
|
|
|
currentFriendTask := taskMgr.GetFriendTask()
|
|
|
|
|
|
currentRevokeTask := taskMgr.GetRevokeTask()
|
|
|
|
|
|
currentSnsTask := taskMgr.GetSnsTask()
|
|
|
|
|
|
currentVerifyTask := taskMgr.GetVerifyTask()
|
|
|
|
|
|
currentWXFileHelperMgr := wxConn.GetWXFileHelperMgr()
|
|
|
|
|
|
currentSnsTransTask := taskMgr.GetSnsTransTask()
|
|
|
|
|
|
currentGrapHBMgr := taskMgr.GetGrabHBTask()
|
|
|
|
|
|
|
|
|
|
|
|
wxAccount := wxConn.GetWXAccount()
|
|
|
|
|
|
uuid := wxAccount.GetUserInfo().UUID
|
|
|
|
|
|
|
|
|
|
|
|
// 新的命令映射
|
|
|
|
|
|
switch cmdText {
|
|
|
|
|
|
case "101": // 原A401 朋友圈自动点赞
|
|
|
|
|
|
isAutoThumbUP := currentSnsTask.IsAutoThumbUP()
|
|
|
|
|
|
if isAutoThumbUP {
|
|
|
|
|
|
currentSnsTask.SetAutoThumbUP(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("朋友圈自动点赞【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A401", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentSnsTask.SetAutoThumbUP(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("朋友圈自动点赞【开启】")
|
|
|
|
|
|
currentReqInvoker.SendSnsTimeLineRequest("", 0)
|
|
|
|
|
|
db.UpdateCommand(uuid, "A401", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "102": // 原B001 朋友圈自动评论
|
|
|
|
|
|
isAutoComment := currentSnsTask.IsAutoComment()
|
|
|
|
|
|
if isAutoComment {
|
|
|
|
|
|
currentSnsTask.SetAutoComment(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("朋友圈自动评论【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "B001", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentSnsTask.SetAutoComment(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("朋友圈自动评论【开启】")
|
|
|
|
|
|
currentReqInvoker.SendSnsTimeLineRequest("", 0)
|
|
|
|
|
|
db.UpdateCommand(uuid, "B001", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "103": // 原A811 自动入群邀请
|
|
|
|
|
|
needVerify := currentVerifyTask.IsAutoJoinGroup()
|
|
|
|
|
|
if needVerify {
|
|
|
|
|
|
currentVerifyTask.SetAutoJoinGroup(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("自动入群邀请【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A811", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentVerifyTask.SetAutoJoinGroup(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("自动入群邀请【开启】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A811", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "104": // 原A801 通过好友验证
|
|
|
|
|
|
needVerify := currentVerifyTask.IsNeedVerify()
|
|
|
|
|
|
if needVerify {
|
|
|
|
|
|
currentVerifyTask.SetNeedVerify(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("通过好友验证【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A801", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentVerifyTask.SetNeedVerify(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("通过好友验证【开启】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A801", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "105": // 原A601 消息防止撤回
|
|
|
|
|
|
isAvoidRevoke := currentRevokeTask.IsAvoidRevoke()
|
|
|
|
|
|
if isAvoidRevoke {
|
|
|
|
|
|
currentRevokeTask.SetAvoidRevoke(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("消息防止撤回【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A601", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentRevokeTask.SetAvoidRevoke(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("消息防止撤回【开启】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A601", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "106": // 原A101 自动领取红包
|
|
|
|
|
|
bAutoGrap := currentGrapHBTask.IsAutoGrap()
|
|
|
|
|
|
if bAutoGrap {
|
|
|
|
|
|
currentGrapHBTask.SetAutoGrap(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("自动领取红包【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A101", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentGrapHBTask.SetAutoGrap(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("自动领取红包【开启】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A101", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "107": // 原A103 延迟领取红包
|
|
|
|
|
|
bGetDelayOpen := currentGrapHBTask.GetDelayOpen()
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg(fmt.Sprintf("延迟抢红包时间为:%d 秒", bGetDelayOpen))
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "108": // 原A104 领取红包后感谢
|
|
|
|
|
|
bAutoGrap := currentGrapHBTask.IsAutoReply()
|
|
|
|
|
|
if bAutoGrap {
|
|
|
|
|
|
currentGrapHBTask.SetAutoReply(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("领取红包后感谢【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A104", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentGrapHBTask.SetAutoReply(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("领取红包后感谢【开启】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A104", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "109": // 原A105 领取个人红包
|
|
|
|
|
|
bAutoGrap := currentGrapHBTask.IsAutoPerson()
|
|
|
|
|
|
if bAutoGrap {
|
|
|
|
|
|
currentGrapHBTask.SetAutoPerson(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("领取个人红包【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A105", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentGrapHBTask.SetAutoPerson(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("领取个人红包【开启】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A105", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "110": // 原A111 置顶群组红包
|
|
|
|
|
|
bAutoGrap := currentGrapHBTask.IsNotTopGroup()
|
|
|
|
|
|
if bAutoGrap {
|
|
|
|
|
|
currentGrapHBTask.SetNotTopGroup(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("置顶群组红包【不抢】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A111", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentGrapHBTask.SetNotTopGroup(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("置顶群组红包【仅抢】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A111", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "111": // 原A106 自动接收转账
|
|
|
|
|
|
bAutoGrap := currentGrapHBTask.IsAutoTransfer()
|
|
|
|
|
|
if bAutoGrap {
|
|
|
|
|
|
currentGrapHBTask.SetAutoTransfer(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("自动接收转账【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A106", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentGrapHBTask.SetAutoTransfer(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("自动接收转账【开启】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A106", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "112": // 原A107 红包统计功能
|
|
|
|
|
|
bAutoGrap := currentGrapHBTask.IsHBStat()
|
|
|
|
|
|
if bAutoGrap {
|
|
|
|
|
|
currentGrapHBTask.SetHBStat(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("红包统计功能【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A107", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentGrapHBTask.SetHBStat(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("红包统计功能【开启】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A107", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "113": // 原A108 红包统计清零
|
|
|
|
|
|
financialStats := &wxcore.FinancialStats{}
|
|
|
|
|
|
db.SETExpirationObj(wxConn.GetWXAccount().GetUserInfo().WxId+"_Amount_0", financialStats, -1)
|
|
|
|
|
|
db.SETExpirationObj(wxConn.GetWXAccount().GetUserInfo().WxId+"_Amount_1", financialStats, -1)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("操作成功,红包统计已重置")
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "114": // 原A109 收款统计功能
|
|
|
|
|
|
bAutoGrap := currentGrapHBTask.IsTransStat()
|
|
|
|
|
|
if bAutoGrap {
|
|
|
|
|
|
currentGrapHBTask.SetTransStat(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("收款统计功能【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A109", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentGrapHBTask.SetTransStat(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("收款统计功能【开启】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A109", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "115": // 原A110 收款统计清零
|
|
|
|
|
|
financialStats := &wxcore.FinancialStats{}
|
|
|
|
|
|
db.SETExpirationObj(wxConn.GetWXAccount().GetUserInfo().WxId+"_ZZ_Amount_0", financialStats, -1)
|
|
|
|
|
|
db.SETExpirationObj(wxConn.GetWXAccount().GetUserInfo().WxId+"_ZZ_Amount_1", financialStats, -1)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("操作成功,转账统计已重置")
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "116": // 原200 查询置顶的群聊
|
|
|
|
|
|
groupList := currentGrapHBMgr.GetTopGroup()
|
|
|
|
|
|
if len(groupList) > 0 {
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("置顶的群聊:\n" + groupList)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("没有置顶的群聊")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "117": // 原A403 朋友圈收藏转发
|
|
|
|
|
|
isSyncTrans := currentSnsTransTask.IsAutoRelay()
|
|
|
|
|
|
if isSyncTrans {
|
|
|
|
|
|
currentSnsTransTask.SetAutoRelay(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("朋友圈收藏转发【关闭】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A403", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentSnsTransTask.SetAutoRelay(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("朋友圈收藏转发【开启】")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A403", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "118": // 原A402 朋友圈跟随转发
|
|
|
|
|
|
isSyncTrans := currentSnsTransTask.IsSyncTrans()
|
|
|
|
|
|
if isSyncTrans {
|
|
|
|
|
|
currentSnsTransTask.SetSyncTrans(false)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("朋友圈跟随转发【关闭】,并清空了同步转发好友列表")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A402", 0, "")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
currentSnsTransTask.SetSyncTrans(true)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("朋友圈跟随转发【开启】,把名片分享到「文件传输助手」绑定/解绑用户")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A402", 1, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "119": // 原901 检测僵死粉
|
|
|
|
|
|
currentFriendTask.StartFriendTask(1)
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "120": // 原902 清理僵死粉
|
|
|
|
|
|
currentFriendTask.StartFriendTask(2)
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "000": // 原000 帮助和功能状态
|
|
|
|
|
|
currentWXCache.SendUsageByText()
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "666": // 原100 查询卡密有效期
|
|
|
|
|
|
tipText := "欢迎使用金云豹"
|
|
|
|
|
|
// 获取卡密过期时间
|
|
|
|
|
|
expiryTime := currentSnsTransTask.GetExpiryDate()
|
|
|
|
|
|
// 本次登录时间
|
|
|
|
|
|
loginTime := wxAccount.GetUserInfo().LastLoginTime.Format("2006-01-02 15:04")
|
|
|
|
|
|
// 本次登录连续在线时间(距离上次手动登录)
|
|
|
|
|
|
onlineTime, _ := wxAccount.GetUserInfo().GetOnlineTime()
|
|
|
|
|
|
// 总计在线时间
|
|
|
|
|
|
totalOnline, _ := wxAccount.GetUserInfo().GetDeviceCreateTime()
|
|
|
|
|
|
|
|
|
|
|
|
tipText = tipText + "\n【您的卡密】:" + uuid
|
|
|
|
|
|
tipText = tipText + "\n【到期时间】:" + expiryTime
|
|
|
|
|
|
tipText = tipText + "\n【登录时间】:" + loginTime
|
|
|
|
|
|
tipText = tipText + "\n【本次在线】:" + onlineTime
|
|
|
|
|
|
tipText = tipText + "\n【总计在线】:" + totalOnline
|
|
|
|
|
|
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg(tipText)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理带#号的命令
|
|
|
|
|
|
if strings.Contains(cmdText, "#") {
|
|
|
|
|
|
parts := strings.Split(cmdText, "#")
|
|
|
|
|
|
if len(parts) != 2 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
cmd := parts[0]
|
|
|
|
|
|
content := parts[1]
|
|
|
|
|
|
|
|
|
|
|
|
switch cmd {
|
|
|
|
|
|
case "102": // 原001# 朋友圈评论内容
|
|
|
|
|
|
if len(content) > 255 {
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("评论长度不能超过255")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
content = strings.Replace(content, ",", ",", -1)
|
|
|
|
|
|
currentSnsTask.SetCommentContent(content)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("朋友圈自动评论内容:" + content)
|
|
|
|
|
|
db.UpdateCommand(uuid, "B001Str", 0, content)
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "104": // 原301# 通过好友验证后回复内容
|
|
|
|
|
|
if len(content) > 255 {
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("内容长度不能超过255")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
currentSnsTransTask.SetAddFriendAutoMsg(content)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("通过好友后回复内容:" + content)
|
|
|
|
|
|
db.UpdateCommand(uuid, "A301Str", 0, content)
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "107": // 原103# 延迟领取红包时间
|
|
|
|
|
|
num, err := strconv.Atoi(content)
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
currentGrapHBTask.SetDelayOpen(num)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("延迟抢红包时间为:" + strconv.Itoa(num) + " 秒")
|
|
|
|
|
|
db.UpdateCommand(uuid, "A103", num, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "108": // 原104# 领取红包后感谢内容
|
|
|
|
|
|
if len(content) > 255 {
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("内容长度不能超过255")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
content = strings.Replace(content, ",", ",", -1)
|
|
|
|
|
|
currentGrapHBTask.SetAutoReplyContent(content)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("领取红包后回复内容:" + content)
|
|
|
|
|
|
db.UpdateCommand(uuid, "A104Str", 1, content)
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
case "111": // 原116# 接收转账后回复内容
|
|
|
|
|
|
if len(content) > 255 {
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("内容长度不能超过255")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
currentGrapHBTask.SetAutoTransferReplyContent(content)
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg("接收转账后回复内容:" + content)
|
|
|
|
|
|
db.UpdateCommand(uuid, "A116Str", 1, content)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// isTextContainsChineseOrLetter 检查字符串是否包含汉字或字母
|
|
|
|
|
|
func isTextContainsChineseOrLetter(text string) bool {
|
|
|
|
|
|
// 定义一个正则表达式, 寻找汉字或字母字符
|
|
|
|
|
|
// 汉字范围:\p{Han}
|
|
|
|
|
|
// 字母范围:A-Za-z
|
|
|
|
|
|
re := regexp.MustCompile(`[A-Za-z\p{Han}]`)
|
|
|
|
|
|
return re.MatchString(text)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理自动入群邀请
|
|
|
|
|
|
func dealAutoJoinGroup(wxConn wxface.IWXConnect, content string, newMsgId string) {
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
currentVerifyTask := taskMgr.GetVerifyTask()
|
|
|
|
|
|
if !currentVerifyTask.IsAutoJoinGroup() {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 解析引用的消息
|
|
|
|
|
|
tmpMsg := new(baseinfo.JoinGroupMsg)
|
|
|
|
|
|
err := xml.Unmarshal([]byte(content), tmpMsg)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断是否是入群邀请
|
|
|
|
|
|
if tmpMsg.JoinGroupInfo.Type != baseinfo.MMAppMsgTypeGroupInvite {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断 url 是否包含 chatroombyinvite
|
|
|
|
|
|
if !strings.Contains(tmpMsg.JoinGroupInfo.Url, "chatroombyinvite") {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 开始加入群聊
|
|
|
|
|
|
fmt.Println("开始加入群聊")
|
|
|
|
|
|
currentVerifyTask.AddJoinGroup(tmpMsg.JoinGroupInfo.Url)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理名片信息
|
|
|
|
|
|
func dealPersionalCard(wxConn wxface.IWXConnect, addMsg *wechat.AddMsg) {
|
|
|
|
|
|
currentReqInvoker := wxConn.GetWXReqInvoker()
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
currentSnsTransTask := taskMgr.GetSnsTransTask()
|
|
|
|
|
|
currentWXFileHelperMgr := wxConn.GetWXFileHelperMgr()
|
|
|
|
|
|
|
|
|
|
|
|
// 先反序列化CardInfo
|
|
|
|
|
|
msgContent := addMsg.GetContent().GetStr()
|
|
|
|
|
|
cardInfo := &baseinfo.CardInfo{}
|
|
|
|
|
|
err := xml.Unmarshal([]byte(msgContent), cardInfo)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
baseutils.PrintLog(err.Error())
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 如果是公众号-不予理会
|
|
|
|
|
|
if strings.HasPrefix(cardInfo.UserName, "gh_") {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 获取详情
|
|
|
|
|
|
userInfo, _, _ := currentReqInvoker.SendGetContactRequestForCache(cardInfo.UserName, true)
|
|
|
|
|
|
// 公众号
|
|
|
|
|
|
if len(userInfo.GetCustomizedInfo().GetExternalInfo()) > 0 {
|
|
|
|
|
|
// 公众号
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if len(userInfo.GetNickName().GetStr()) <= 0 {
|
|
|
|
|
|
// 昵称不存在
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 如果开启了自动转发功能
|
|
|
|
|
|
if currentSnsTransTask.IsSyncTrans() {
|
|
|
|
|
|
// 如果不存在则增加,然后初始化
|
|
|
|
|
|
if currentSnsTransTask.AddSyncTransFriend(cardInfo.UserName) {
|
|
|
|
|
|
currentReqInvoker.SendSnsUserPageRequest(cardInfo.UserName, "", 0, false)
|
|
|
|
|
|
showText := "成功绑定名片【" + cardInfo.NickName + "】\n"
|
|
|
|
|
|
showText = showText + "当前绑定" + strconv.Itoa(currentSnsTransTask.GetTransFriendCount()) + "个"
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg(showText)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 如果存在则移除
|
|
|
|
|
|
currentSnsTransTask.DelSyncTransFriend(cardInfo.UserName)
|
|
|
|
|
|
showText := "成功解绑名片【" + cardInfo.NickName + "】\n"
|
|
|
|
|
|
showText = showText + "当前绑定" + strconv.Itoa(currentSnsTransTask.GetTransFriendCount()) + "个"
|
|
|
|
|
|
currentWXFileHelperMgr.AddNewTipMsg(showText)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理自动抢红包操作(群)
|
|
|
|
|
|
func dealGroupHB(wxConn wxface.IWXConnect, content string, groupWXID string) {
|
|
|
|
|
|
// 判断是否开启了自动抢红包功能
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
currentGrapHBMgr := taskMgr.GetGrabHBTask()
|
2026-02-26 10:44:13 +08:00
|
|
|
|
// if !currentGrapHBMgr.IsAutoGrap() {
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
2026-02-17 13:06:23 +08:00
|
|
|
|
// 解析引用的消息
|
|
|
|
|
|
tmpMsg := new(baseinfo.Msg)
|
|
|
|
|
|
err := xml.Unmarshal([]byte(content), tmpMsg)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断是否是红包
|
|
|
|
|
|
if tmpMsg.APPMsg.MsgType != baseinfo.MMAppMsgTypePayInfo {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断是否红包类型 10002
|
|
|
|
|
|
// fmt.Println(tmpMsg.APPMsg.WCPayInfo.SceneID)
|
|
|
|
|
|
if tmpMsg.APPMsg.WCPayInfo.SceneID != baseinfo.MMPayInfoSceneIDHongBao {
|
|
|
|
|
|
if tmpMsg.APPMsg.WCPayInfo.SceneID != baseinfo.MMPayInfoSceneIDHongBao1 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-02-26 10:44:13 +08:00
|
|
|
|
recvAtMs := time.Now().UnixMilli()
|
|
|
|
|
|
// //是否置顶的群
|
|
|
|
|
|
// isTopGroup := currentGrapHBMgr.IsTopGroup(groupWXID)
|
|
|
|
|
|
// //(false 不抢置顶群, true 只抢置顶群)判断没有置顶 return
|
|
|
|
|
|
// if currentGrapHBMgr.IsNotTopGroup() && !isTopGroup {
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
// //(false 不抢置顶群) 判断已置顶 return
|
|
|
|
|
|
// if !currentGrapHBMgr.IsNotTopGroup() && isTopGroup {
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
2026-02-17 13:06:23 +08:00
|
|
|
|
//延迟抢红包
|
2026-02-26 10:44:13 +08:00
|
|
|
|
// delaytime := currentGrapHBMgr.GetDelayOpen()
|
|
|
|
|
|
// if int(delaytime) >= 1 {
|
|
|
|
|
|
// time.Sleep(time.Duration(delaytime) * time.Second)
|
|
|
|
|
|
// }
|
2026-02-17 13:06:23 +08:00
|
|
|
|
|
|
|
|
|
|
// 过滤汉字/字母红包
|
2026-02-26 10:44:13 +08:00
|
|
|
|
// if currentGrapHBMgr.IsFilterText() {
|
|
|
|
|
|
// text := tmpMsg.APPMsg.WCPayInfo.ReceiverTitle
|
|
|
|
|
|
// // 判断是否包含汉字或字母
|
|
|
|
|
|
// if isTextContainsChineseOrLetter(text) {
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2026-02-17 13:06:23 +08:00
|
|
|
|
// 过滤测挂红包
|
2026-02-26 10:44:13 +08:00
|
|
|
|
// if currentGrapHBMgr.IsFilterCheats() {
|
|
|
|
|
|
// filterCheatsKey := currentGrapHBMgr.GetFilterCheatsKey()
|
|
|
|
|
|
// // fmt.Println(filterCheatsKey)
|
|
|
|
|
|
// // 字符串转 数组
|
|
|
|
|
|
// temKeywords := strings.Split(filterCheatsKey, ",")
|
|
|
|
|
|
// // 关键字
|
|
|
|
|
|
// keywords := make([]string, 0)
|
|
|
|
|
|
// // 去掉头尾空格
|
|
|
|
|
|
// for i := 0; i < len(temKeywords); i++ {
|
|
|
|
|
|
// keywordItem := strings.TrimSpace(temKeywords[i])
|
|
|
|
|
|
// if keywordItem != "" {
|
|
|
|
|
|
// keywords = append(keywords, keywordItem)
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // fmt.Println(keywords)
|
|
|
|
|
|
// // 判断关键字是否为空
|
|
|
|
|
|
// if len(keywords) > 0 {
|
|
|
|
|
|
// text := tmpMsg.APPMsg.WCPayInfo.ReceiverTitle
|
|
|
|
|
|
// for _, keyword := range keywords {
|
|
|
|
|
|
// if strings.Contains(text, keyword) {
|
|
|
|
|
|
// return
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
2026-02-17 13:06:23 +08:00
|
|
|
|
// 开始抢红包
|
|
|
|
|
|
hbItem := new(baseinfo.HongBaoItem)
|
|
|
|
|
|
hbItem.IsGroup = 1
|
|
|
|
|
|
hbItem.SceneID = tmpMsg.APPMsg.WCPayInfo.SceneID
|
|
|
|
|
|
hbItem.NativeURL = tmpMsg.APPMsg.WCPayInfo.NativeURL
|
2026-02-26 10:44:13 +08:00
|
|
|
|
hbItem.RecvAtMs = recvAtMs
|
2026-02-17 13:06:23 +08:00
|
|
|
|
hongBaoURLItem, err := clientsdk.ParseHongBaoURL(hbItem.NativeURL, groupWXID)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-02-26 10:44:13 +08:00
|
|
|
|
fmt.Print("\n开始抢红包\n")
|
2026-02-17 13:06:23 +08:00
|
|
|
|
hbItem.URLItem = hongBaoURLItem
|
|
|
|
|
|
hbItem.FromUserName = tmpMsg.FromUserName
|
|
|
|
|
|
currentGrapHBMgr.AddHBItem(hbItem)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理自动抢红包操作(私发)
|
|
|
|
|
|
func dealPersonHB(wxConn wxface.IWXConnect, content string, groupWXID string) {
|
|
|
|
|
|
// 判断是否开启了自动抢红包功能
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
currentGrapHBMgr := taskMgr.GetGrabHBTask()
|
|
|
|
|
|
// 判断是否开启接收个人红包
|
|
|
|
|
|
if !currentGrapHBMgr.IsAutoPerson() {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 解析引用的消息
|
|
|
|
|
|
tmpMsg := new(baseinfo.Msg)
|
|
|
|
|
|
err := xml.Unmarshal([]byte(content), tmpMsg)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断是否是红包
|
|
|
|
|
|
if tmpMsg.APPMsg.MsgType != baseinfo.MMAppMsgTypePayInfo {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断是否红包类型
|
|
|
|
|
|
if tmpMsg.APPMsg.WCPayInfo.SceneID != baseinfo.MMPayInfoSceneIDHongBao {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-02-26 10:44:13 +08:00
|
|
|
|
recvAtMs := time.Now().UnixMilli()
|
2026-02-17 13:06:23 +08:00
|
|
|
|
//延迟抢红包
|
|
|
|
|
|
delaytime := currentGrapHBMgr.GetDelayOpen()
|
|
|
|
|
|
if int(delaytime) >= 1 {
|
|
|
|
|
|
time.Sleep(time.Duration(delaytime) * time.Second)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 开始抢红包
|
|
|
|
|
|
hbItem := new(baseinfo.HongBaoItem)
|
|
|
|
|
|
hbItem.IsGroup = 0
|
|
|
|
|
|
hbItem.NativeURL = tmpMsg.APPMsg.WCPayInfo.NativeURL
|
2026-02-26 10:44:13 +08:00
|
|
|
|
hbItem.RecvAtMs = recvAtMs
|
2026-02-17 13:06:23 +08:00
|
|
|
|
hongBaoURLItem, err := clientsdk.ParseHongBaoURL(hbItem.NativeURL, groupWXID)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
hbItem.URLItem = hongBaoURLItem
|
|
|
|
|
|
// fmt.Print("\n开始抢个人红包\n")
|
|
|
|
|
|
currentGrapHBMgr.AddHBItem(hbItem)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理自动接收转账操作
|
|
|
|
|
|
func dealAutoTransfer(wxConn wxface.IWXConnect, content string, fromUserName string) {
|
|
|
|
|
|
// 判断是否开启了自动接收转账功能
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
currentGrapHBMgr := taskMgr.GetGrabHBTask()
|
|
|
|
|
|
if !currentGrapHBMgr.IsAutoTransfer() {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 解析引用的消息
|
|
|
|
|
|
tmpMsg := new(baseinfo.Msg2)
|
|
|
|
|
|
err := xml.Unmarshal([]byte(content), tmpMsg)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断是否转账
|
|
|
|
|
|
if tmpMsg.APPMsg.MsgType != baseinfo.MMAppMsgTypeTransfer {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
wcPayInfo := tmpMsg.APPMsg.WCPayInfo
|
|
|
|
|
|
|
|
|
|
|
|
tenpayUrl := "invalid_time=" + wcPayInfo.InvalidTime + "&op=confirm&total_fee=0&trans_id=" + wcPayInfo.TransFerId + "&transaction_id=" + wcPayInfo.TransactionId + "&username=" + wcPayInfo.ToUserName
|
|
|
|
|
|
wcPaySign, err := clientsdk.TenPaySignDes3(tenpayUrl, "%^&*Tenpay!@#$")
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 判断群聊
|
|
|
|
|
|
if strings.HasSuffix(fromUserName, "@chatroom") {
|
|
|
|
|
|
wcPayInfo.FromGroupId = fromUserName
|
|
|
|
|
|
} else {
|
|
|
|
|
|
wcPayInfo.FromGroupId = ""
|
|
|
|
|
|
wcPayInfo.FromUserName = fromUserName
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tenpayUrl += "&WCPaySign=" + wcPaySign
|
|
|
|
|
|
tmpReqItem := &baseinfo.TenPayReqItem{}
|
|
|
|
|
|
tmpReqItem.CgiCMD = 85
|
|
|
|
|
|
tmpReqItem.ReqText = tenpayUrl
|
|
|
|
|
|
currentGrapHBMgr.DirectTransfer(tmpReqItem, &wcPayInfo)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理自动通过好友添加
|
|
|
|
|
|
func dealAutoAddFriend(wxConn wxface.IWXConnect, content string) {
|
|
|
|
|
|
// 判断是否开启了自动接收转账功能
|
|
|
|
|
|
currentTaskMgr := wxConn.GetWXTaskMgr()
|
|
|
|
|
|
taskMgr, _ := currentTaskMgr.(*wxcore.WXTaskMgr)
|
|
|
|
|
|
currentVerifyTask := taskMgr.GetVerifyTask()
|
|
|
|
|
|
notNeedVerify := currentVerifyTask.IsNeedVerify()
|
|
|
|
|
|
if !notNeedVerify {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// 解析引用的消息
|
|
|
|
|
|
tmpMsg := new(baseinfo.AddFriendMsg)
|
|
|
|
|
|
err := xml.Unmarshal([]byte(content), tmpMsg)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !strings.HasPrefix(tmpMsg.EncryptUsername, "v3_") || !strings.HasPrefix(tmpMsg.Ticket, "v4_") {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
// bytes, _ := json.Marshal(tmpMsg)
|
|
|
|
|
|
// fmt.Println("FrindAddMsg:", string(bytes))
|
|
|
|
|
|
// 延时3秒
|
|
|
|
|
|
time.Sleep(3 * time.Second)
|
|
|
|
|
|
// 自动通过好友请求
|
|
|
|
|
|
|
|
|
|
|
|
_, _ = wxConn.GetWXReqInvoker().VerifyUserRequest(3, "", tmpMsg.Scene, tmpMsg.EncryptUsername, tmpMsg.Ticket, "")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dealKeywordAutoReply 处理关键词自动回复
|
|
|
|
|
|
func dealKeywordAutoReply(wxConn wxface.IWXConnect, content string, fromUserName string) {
|
|
|
|
|
|
// 获取当前账号UUID
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
|
|
|
|
|
|
// 查询关键词自动回复配置
|
|
|
|
|
|
command, err := db.QueryCommand(uuid)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否启用关键词自动回复
|
|
|
|
|
|
if command.B002 != 1 || command.B002Str == "" {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解析关键词回复配置
|
|
|
|
|
|
var pairs []req.KeywordReplyPair
|
|
|
|
|
|
err = json.Unmarshal([]byte(command.B002Str), &pairs)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 遍历关键词进行匹配
|
|
|
|
|
|
for _, pair := range pairs {
|
|
|
|
|
|
if strings.Contains(content, pair.Keyword) {
|
|
|
|
|
|
// 发送回复消息
|
|
|
|
|
|
currentUserMsgMgr := wxConn.GetWXFriendMsgMgr()
|
|
|
|
|
|
currentUserMsgMgr.AddNewTextMsg(pair.Reply, fromUserName)
|
|
|
|
|
|
break // 只回复第一个匹配的关键词
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dealAdminKeyword 处理关键词设置管理员
|
|
|
|
|
|
func dealAdminKeyword(wxConn wxface.IWXConnect, content string, fromUserName string, beAtUser string) {
|
|
|
|
|
|
// fmt.Println("dealAdminKeyword")
|
|
|
|
|
|
|
|
|
|
|
|
// 只处理群消息
|
|
|
|
|
|
if !strings.HasSuffix(fromUserName, "@chatroom") {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前账号UUID
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
|
|
|
|
|
|
// 查询管理员关键词配置
|
|
|
|
|
|
command, err := db.QueryCommand(uuid)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否启用管理员关键词功能
|
|
|
|
|
|
if command.B004 != 1 || command.B004Str == "" {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解析管理员关键词配置
|
|
|
|
|
|
var config req.AdminKeywordConfig
|
|
|
|
|
|
err = json.Unmarshal([]byte(command.B004Str), &config)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查消息是否包含关键词
|
|
|
|
|
|
contentParts := strings.SplitN(content, ":", 2)
|
|
|
|
|
|
if len(contentParts) != 2 {
|
|
|
|
|
|
fmt.Println("消息格式错误")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取发送者wxid
|
|
|
|
|
|
senderUsername := strings.TrimSpace(contentParts[0])
|
|
|
|
|
|
messageContent := strings.TrimSpace(contentParts[1])
|
|
|
|
|
|
|
|
|
|
|
|
if !strings.Contains(messageContent, config.Keyword) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取群信息,检查发送者是否是群主或管理员
|
|
|
|
|
|
currentReqInvoker := wxConn.GetWXReqInvoker()
|
|
|
|
|
|
resp, err := currentReqInvoker.SendGetContactRequestForHB(fromUserName)
|
|
|
|
|
|
if err != nil || resp.GetBaseResponse().GetRet() != 0 {
|
|
|
|
|
|
fmt.Println("获取群信息失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查权限
|
|
|
|
|
|
hasPermission := false
|
|
|
|
|
|
chatRoom := resp.GetContactList()[0]
|
|
|
|
|
|
chatroomData := chatRoom.GetNewChatroomData()
|
|
|
|
|
|
if chatroomData == nil {
|
|
|
|
|
|
fmt.Println("获取群信息失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否是群主或管理员
|
|
|
|
|
|
memberList := chatroomData.GetChatroomMemberList()
|
|
|
|
|
|
for _, member := range memberList {
|
|
|
|
|
|
if member.GetUserName() == senderUsername {
|
|
|
|
|
|
fmt.Println(member.GetChatroomMemberFlag())
|
|
|
|
|
|
if member.GetChatroomMemberFlag() == 1 { // 普通成员
|
|
|
|
|
|
hasPermission = false
|
|
|
|
|
|
}
|
|
|
|
|
|
if member.GetChatroomMemberFlag() == 2 { // 群主
|
|
|
|
|
|
hasPermission = true
|
|
|
|
|
|
} else if member.GetChatroomMemberFlag() == 2049 { // 管理员
|
|
|
|
|
|
hasPermission = true
|
|
|
|
|
|
}
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !hasPermission {
|
|
|
|
|
|
fmt.Println("用户没有权限设置管理员")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("targetUsername", beAtUser, "fromUserName", fromUserName)
|
|
|
|
|
|
// 设置为管理员
|
|
|
|
|
|
currentReqInvoker.SendAddChatroomAdminRequest(fromUserName, []string{beAtUser})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dealWelcomeMessage 处理新人进群欢迎词
|
|
|
|
|
|
func dealWelcomeMessage(wxConn wxface.IWXConnect, content string, fromUserName string) {
|
|
|
|
|
|
fmt.Println("dealWelcomeMessage")
|
|
|
|
|
|
// 获取当前账号UUID
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
|
|
|
|
|
|
// 查询欢迎词配置
|
|
|
|
|
|
command, err := db.QueryCommand(uuid)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否启用欢迎词
|
|
|
|
|
|
if command.B003 != 1 || command.B003Str == "" {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解析欢迎词配置
|
|
|
|
|
|
var config req.WelcomeConfig
|
|
|
|
|
|
err = json.Unmarshal([]byte(command.B003Str), &config)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查当前群聊是否在配置的群聊列表中
|
|
|
|
|
|
found := false
|
|
|
|
|
|
fmt.Println(fromUserName)
|
|
|
|
|
|
for _, room := range config.ChatRooms {
|
|
|
|
|
|
if room == fromUserName {
|
|
|
|
|
|
found = true
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if !found {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查消息内容是否包含 "加入群聊" 字样
|
|
|
|
|
|
if !strings.Contains(content, "加入了群聊") {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 发送欢迎词
|
|
|
|
|
|
wxConn.GetWXReqInvoker().SendTextMsgRequest(fromUserName, config.Content, nil, 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dealKickKeyword 处理关键词踢人
|
|
|
|
|
|
func dealKickKeyword(wxConn wxface.IWXConnect, content string, fromUserName string, beAtUser string) {
|
|
|
|
|
|
// fmt.Println("dealKickKeyword")
|
|
|
|
|
|
// 只处理群消息
|
|
|
|
|
|
if !strings.HasSuffix(fromUserName, "@chatroom") {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前账号UUID
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
|
|
|
|
|
|
// 查询踢人关键词配置
|
|
|
|
|
|
command, err := db.QueryCommand(uuid)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否启用踢人关键词功能
|
|
|
|
|
|
if command.B006 != 1 || command.B006Str == "" {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解析踢人关键词配置
|
|
|
|
|
|
var config req.KickKeywordConfig
|
|
|
|
|
|
err = json.Unmarshal([]byte(command.B006Str), &config)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 提取发送者信息
|
|
|
|
|
|
contentParts := strings.SplitN(content, ":", 2)
|
|
|
|
|
|
if len(contentParts) != 2 {
|
|
|
|
|
|
fmt.Println("消息格式错误")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取发送者wxid
|
|
|
|
|
|
senderUsername := strings.TrimSpace(contentParts[0])
|
|
|
|
|
|
messageContent := strings.TrimSpace(contentParts[1])
|
|
|
|
|
|
|
|
|
|
|
|
// 检查消息是否包含关键词
|
|
|
|
|
|
if !strings.Contains(messageContent, config.Keyword) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查被@用户是否存在
|
|
|
|
|
|
if beAtUser == "" {
|
|
|
|
|
|
fmt.Println("没有被@的用户")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取群信息,检查发送者是否是群主或管理员
|
|
|
|
|
|
currentReqInvoker := wxConn.GetWXReqInvoker()
|
|
|
|
|
|
resp, err := currentReqInvoker.SendGetContactRequestForHB(fromUserName)
|
|
|
|
|
|
if err != nil || resp.GetBaseResponse().GetRet() != 0 {
|
|
|
|
|
|
fmt.Println("获取群信息失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查权限
|
|
|
|
|
|
hasPermission := false
|
|
|
|
|
|
chatRoom := resp.GetContactList()[0]
|
|
|
|
|
|
chatroomData := chatRoom.GetNewChatroomData()
|
|
|
|
|
|
if chatroomData == nil {
|
|
|
|
|
|
fmt.Println("获取群信息失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否是群主或管理员
|
|
|
|
|
|
memberList := chatroomData.GetChatroomMemberList()
|
|
|
|
|
|
for _, member := range memberList {
|
|
|
|
|
|
if member.GetUserName() == senderUsername {
|
|
|
|
|
|
fmt.Println(member.GetChatroomMemberFlag())
|
|
|
|
|
|
if member.GetChatroomMemberFlag() == 1 { // 普通成员
|
|
|
|
|
|
hasPermission = false
|
|
|
|
|
|
}
|
|
|
|
|
|
if member.GetChatroomMemberFlag() == 2 { // 群主
|
|
|
|
|
|
hasPermission = true
|
|
|
|
|
|
} else if member.GetChatroomMemberFlag() == 2049 { // 管理员
|
|
|
|
|
|
hasPermission = true
|
|
|
|
|
|
}
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !hasPermission {
|
|
|
|
|
|
fmt.Println("用户没有权限踢人")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("踢出用户", beAtUser, "从群", fromUserName)
|
|
|
|
|
|
// 执行踢人操作
|
|
|
|
|
|
currentReqInvoker.SendDelDelChatRoomMemberRequest(fromUserName, []string{beAtUser})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理设置欢迎群关键词
|
|
|
|
|
|
func dealWelcomeGroupKeyword(wxConn wxface.IWXConnect, content string, fromUserName string) {
|
|
|
|
|
|
// 只处理群消息
|
|
|
|
|
|
if !strings.HasSuffix(fromUserName, "@chatroom") {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取当前账号UUID
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
|
|
|
|
|
|
// 查询欢迎词配置
|
|
|
|
|
|
command, err := db.QueryCommand(uuid)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否启用欢迎词功能
|
|
|
|
|
|
if command.B003 != 1 || command.B003Str == "" {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解析欢迎词配置
|
|
|
|
|
|
var config req.WelcomeConfig
|
|
|
|
|
|
err = json.Unmarshal([]byte(command.B003Str), &config)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 提取发送者信息
|
|
|
|
|
|
contentParts := strings.SplitN(content, ":", 2)
|
|
|
|
|
|
if len(contentParts) != 2 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取发送者wxid和消息内容
|
|
|
|
|
|
senderUsername := strings.TrimSpace(contentParts[0])
|
|
|
|
|
|
messageContent := strings.TrimSpace(contentParts[1])
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否包含设置欢迎群的关键词
|
|
|
|
|
|
if config.GroupKeyword == "" || !strings.Contains(messageContent, config.GroupKeyword) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查发送者是否有权限(群主或管理员)
|
|
|
|
|
|
currentReqInvoker := wxConn.GetWXReqInvoker()
|
|
|
|
|
|
resp, err := currentReqInvoker.SendGetContactRequestForHB(fromUserName)
|
|
|
|
|
|
if err != nil || resp.GetBaseResponse().GetRet() != 0 {
|
|
|
|
|
|
fmt.Println("获取群信息失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查权限
|
|
|
|
|
|
hasPermission := false
|
|
|
|
|
|
chatRoom := resp.GetContactList()[0]
|
|
|
|
|
|
chatroomData := chatRoom.GetNewChatroomData()
|
|
|
|
|
|
if chatroomData == nil {
|
|
|
|
|
|
fmt.Println("获取群信息失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否是群主或管理员
|
|
|
|
|
|
memberList := chatroomData.GetChatroomMemberList()
|
|
|
|
|
|
for _, member := range memberList {
|
|
|
|
|
|
if member.GetUserName() == senderUsername {
|
|
|
|
|
|
if member.GetChatroomMemberFlag() == 2 { // 群主
|
|
|
|
|
|
hasPermission = true
|
|
|
|
|
|
} else if member.GetChatroomMemberFlag() == 2049 { // 管理员
|
|
|
|
|
|
hasPermission = true
|
|
|
|
|
|
}
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !hasPermission {
|
|
|
|
|
|
fmt.Println("用户没有权限设置欢迎群")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查当前群是否已在列表中
|
|
|
|
|
|
for _, room := range config.ChatRooms {
|
|
|
|
|
|
if room == fromUserName {
|
|
|
|
|
|
// 群已经在列表中,无需添加
|
|
|
|
|
|
currentReqInvoker.SendTextMsgRequest(fromUserName, "该群已设置为欢迎群", nil, 1)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 将当前群添加到欢迎群列表
|
|
|
|
|
|
config.ChatRooms = append(config.ChatRooms, fromUserName)
|
|
|
|
|
|
|
|
|
|
|
|
// 将配置转换为JSON并更新
|
|
|
|
|
|
configJSON, err := json.Marshal(config)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Println("序列化欢迎词配置失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_, err = db.UpdateCommand(uuid, "B003Str", 0, string(configJSON))
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Println("更新欢迎词配置失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 发送设置成功消息
|
|
|
|
|
|
currentReqInvoker.SendTextMsgRequest(fromUserName, "已将该群设置为欢迎群", nil, 1)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dealInviteKeyword 处理关键词邀请入群
|
|
|
|
|
|
func dealInviteKeyword(wxConn wxface.IWXConnect, content string, fromUserName string) {
|
|
|
|
|
|
// 获取当前账号UUID
|
|
|
|
|
|
uuid := wxConn.GetWXAccount().GetUserInfo().UUID
|
|
|
|
|
|
|
|
|
|
|
|
// 查询邀请入群关键词配置
|
|
|
|
|
|
command, err := db.QueryCommand(uuid)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否启用邀请入群关键词功能
|
|
|
|
|
|
if command.B005 != 1 || command.B005Str == "" {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 解析邀请入群关键词配置
|
|
|
|
|
|
var config req.InviteKeywordConfig
|
|
|
|
|
|
err = json.Unmarshal([]byte(command.B005Str), &config)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查功能是否启用
|
|
|
|
|
|
if !config.Enable {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 处理群聊消息 - 设置关键词
|
|
|
|
|
|
if strings.HasSuffix(fromUserName, "@chatroom") {
|
|
|
|
|
|
// 处理设置关键词的逻辑
|
|
|
|
|
|
// 提取发送者信息
|
|
|
|
|
|
contentParts := strings.SplitN(content, ":", 2)
|
|
|
|
|
|
if len(contentParts) != 2 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取发送者wxid和消息内容
|
|
|
|
|
|
senderUsername := strings.TrimSpace(contentParts[0])
|
|
|
|
|
|
messageContent := strings.TrimSpace(contentParts[1])
|
|
|
|
|
|
|
|
|
|
|
|
// 检查消息是否包含设置关键词的关键词
|
|
|
|
|
|
if config.SetupKeyword == "" || !strings.Contains(messageContent, config.SetupKeyword) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 尝试提取设置的关键词和群ID
|
|
|
|
|
|
parts := strings.Split(messageContent, "+")
|
|
|
|
|
|
if len(parts) != 2 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inviteKeyword := strings.TrimSpace(parts[1])
|
|
|
|
|
|
|
|
|
|
|
|
// 检查关键词是否为空
|
|
|
|
|
|
if len(inviteKeyword) == 0 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查发送者是否有权限(群主或管理员)
|
|
|
|
|
|
currentReqInvoker := wxConn.GetWXReqInvoker()
|
|
|
|
|
|
resp, err := currentReqInvoker.SendGetContactRequestForHB(fromUserName)
|
|
|
|
|
|
if err != nil || resp.GetBaseResponse().GetRet() != 0 {
|
|
|
|
|
|
fmt.Println("获取群信息失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查权限
|
|
|
|
|
|
hasPermission := false
|
|
|
|
|
|
chatRoom := resp.GetContactList()[0]
|
|
|
|
|
|
chatroomData := chatRoom.GetNewChatroomData()
|
|
|
|
|
|
if chatroomData == nil {
|
|
|
|
|
|
fmt.Println("获取群信息失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查是否是群主或管理员
|
|
|
|
|
|
memberList := chatroomData.GetChatroomMemberList()
|
|
|
|
|
|
for _, member := range memberList {
|
|
|
|
|
|
if member.GetUserName() == senderUsername {
|
|
|
|
|
|
if member.GetChatroomMemberFlag() == 2 { // 群主
|
|
|
|
|
|
hasPermission = true
|
|
|
|
|
|
} else if member.GetChatroomMemberFlag() == 2049 { // 管理员
|
|
|
|
|
|
hasPermission = true
|
|
|
|
|
|
}
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !hasPermission {
|
|
|
|
|
|
fmt.Println("用户没有权限设置邀请关键词")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 检查关键词是否已存在
|
|
|
|
|
|
for i, pair := range config.Pairs {
|
|
|
|
|
|
if pair.Keyword == inviteKeyword {
|
|
|
|
|
|
// 更新现有的关键词
|
|
|
|
|
|
config.Pairs[i].ChatRoom = fromUserName
|
|
|
|
|
|
fmt.Println("更新关键词:", inviteKeyword, "对应群:", fromUserName)
|
|
|
|
|
|
|
|
|
|
|
|
// 更新配置
|
|
|
|
|
|
configJSON, err := json.Marshal(config)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Println("序列化邀请关键词配置失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_, err = db.UpdateCommand(uuid, "B005Str", 0, string(configJSON))
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Println("更新邀请关键词配置失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 发送设置成功消息
|
|
|
|
|
|
currentReqInvoker.SendTextMsgRequest(fromUserName, "已设置关键词: "+inviteKeyword+" 对应本群", nil, 1)
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 添加新的关键词和群ID对应关系
|
|
|
|
|
|
newPair := req.InviteKeywordPair{
|
|
|
|
|
|
Keyword: inviteKeyword,
|
|
|
|
|
|
ChatRoom: fromUserName,
|
|
|
|
|
|
}
|
|
|
|
|
|
config.Pairs = append(config.Pairs, newPair)
|
|
|
|
|
|
fmt.Println("添加关键词:", inviteKeyword, "对应群:", fromUserName)
|
|
|
|
|
|
|
|
|
|
|
|
// 更新配置
|
|
|
|
|
|
configJSON, err := json.Marshal(config)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Println("序列化邀请关键词配置失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_, err = db.UpdateCommand(uuid, "B005Str", 0, string(configJSON))
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fmt.Println("更新邀请关键词配置失败")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 发送设置成功消息
|
|
|
|
|
|
currentReqInvoker.SendTextMsgRequest(fromUserName, "已设置关键词: "+inviteKeyword+" 对应本群", nil, 1)
|
|
|
|
|
|
return
|
|
|
|
|
|
} else if strings.HasPrefix(fromUserName, "wxid_") || strings.HasPrefix(fromUserName, "gh_") {
|
|
|
|
|
|
// 处理私聊消息 - 邀请入群
|
|
|
|
|
|
// 检查消息是否匹配某个关键词
|
|
|
|
|
|
for _, pair := range config.Pairs {
|
|
|
|
|
|
if pair.Keyword != "" && content == pair.Keyword {
|
|
|
|
|
|
// 判断是否有效的群ID
|
|
|
|
|
|
if strings.HasSuffix(pair.ChatRoom, "@chatroom") {
|
|
|
|
|
|
fmt.Println("邀请用户", fromUserName, "进入群聊", pair.ChatRoom)
|
|
|
|
|
|
// 使用邀请API将用户拉入群聊
|
|
|
|
|
|
currentReqInvoker := wxConn.GetWXReqInvoker()
|
|
|
|
|
|
currentReqInvoker.SendAddChatRoomMemberRequest(pair.ChatRoom, []string{fromUserName})
|
|
|
|
|
|
// 发送邀请成功消息
|
|
|
|
|
|
currentReqInvoker.SendTextMsgRequest(fromUserName, "已邀请您进入群聊", nil, 1)
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|