首页 > 解决方案 > php android推送通知设置高优先级

问题描述

我正在使用 PHP 从浏览器向 Android 设备发送通知。当我在注销通知到来后启动应用程序但如果我终止应用程序通知不会到来。任何解决方案。

 public function send_android($target, $fields) {
    $apiKey = 'XXXXXXXXX';
    $headers = array("Content-Type:" . "application/json", "Authorization:key=" . $apiKey);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");
    curl_setopt( $ch, CURLOPT_POST, true );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    $result = curl_exec($ch);
    curl_close($ch);
}

标签: phpandroidpush-notification

解决方案


您需要在名为的字段数组中发送额外的键"priority",值将是“ high”。所以你的字段数组将与...相同

$fields = array('to' => $token, 'notification' => $notification,'priority'=>'high');

推荐阅读