【发布时间】:2022-07-21 15:35:16
【问题描述】:
我用firebase完成了在flutter android部分设置通知的过程,当我从面板发送通知时,它可以正常工作。
我想用 php 自动化这个。我在互联网上尝试了代码,但没有一个有效。如果您能帮助我解决这个问题,我将非常高兴。
这里是代码。我想要所有设备
<?php
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$token='token';
$notification = [
"title" =>"title12",
"body" => "body of message.",
"alert" => "Test Push Message",
"sound" => "default",
];
$data = [
"title" => "This is notification title",
"body" =>"This is notification text",
"priority" => "high",
"content_available" => true
];
$fcmNotification = [
'to' => '/topics/alerts',
'notification' => $notification,
'data' => $data,
'priority' => 10
];
$headers = [
'Authorization: key= server_key',
'Content-Type: application/json'
];
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$cRequest = curl_init();
curl_setopt($cRequest, CURLOPT_URL, $fcmUrl);
curl_setopt($cRequest, CURLOPT_POST, true);
curl_setopt($cRequest, CURLOPT_HTTPHEADER, $headers);
curl_setopt($cRequest, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cRequest, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cRequest, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
$result = curl_exec($cRequest);
curl_close($cRequest);
echo $result;
?>
【问题讨论】:
标签: php firebase push-notification