Answer the question
In order to leave comments, you need to log in
How to work with laravel push notifications?
Good afternoon. I need to implement sending push notifications via gcm to a mobile device. I am using this library . I don’t understand how to create a device token and how to check pusha sending if I develop only a server and do not have access to a mobile application.
Answer the question
In order to leave comments, you need to log in
use libraries optional
sending is done by regular post
// Server URL Google Firebase Cloud Messages
$SERVER_URL = '';
// Server key FCM/GCM
$API_ACCESS_KEY = '';
// Массив токенов
$arTokens = [];
// Отправляем
$headers = [
'Authorization: key=' . $API_ACCESS_KEY,
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, $SERVER_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 );
$fields = [
'registration_ids' => $arTokens,
'data' => [
'message' => $message
]
];
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch);
curl_close( $ch );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question