我正在使用以下脚本向特定用户发送通知:
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'My_API_KEY' );
$registrationIds = array( TOKENS );
// prep the bundle
$msg = array
(
'body' => "abc",
'title' => "Hello from Api",
'vibrate' => 1,
'sound' => 1,
);
$fields = array
(
'registration_ids' => $registrationIds,
'notification' => $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 ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
?>
脚本运行良好,但我如何向所有安装了我的应用程序的用户发送通知。我在我的应用程序(警报)中创建了一个主题,我可以通过 firebase 控制台向所有用户发送通知。谁能指导我更新上面的主题脚本。
最佳答案
我通过替换修复了
$fields = array
(
'registration_ids' => $registrationIds,
'notification' => $msg
);
到
$fields = array
(
'to' => '/topics/alerts',
'notification' => $msg
);
关于php - Firebase 如何发送主题通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42384157/