From a3a9c607fe4672b157712a18f0fcc4cc4d29b7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Tue, 26 Sep 2023 15:12:47 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/water_group.go | 2 +- utils/send.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tasks/water_group.go b/tasks/water_group.go index e7766bef..49600c2f 100644 --- a/tasks/water_group.go +++ b/tasks/water_group.go @@ -74,5 +74,5 @@ func dealYesterday(gid string) { notifyMsgs = append(notifyMsgs, " \n请未上榜的群友多多反思。") log.Printf("排行榜: \n%s", strings.Join(notifyMsgs, "\n")) - go utils.SendMessage(gid, "", strings.Join(notifyMsgs, "\n")) + go utils.SendMessage(gid, "", strings.Join(notifyMsgs, "\n"), 0) } diff --git a/utils/send.go b/utils/send.go index a284d7bb..dabe5f10 100644 --- a/utils/send.go +++ b/utils/send.go @@ -4,6 +4,7 @@ import ( "encoding/json" "github.com/go-resty/resty/v2" "log" + "time" ) // SendMessage @@ -11,7 +12,11 @@ import ( // @param toId // @param atId // @param msg -func SendMessage(toId, atId, msg string) { +func SendMessage(toId, atId, msg string, retryCount int) { + if retryCount > 5 { + log.Printf("重试五次失败,停止发送") + return + } // 组装参数 param := map[string]any{ "wxid": toId, // 群或好友Id @@ -26,7 +31,9 @@ func SendMessage(toId, atId, msg string) { Post("http://10.0.0.73:19088/api/sendTextMsg") if err != nil { log.Printf("发送文本消息失败: %s", err.Error()) - return + // 休眠五秒后重新发送 + time.Sleep(5 * time.Second) + SendMessage(toId, atId, msg, retryCount+1) } log.Printf("发送文本消息结果: %s", resp.String()) }