Skip to content

Instantly share code, notes, and snippets.

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 Nikoloutsos/7973398574fd4742635a42497b999809 to your computer and use it in GitHub Desktop.
Save Nikoloutsos/7973398574fd4742635a42497b999809 to your computer and use it in GitHub Desktop.
Send push notification from firebase to android device
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