Anonymous
Возникает ошибка 404 при отправке уведомления
Сообщение
Anonymous » 06 окт 2024, 16:01
Я использую Firebase для отправки уведомлений приложений в PHP 5.6, CodeIgniter 2.15.
Похоже, что срок действия токена fcm во многих случаях истекает через 2–3 дня, и возникает эта ошибка:
Код: Выделить всё
[fblurojit] => {
"error": {
"code": 404,
"message": "Requested entity was not found.",
"status": "NOT_FOUND",
"details": [
{
"@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "UNREGISTERED"
}
]
Но если пользователь только что вошел в систему сегодня, уведомление отправляется, но не на все телефоны.
И как я могу отправлять уведомления пакетами в этой версии 1?
Код: Выделить всё
function sendNotificationBulk($message = null, $title = null, $imageUrl = null, $usernamesString = null)
{
$usernamesString = '"fktmctsantosh","fblurojit","fktmanil111","ctdeveloper","fltpmin11","fblubishnu7"';
$message = "Test";
$title = "Notification Testing";
$imageUrl = "2024-10-06_11153_recharge_325_new_offer.jpeg&share=2024-10-06_11153.jpeg";
$serviceAccountFile = '/Users/rajivbhandari/Desktop/classic-tech-firebase.json';
$accessToken = $this->getAccessToken($serviceAccountFile);
$support = $this->load->database('test', TRUE);
$limit = 200;
$offset = 0;
$image_path = !empty($imageUrl) ? "https://fileserver.classic.com.np/api/files/cat?path=%2F" . $imageUrl : "";
$loopcount = 1;
$responseArray = array();
if (!empty($usernamesString))
{
do {
$sql = "SELECT fcm.fcm_token, fcm.username, fcm.platform
FROM app_fcm_token AS fcm
WHERE id IN (SELECT MAX(id) FROM app_fcm_token WHERE username IN ($usernamesString) GROUP BY username)
ORDER BY fcm.created_date DESC
LIMIT $limit OFFSET $offset ";
$fcmList = $support->query($sql);
$queryResultCount = $fcmList->num_rows();
$resultSet = $fcmList->result_array();
foreach ($resultSet as $row)
{
$fcmToken = $row['fcm_token'];
$fcmMsg = [
'body' => $message,
'title' => $title
];
$payload = [
'message' => [
'token' => $fcmToken,
'notification' => $fcmMsg,
'android' => [
'priority' => 'high',
'notification' => [
'sound' => 'default'
]
],
'apns' => [
'payload' => [
'aps' => [
'mutable-content' => 1,
'content-available' => 1
]
],
'fcm_options' => [
'image' => $image_path
]
],
'webpush' => [
'fcm_options' => [
'link' => $image_path
]
]
]
];
$headers = [
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/v1/projects/test-tech/messages:send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
$result = curl_exec($ch);
if ($result === false) {
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// throw new Exception('FCM Send Error: ' . curl_error($ch), $status_code);
}
curl_close($ch);
$responseArray[$row['username']] = $result;
}
$offset += $limit;
} while ($queryResultCount > 0);
}
echo "
";
print_r($responseArray);
exit();
}
Я ожидаю, что уведомления будут отправляться пакетами. Как это исправить?
Подробнее здесь:
https://stackoverflow.com/questions/790 ... tification
1728219711
Anonymous
Я использую Firebase для отправки уведомлений приложений в PHP 5.6, CodeIgniter 2.15. Похоже, что срок действия токена fcm во многих случаях истекает через 2–3 дня, и возникает эта ошибка: [code][fblurojit] => { "error": { "code": 404, "message": "Requested entity was not found.", "status": "NOT_FOUND", "details": [ { "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError", "errorCode": "UNREGISTERED" } ] [/code] Но если пользователь только что вошел в систему сегодня, уведомление отправляется, но не на все телефоны. И как я могу отправлять уведомления пакетами в этой версии 1? [code]function sendNotificationBulk($message = null, $title = null, $imageUrl = null, $usernamesString = null) { $usernamesString = '"fktmctsantosh","fblurojit","fktmanil111","ctdeveloper","fltpmin11","fblubishnu7"'; $message = "Test"; $title = "Notification Testing"; $imageUrl = "2024-10-06_11153_recharge_325_new_offer.jpeg&share=2024-10-06_11153.jpeg"; $serviceAccountFile = '/Users/rajivbhandari/Desktop/classic-tech-firebase.json'; $accessToken = $this->getAccessToken($serviceAccountFile); $support = $this->load->database('test', TRUE); $limit = 200; $offset = 0; $image_path = !empty($imageUrl) ? "https://fileserver.classic.com.np/api/files/cat?path=%2F" . $imageUrl : ""; $loopcount = 1; $responseArray = array(); if (!empty($usernamesString)) { do { $sql = "SELECT fcm.fcm_token, fcm.username, fcm.platform FROM app_fcm_token AS fcm WHERE id IN (SELECT MAX(id) FROM app_fcm_token WHERE username IN ($usernamesString) GROUP BY username) ORDER BY fcm.created_date DESC LIMIT $limit OFFSET $offset "; $fcmList = $support->query($sql); $queryResultCount = $fcmList->num_rows(); $resultSet = $fcmList->result_array(); foreach ($resultSet as $row) { $fcmToken = $row['fcm_token']; $fcmMsg = [ 'body' => $message, 'title' => $title ]; $payload = [ 'message' => [ 'token' => $fcmToken, 'notification' => $fcmMsg, 'android' => [ 'priority' => 'high', 'notification' => [ 'sound' => 'default' ] ], 'apns' => [ 'payload' => [ 'aps' => [ 'mutable-content' => 1, 'content-available' => 1 ] ], 'fcm_options' => [ 'image' => $image_path ] ], 'webpush' => [ 'fcm_options' => [ 'link' => $image_path ] ] ] ]; $headers = [ 'Authorization: Bearer ' . $accessToken, 'Content-Type: application/json' ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/v1/projects/test-tech/messages:send'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); $result = curl_exec($ch); if ($result === false) { $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // throw new Exception('FCM Send Error: ' . curl_error($ch), $status_code); } curl_close($ch); $responseArray[$row['username']] = $result; } $offset += $limit; } while ($queryResultCount > 0); } echo " "; print_r($responseArray); exit(); } [/code] Я ожидаю, что уведомления будут отправляться пакетами. Как это исправить? Подробнее здесь: [url]https://stackoverflow.com/questions/79059135/getting-404-error-when-sending-notification[/url]