Skip to content

Instantly share code, notes, and snippets.

@AdityaDeshmane
Created May 16, 2017 11:06
Show Gist options
  • Select an option

  • Save AdityaDeshmane/2e5e0436b88520c2d0a98eea56bdeb1a to your computer and use it in GitHub Desktop.

Select an option

Save AdityaDeshmane/2e5e0436b88520c2d0a98eea56bdeb1a to your computer and use it in GitHub Desktop.
GCM php script
<?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