From ee79728f9d8f390b00defe7d79551b447cf9c7ad Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 29 Jul 2022 16:07:05 +0800 Subject: [PATCH 1/2] add test file --- internal/push/fcm/push.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/push/fcm/push.go b/internal/push/fcm/push.go index 33ef97332..80449907b 100644 --- a/internal/push/fcm/push.go +++ b/internal/push/fcm/push.go @@ -13,6 +13,8 @@ import ( "strconv" ) +const SinglePushCountLimit = 400 + type Fcm struct { FcmMsgCli *messaging.Client } @@ -60,21 +62,21 @@ func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string, } tokenlen := len(Tokens) // 500组为一个推送,我们用400好了 - limit := 400 - pages := int((tokenlen-1)/limit + 1) + pages := int((tokenlen-1)/SinglePushCountLimit + 1) Success := 0 Fail := 0 + log.Info(operationID, "fmc args", tokenlen, pages) for i := 0; i < pages; i++ { Msg := new(messaging.MulticastMessage) Msg.Notification = &messaging.Notification{} Msg.Notification.Body = detailContent Msg.Notification.Title = alert ctx := context.Background() - max := (i+1)*limit - 1 + max := (i+1)*SinglePushCountLimit - 1 if max >= tokenlen { max = tokenlen - 1 } - Msg.Tokens = Tokens[i*limit : max] + Msg.Tokens = Tokens[i*SinglePushCountLimit : max] //SendMulticast sends the given multicast message to all the FCM registration tokens specified. //The tokens array in MulticastMessage may contain up to 500 tokens. //SendMulticast uses the `SendAll()` function to send the given message to all the target recipients. From cd3778a6209c922cf047283556747683a77e7528 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Fri, 29 Jul 2022 16:09:53 +0800 Subject: [PATCH 2/2] add test file --- internal/push/fcm/push.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/push/fcm/push.go b/internal/push/fcm/push.go index 80449907b..a7a928978 100644 --- a/internal/push/fcm/push.go +++ b/internal/push/fcm/push.go @@ -8,6 +8,7 @@ import ( "context" firebase "firebase.google.com/go" "firebase.google.com/go/messaging" + "fmt" "google.golang.org/api/option" "path/filepath" "strconv" @@ -65,7 +66,7 @@ func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string, pages := int((tokenlen-1)/SinglePushCountLimit + 1) Success := 0 Fail := 0 - log.Info(operationID, "fmc args", tokenlen, pages) + fmt.Println(operationID, "fcm args", tokenlen, pages) for i := 0; i < pages; i++ { Msg := new(messaging.MulticastMessage) Msg.Notification = &messaging.Notification{}