我使用 promise all 来发送多个 promise,我得到了这个错误
429 - {“错误”:{“代码”:“TooManyRequests”,“消息”:“请求太多”}}
我有数据列表,我按 10 组分组数据,然后我为每个人发送通知
await Promise.all(usersList.map(usersTokens=> {
return sendPush(heading, content,usersTokens, platform).catch((e) => {
console.error(e)
errors.push({ e, android })
})
}))
发送推送功能
import * as rp from 'request-promise'
export const sendPush = (title="",secondTitle,tokens,platform) => {
let message = {
notification_content : {
name:title,
title : secondTitle,
body : secondTitle,
},
notification_target : {
type : "devices_target",
devices : tokens
},
}
var headers = {
"Content-Type": "application/json; charset=utf-8",
"X-API-Token": 'XXXXXXXXXXXXXXXXXXXXXXXXXXX'
};
var options = {
uri: `https://api.appcenter.ms/v0.1/apps/XXXXXXXXXX/${platform}/push/notifications`,
method: "POST",
headers: headers,
body: message,
json: true
}
return rp(options)
}