Created
September 24, 2018 12:36
-
-
Save isfaaghyth/526b9104543e8c4bb38dd93be623d475 to your computer and use it in GitHub Desktop.
Send GCM
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
<?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