Я работаю над отправкой уведомлений pu sh с помощью Google Firebase в php.
. Вот код для Ios, android и веб-браузеров.
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array('Authorization:key=KEY', 'Content-Type: application/json');
/*--- send notification to IOS devices ---*/
$ios_array = array("topic" => "/topics/ios_1234");
$ios_array['url'] = $browser_url;
$ios_array['image'] = $image;
$fields = array(
"to" => "/topics/ios_1234",
"priority" => "high",
"notification" => array(
"title" => "Title",
"body" => "This is a test message",
"sound" => "default",
"content_available" => true),
"data" => $ios_array);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
/*--- send notification to Android device ---*/
$android_array = array("title" => "Title", "body" => "This is a test message", "sound" => "default");
$android_array['url'] = $browser_url;
$android_array['image'] = $image;
$fields = array(
"to" => "/topics/android_1234",
"priority" => "high",
"data" => $android_array,
"content_available" => true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
/*--- send notification to WEB Browsers ---*/
$radio_url = "https://example.com";
$fields = array(
"to" => "/topics/web_1234",
"priority" => "high",
"notification" => array(
"title" => "Title",
"body" => "This is a test message",
"icon" => "",
"click_action" => $radio_url,
"image" => $image));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result == 1) {
curl_close($ch);
}
Где $ image & $ browser_url - это URL-адреса изображений и URL-адреса перенаправления соответственно.
Я пытаюсь отправить изображение на всех устройствах, но изображение не отображается в уведомлениях браузера и в ios & android само уведомление не получено, когда изображение включено в уведомление.
Может ли кто-нибудь помочь мне в этом?