Last active
February 26, 2018 18:19
-
-
Save laptrinhcomvn/d8e8e5ee396ff01dbc861646e9f4ada4 to your computer and use it in GitHub Desktop.
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 | |
// 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