Skip to content

Instantly share code, notes, and snippets.

@isfaaghyth
Created September 24, 2018 12:36
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 isfaaghyth/526b9104543e8c4bb38dd93be623d475 to your computer and use it in GitHub Desktop.
Save isfaaghyth/526b9104543e8c4bb38dd93be623d475 to your computer and use it in GitHub Desktop.
Send GCM
<?php
function sendFirebaseNotification($threat, $id) {
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = [
'to' => $id,
'data' => [
"caption" => $threat->caption,
"browser" => $threat->browser,
"capture" => $threat->capture,
"children_id" => $threat->children_id
]
];
$fields = json_encode ($fields);
$headers = [
'Authorization: key=' . "YOUR_KEY_HERE",
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);
echo $result;
curl_close ($ch);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment