Skip to content

Instantly share code, notes, and snippets.

@sidiqpermana
Created July 26, 2016 17:33
Show Gist options
  • Save sidiqpermana/137a06efc127dc261fa89997ece2a4cb to your computer and use it in GitHub Desktop.
Save sidiqpermana/137a06efc127dc261fa89997ece2a4cb to your computer and use it in GitHub Desktop.
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR_FIREBASE_API_ACCESS_KEY' );
$registrationIds = array( $_GET['id'] ); //You may put on array >1 registrationIds
// prep the bundle
$msg = array
(
'body' => $_GET['body'],
'title' => $_GET['title'],
'sound' => 'granules', //this is the notification sound name
);
$fields = array
(
'registration_ids' => $registrationIds,
'notification' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment