[英]How to internationalize/localize your FCM push notifications, especially topics?
[英]How to send FCM Push Notifications to multiple topics
我正在使用 php 服務器發送 FCM 推送通知。 我想知道如何同時向多個主題發送推送通知。
這是我的代碼。
function sendPush($topic,$msg){
$API_ACCESS_KEY = '...';
$msg = array
(
'msg' => $msg
);
$fields = array('to' => '/topics/' . $topic, 'priority' => 'high', 'data' => $msg);
$headers = array
(
'Authorization: key=' . $API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$pushResult = curl_exec($ch);
curl_close($ch);
}
您使用condition
鍵發送到多個主題。
例如:
{
"condition": "'dogs' in topics || 'cats' in topics",
"priority" : "high",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message",
}
}
這會將消息發送到訂閱主題“狗”或“貓”的設備。
FCM 文檔的相關引用:
為了發送到多個主題的組合,應用服務器將條件鍵設置為指定目標主題的布爾條件。
請注意,您僅限於 2 個布爾條件,這意味着您最多可以向 3 個主題發送一條消息。
更新:現在您可以包含 5 個主題。
您最多可以在條件表達式中包含五個主題,並且支持括號。 支持的運算符:&&、||、!。 注意 ! 的用法:
閱讀文檔: https : //firebase.google.com/docs/cloud-messaging/send-message
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.