我正在使用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);
}
1 回答
您使用
condition
键发送到多个主题 .例如:
这会将消息发送给订阅主题为“狗”或“猫”的设备 .
来自FCM docs的相关报价:
请注意,您只能使用2个布尔条件,这意味着您可以将一条消息发送到最多3个主题 .