From bb58b5090b2ad0870576fc9452edc541bd4e9099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Fri, 12 Jul 2024 10:03:45 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BC=98=E5=8C=96=E8=A2=AB=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E7=BE=A4=E8=81=8A=E4=B9=8B=E5=90=8E=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/plugins/notify2configuser.go | 3 +++ utils/send.go | 30 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/plugin/plugins/notify2configuser.go b/plugin/plugins/notify2configuser.go index e46d3a2..dd7f40e 100644 --- a/plugin/plugins/notify2configuser.go +++ b/plugin/plugins/notify2configuser.go @@ -34,6 +34,9 @@ func NotifyInvitationJoinGroup(m *plugin.MessageContext) { func NotifyRemoveFromChatroom(m *plugin.MessageContext) { // 如果是被移出群聊,推送到配置的用户 if strings.HasPrefix(m.Content, "你被\"") && strings.HasSuffix(m.Content, "\"移出群聊") { + // 调用一下退出群聊接口,防止被移出后还能从好友列表接口拉到相关信息 + utils.QuitChatroom(m.FromUser, 0) + // 取出群名称 groupInfo, err := service.GetFriendInfoById(m.FromUser) if err != nil { diff --git a/utils/send.go b/utils/send.go index 01bf18c..6d725f2 100644 --- a/utils/send.go +++ b/utils/send.go @@ -158,3 +158,33 @@ func DeleteGroupMember(chatRoomId, memberIds string, retryCount int, isSure bool DeleteGroupMember(chatRoomId, memberIds, 5, true) } } + +// QuitChatroom +// @description: 退出群聊 +// @param chatRoomId string 群Id +// @param retryCount int 重试次数 +func QuitChatroom(chatRoomId string, retryCount int) { + if retryCount > 5 { + log.Printf("重试五次失败,停止发送") + return + } + + // 组装参数 + param := map[string]any{ + "chatRoomId": chatRoomId, // 群Id + } + pbs, _ := json.Marshal(param) + + res := resty.New() + resp, err := res.R(). + SetHeader("Content-Type", "application/json;chartset=utf-8"). + SetBody(string(pbs)). + Post(config.Conf.Wechat.GetURL("/api/quitChatRoom")) + if err != nil { + log.Printf("退群失败: %s", err.Error()) + // 休眠五秒后重新发送 + time.Sleep(5 * time.Second) + QuitChatroom(chatRoomId, retryCount+1) + } + log.Printf("退群结果: %s", resp.String()) +}