Created
January 24, 2018 11:23
-
-
Save cse031sust02/9005d454a60f53d765ac9f22409ae858 to your computer and use it in GitHub Desktop.
Send push notification using Firebase
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 | |
use GuzzleHttp; | |
$access_token = 'FIREBASE CLOUD MESSAGING SERVER KEY'; | |
$reg_id = 'DEVICE REGISTRATION ID'; | |
$message = [ | |
'notification' => [ | |
'title' => 'Test Message', | |
'body' => "This is a test!" | |
], | |
'to' => $reg_id | |
]; | |
$client = new GuzzleHttp\Client([ | |
'headers' => [ | |
'Content-Type' => 'application/json', | |
'Authorization' => 'key='.$access_token, | |
] | |
]); | |
$response = $client->post('https://fcm.googleapis.com/fcm/send', | |
['body' => json_encode($message)] | |
); | |
echo $response->getBody(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks