Forked from IsmailShurrab/firebase notification curl
Created
February 24, 2019 02:25
-
-
Save sugaith/688e2edc02df56dab7fa2666f4aaf698 to your computer and use it in GitHub Desktop.
firebase notification curl php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $url = "https://fcm.googleapis.com/fcm/send"; | |
| $token = "your device token"; | |
| $serverKey = 'your server token of FCM project'; | |
| $title = "Notification title"; | |
| $body = "Hello I am from Your php server"; | |
| $notification = array('title' =>$title , 'text' => $body, 'sound' => 'default', 'badge' => '1'); | |
| $arrayToSend = array('to' => $token, 'notification' => $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); | |
| //Send the request | |
| $response = curl_exec($ch); | |
| //Close request | |
| if ($response === FALSE) { | |
| die('FCM Send Error: ' . curl_error($ch)); | |
| } | |
| curl_close($ch); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment