Created
May 16, 2017 11:06
-
-
Save AdityaDeshmane/2e5e0436b88520c2d0a98eea56bdeb1a to your computer and use it in GitHub Desktop.
GCM php script
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 | |
| //To Execute this this from Mac Terminal type php thisFilename.php | |
| $url = 'https://fcm.googleapis.com/fcm/send'; | |
| $fields = array ( | |
| 'to' => 'fq5fI_wcXNY:APA91bGpR-qCYW01wNJ8pnp1ftfgR3DHqPk3ViXDqTYrq-p7MUhry9cPcpXEl7z4GFHGUPcTduww656Rks8cOpSZR-FjrseDX4S-eGdzGaBEqI46KWF8ZJmJpegbf3tzVZwILmnf64aU',//Replace with FIRInstanceID.instanceID().token() this you can get in Appdelegate, note this is NOT token received in didRegisterForRemoteNotificationsWithDeviceToken | |
| 'notification' => array ( | |
| "body" => "message", | |
| "title" => "Title", | |
| "icon" => "myicon" | |
| ) | |
| ); | |
| $fields = json_encode ( $fields ); | |
| $headers = array ( | |
| 'Authorization: key=' . "AIdfdfzaSyC_0F8sqVqOgdg3Es4trWFcrNcrLpBjG6w06w",//This is Server Key, you can get it from Firebase console -> App Setting -> Cloud Messaging Tab - Legacy server key | |
| 'Content-Type: application/json' | |
| ); | |
| $ch = curl_init (); | |
| curl_setopt ( $ch, CURLOPT_URL, $url ); | |
| curl_setopt ( $ch, CURLOPT_POST, true ); | |
| curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers ); | |
| curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true ); | |
| curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields ); | |
| $result = curl_exec ( $ch ); | |
| curl_close ( $ch ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment