Firebase Push Notification by Curl

Firebase Push Notification by Curl

About FCM

Firebase Cloud Messaging (FCM) is a Google product. It’s a provide free (notification and messanging) cloud services across over world in different types of platforms, which are using these types of services developers end and the messages and notifications are sends including Android, iOS and web applications.FCM is also known as Google Cloud Messaging (GCM).

This is way how to create Push Notification through Curl…
public function sendFirebaseMessage($token, $title, $body) { $url = "https://fcm.googleapis.com/fcm/send"; //$token = "ctOQIjguuKk:APA91bEC90CqQUtaNNzVR-5JyDa4JXP5zfXGmLwM2i9djLobg1QSBlt5TkshNicqRQkY_Y773Ea4hDsoxP1zIWG76kjVQKmPfWZEfuLgvC289gNQEG64j39Ero6tlJne8w6DeqgJrIxg"; $serverKey = 'AAAAK7zk98I:APA91bH-TtQAIJkx3wivy4WYUiocQElVJewYKp9VHrcUcaxz-sWRu0byFKIqWWt3cPzsBZAK3FJSf-5UdiJs6ohv7qn44E1eH0c77T1I_El_cRl_rwuGN00H6M00wsffo7XNQwtJ4UdK'; //$title = "Notification title"; //$body = "Hello I am from Your php server"; $notification = array('title' =>$title , 'body' => $body, 'sound' => 'default', 'badge' => '1'); $arrayToSend = array('to' => $token, 'notification' => $notification, 'data' => $notification,'priority'=>'high'); $json = json_encode($arrayToSend); $headers = array(); $headers[] = 'Content-Type: application/json'; $headers[] = 'Authorization: key='. $serverKey; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER,$headers); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); //Send the request $response = curl_exec($ch); }
Please follow and like us:

Leave A Comment

Your email address will not be published. Required fields are marked *