Answer the question
In order to leave comments, you need to log in
How to send Firebase Cloud Messaging when backend in php?
Hello. I faced such problem. The task is to make notifications in applications on iOS and Android. I first decided to use Firebase Cloud Messaging. Later I found out that Firebase does not work with PHP... The backend of the application is written in PHP.
On the backend, I do only 2 scenarios for notifications:
- Receiving bonuses for certain actions
- Notification of the purchase of goods
Now I'm wondering how I can connect these scripts with Firebase Cloud Messaging in order to send them by pushes to the application .. And the notifications themselves were also stored in the application as a list on a separate screen.
Is there a solution to make an intermediary on js and already connect it with Firebase Cloud Messaging? What do you think?
Thank you in advance for any solutions.
Answer the question
In order to leave comments, you need to log in
Example:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, htmlspecialchars_decode('https://fcm.googleapis.com/fcm/send'));
curl_setopt($ch, CURLOPT_POST, true);
$headers = [
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2);
$fields = [
'to' => 'userAgentToken',
'notification' => [
'body' => 'Some body text',
'title' => 'Some title text'
]];
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
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