Skip to content

Instantly share code, notes, and snippets.

@laptrinhcomvn
Last active February 26, 2018 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laptrinhcomvn/d8e8e5ee396ff01dbc861646e9f4ada4 to your computer and use it in GitHub Desktop.
Save laptrinhcomvn/d8e8e5ee396ff01dbc861646e9f4ada4 to your computer and use it in GitHub Desktop.
<?php
// API access key from Google API's Console; change to cloud messaging tab to get the server token
define( 'API_ACCESS_KEY', 'YOUR_FIREBASE_API_ACCESS_KEY' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
(
'body' => $_GET['body'],
'title' => $_GET['title'],
'vibrate' => 1,
'sound' => 1,
);
// custom sound should be existing in res/raw/notification.mp3
$msg = array
(
'body' => $_GET['body'],
'title' => $_GET['title'],
'vibrate' => 1,
'sound' => 'notification',
);
$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