php - Firebase 如何发送主题通知

标签 php android firebase firebase-cloud-messaging

我正在使用以下脚本向特定用户发送通知:

<?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/

相关文章:

javascript - 具有 Firebase 云功能的自定义观察器

firebase - 如何在flutter中设置模型对象的值并在FutureBuilder ListView中使用它?

php - 事务无法正常工作 - PHP 和 MySql

php - Codeigniter - 将 2 个文件附加到已从用户表单上传到网络服务器的电子邮件

php - 用php将excel(xlsx)导入mysql数据库

java - 如何从另一个类设置 TextView (Android)

javascript - 将 CSV 转换为 JSON 键值

android - 带有自定义适配器的ListView,一个一个添加元素

android - jWplayer 不在 Android 上运行流

java - 新的NotificationCompat.BigPictureStyle()显示错误无法膨胀通知 View