add test file

This commit is contained in:
Gordon 2022-07-29 16:07:05 +08:00
parent b01474523e
commit ee79728f9d

View File

@ -13,6 +13,8 @@ import (
"strconv" "strconv"
) )
const SinglePushCountLimit = 400
type Fcm struct { type Fcm struct {
FcmMsgCli *messaging.Client FcmMsgCli *messaging.Client
} }
@ -60,21 +62,21 @@ func (f *Fcm) Push(accounts []string, alert, detailContent, operationID string,
} }
tokenlen := len(Tokens) tokenlen := len(Tokens)
// 500组为一个推送我们用400好了 // 500组为一个推送我们用400好了
limit := 400 pages := int((tokenlen-1)/SinglePushCountLimit + 1)
pages := int((tokenlen-1)/limit + 1)
Success := 0 Success := 0
Fail := 0 Fail := 0
log.Info(operationID, "fmc args", tokenlen, pages)
for i := 0; i < pages; i++ { for i := 0; i < pages; i++ {
Msg := new(messaging.MulticastMessage) Msg := new(messaging.MulticastMessage)
Msg.Notification = &messaging.Notification{} Msg.Notification = &messaging.Notification{}
Msg.Notification.Body = detailContent Msg.Notification.Body = detailContent
Msg.Notification.Title = alert Msg.Notification.Title = alert
ctx := context.Background() ctx := context.Background()
max := (i+1)*limit - 1 max := (i+1)*SinglePushCountLimit - 1
if max >= tokenlen { if max >= tokenlen {
max = tokenlen - 1 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. //SendMulticast sends the given multicast message to all the FCM registration tokens specified.
//The tokens array in MulticastMessage may contain up to 500 tokens. //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. //SendMulticast uses the `SendAll()` function to send the given message to all the target recipients.