Пуш-уведомление PHP firebase не отображается на экране и звук не воспроизводится, если приложение находится в фоновом режиме - PullRequest
0 голосов
/ 23 октября 2019

Я использую этот класс и код php для отправки push-уведомлений на устройство Android, но уведомление не отображается на экране, даже если приложение находится впереди. Звук не воспроизводится, если приложение находится в фоновом режиме

class PushNotifications
{

private static $URL = "https://fcm.googleapis.com/fcm/send";

private static $API_ACCESS_KEY = 'AAAAr....fpmYmt';

public function __construct()
{

}

public static function sendPushNotification($token = "", $fields = array())
{
    $registrationIds = array();

    array_push($registrationIds, $token);

    $msg = array('body' => $fields['body'], 'title' => $fields['title'], "priority" => $fields['priority']);

    $fields = array('registration_ids' => $registrationIds, 'notification' => $msg);

    $headers = array('Authorization: key=' . self::$API_ACCESS_KEY, 'Content-Type: application/json');

    #Send Reponse To FireBase Server
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, self::$URL);
    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);
    return $result;
}
}


require_once 'PushNotifications.php';
$device_token    =  "d3j....O9kj";
$fields          =  ["title" => "message title", "body" => "message text", "sound" => "default", 'priority' => 'high'];
$response        =  PushNotifications::sendPushNotification($device_token, $fields);
echo $response.'<br>';
$array = json_decode($response, true);

Как это исправить, чтобы уведомление отображалось на экране и воспроизводилось звук? Заранее спасибо

...