Skip to content

Instantly share code, notes, and snippets.

@cse031sust02
Created January 24, 2018 11:23
Show Gist options
  • Save cse031sust02/9005d454a60f53d765ac9f22409ae858 to your computer and use it in GitHub Desktop.
Save cse031sust02/9005d454a60f53d765ac9f22409ae858 to your computer and use it in GitHub Desktop.
Send push notification using Firebase
<?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();
@os-kingsley
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment