我需要将 FCM 推送通知发送到多个设备。我不能为此使用“主题”,因为我需要将其发送到特定的和多个令牌。
在旧方法中,我使用“register_ids”来实现此目的,但 Google 在 2023 年 6 月 20 日宣布,旧方法将于 2024 年 6 月 20 日结束。在新的 v1 API 中,不再支持“register_ids”。
我需要的是一个使用 cURL 和 PHP 向多个令牌发送推送通知的解决方案。
在这个网站上,有人问了和我类似的问题:
@Frank van Puffelen 说:
在这个新的版本化 API 中,您可以通过向常规端点发送多部分请求来发送多条消息。此过程在有关发送批量消息的部分中有完整记录,并且大多数可用的管理 SDK 也支持该过程. ”
Frank von Puffelen 提供了一个链接:
https://firebase.google.com/docs/cloud-messaging/send-message#send-a-batch-of-messages
然而,现在该网站上有一条说明:
本节中描述的批量发送方法已于 2023 年 6 月 21 日弃用,并将于 2024 年 6 月删除。相反,请通过实现您自己的批量发送逻辑、迭代收件人列表和发送到每个收件人的令牌。对于 Admin SDK 方法,请确保更新到下一个主要版本。 ”
在该网站的更上方,有一个标题为“向多个设备发送消息”的部分。但是,本节仅提供 Node.js、Java、Python、Go、C# 和 REST 的解决方案。我需要 PHP 和 cURL 的解决方案。
到目前为止我已经尝试过如下,但由于架构错误而无法正常工作:
$tokens = array(
"token 1", …Run Code Online (Sandbox Code Playgroud) 我使用此 preg 替换来删除字符串中的所有表情符号:
$data['message'] = preg_replace("/([0-9|#][\x{20E3}])|[\x{00ae}|\x{00a9}|\x{203C}|\x{2047}|\x{2048}|\x{2049}|\x{3030}|\x{303D}|\x{2139}|\x{2122}|\x{3297}|\x{3299}][\x{FE00}-\x{FEFF}]?|[\x{2190}-\x{21FF}][\x{FE00}-\x{FEFF}]?|[\x{2300}-\x{23FF}][\x{FE00}-\x{FEFF}]?|[\x{2460}-\x{24FF}][\x{FE00}-\x{FEFF}]?|[\x{25A0}-\x{25FF}][\x{FE00}-\x{FEFF}]?|[\x{2600}-\x{27BF}][\x{FE00}-\x{FEFF}]?|[\x{2900}-\x{297F}][\x{FE00}-\x{FEFF}]?|[\x{2B00}-\x{2BF0}][\x{FE00}-\x{FEFF}]?|[\x{1F000}-\x{1F6FF}][\x{FE00}-\x{FEFF}]?/u", "", $data['message']);
Run Code Online (Sandbox Code Playgroud)
这非常有效,但我不想删除它们。相反,我必须用 bbcode 替换它们。这意味着字符串中的每个表情符号都应该替换为自己的 bbcode。
例子:
U+1F600
Run Code Online (Sandbox Code Playgroud)
变成
[emoji]1f600[/emoji]
Run Code Online (Sandbox Code Playgroud)
或者
U+1F603
Run Code Online (Sandbox Code Playgroud)
变成
[emoji]1f603[/emoji]
Run Code Online (Sandbox Code Playgroud)
这可能吗?非常感谢。
对于图片库,我使用亚马逊cloudfront。
\n\n我在原点设置了:
\n\nCache-Control:max-age=31536000 (1 Year)\nRun Code Online (Sandbox Code Playgroud)\n\n1 . 当我已经设置了 max-age 时,将 TTL 0(24 小时)设置为 1 年是否有用?
\n\n2 . 当我将 max-age 设置为 1 年时,亚马逊会每 24 小时检查一次 TTL0 的文件吗?
\n\n亚马逊是这样说的:
\n\nObjects are cached for the greater of the value of the Cache-Control max-age directive or the value of the CloudFront Minimum TTL\nRun Code Online (Sandbox Code Playgroud)\n\n亚马逊还表示:
\n\nIf an object in an edge location isn't frequently requested, CloudFront might evict the object\xe2\x80\x94remove the object before its expiration date\xe2\x80\x94to …Run Code Online (Sandbox Code Playgroud)