У меня есть приложение android, которое использует базу данных MySQL на сервере. Когда новые данные вставляются в таблицу, мой файл php отправляет уведомление через Firebase. если firebase доставляет уведомление на одно устройство, данные сохраняются в table_1, если firebase не может доставить уведомление, данные сохраняются в table_2. Мой вопрос; можно ли проверить, доставляет ли firebase уведомление в php?
FirebaseNotification. php
class FirebaseNotification {
public function send($registration_ids, $notification){
$fields = array(
'registration_ids' => $registration_ids,
'data' => $notification
);
return $this->sendPushNotification($fields);
}
private function sendPushNotification($fields){
require_once dirname(__FILE__) . '/Constants.php';
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key=' . FIREBASE_API_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $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);
if ($result === FALSE){
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
}
PushNotification. php
class PushNotification{
private $mTitle;
private $mContent;
private $mProcess;
function __construct($mTitle, $mContent, $mProcess)
{
$this->mTitle = $mTitle;
$this->mContent = $mContent;
$this->mProcess = $mProcess;
}
public function getPushNotification(){
$res = array();
$res['ntf']['title'] = $this->mTitle;
$res['ntf']['content'] = $this->mContent;
$res['ntf']['process'] = $this->mProcess;
return $res;
}
}