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"
)
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.