Skip to content

Instantly share code, notes, and snippets.

@umuieme
Created March 4, 2019 17:06
Show Gist options
  • Save umuieme/014f55d3443030ad086cdf4cf6ae386a to your computer and use it in GitHub Desktop.
Save umuieme/014f55d3443030ad086cdf4cf6ae386a to your computer and use it in GitHub Desktop.
function sendNotifiction($title, $message){
$header = array(
"authorization: key=YOUR_FIREBASE_KEY",
"content-type: application/json",
);
$data = array
(
'title' => $title,
'message' => $message,
);
$body = array
(
'data' => $data,
'to' => '/topics/test',
);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode($body),
CURLOPT_HTTPHEADER => $header,
));
$response = json_decode(curl_exec($curl));
$err = curl_error($curl);
$success = (isset($response->message_id));
curl_close($curl);
return $success;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment