嗨我正在使用firebase推送通知来发送推送通知我正在使用CodeIgniter框架我想向所有用户发送通知请帮助。
$data = [
"notification" => [
"body" => $body,
"title" => $title,
"url" => $link,
"link" => $link,
"image" => $imgurl,
"icon" => 'https://timages/favicon.ico'
],
"priority" => "high",
"data" => [
"click_action" => "FLUTTER_NOTIFICATION_CLICK",
"id" => "1",
"status" => "done",
"info" => [
"title" => $title,
"url" => $link,
"image" => $imgurl,
"icon" => 'https://timages/favicon.ico'
]
],
"to" => "/topic/all"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Authorization: key=< key >';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close ($ch);
1条答案
按热度按时间6tqwzwtp1#
对于Codeignighter用户,Firebase PHP SDK https://github.com/tattersoftware/codeigniter4-firebase
请参阅本文档-https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html
https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html#webpush
使用php将Firebase通知发送到所有android