Created
November 20, 2020 22:56
-
-
Save Nikoloutsos/7973398574fd4742635a42497b999809 to your computer and use it in GitHub Desktop.
Send push notification from firebase to android device
This file contains 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
const GOOGLE_API_KEY = "XXXXX"; | |
const GOOGLE_GCM_URL = "https://fcm.googleapis.com/fcm/send"; | |
$fields = array( | |
'to' => $device_token, | |
'sound' => 'default', | |
'priority' => 'high', | |
'data' => array("title" => $this-title, | |
"message" => $this->message // You may add more data | |
) | |
); | |
$headers = array( | |
self::GOOGLE_GCM_URL, | |
'Content-Type: application/json', | |
'Authorization: key='.self::GOOGLE_API_KEY | |
); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, self::GOOGLE_GCM_URL); | |
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment