How to send notification on mobile devices using firebase in php
Firebase is a platform developed by google for creating web and mobile app. We can send push notification to mobiles devices using firebase.
<?php $fireBaseApiKey = 'Add your firebase api key'; $messageTitle = "Notification Title"; $messageText = "Notification Text"; $fireBaseDeviceId = 'Add device token here'; $registrationIds[] = $fireBaseDeviceId; // this should be in array form $aMessage = array( 'body' => $messageText, 'title' => $messageTitle, "content_available" => true, "priority" => "high" ); $aNotification = array( 'text' => $messageText, 'title' => $messageTitle, "content_available" => true, "priority" => "high" ); $aFields = array( 'registration_ids' => $registrationIds, 'data' => $aMessage, 'notification' => $aNotification ); $aHeaders = array( 'Authorization: key=' . $fireBaseApiKey, 'Content-Type: application/json' ); $aUrl = "https://fcm.googleapis.com/fcm/send"; $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, $aUrl ); curl_setopt( $ch,CURLOPT_POST, true ); curl_setopt( $ch,CURLOPT_HTTPHEADER, $aHeaders ); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $aFields ) ); $result = curl_exec($ch ); print_r($result); curl_close( $ch );