Skip to content

Instantly share code, notes, and snippets.

@ikishanoza
Created October 31, 2018 07:05
Show Gist options
  • Save ikishanoza/e9064cd5e553ab507805dbcf0d713a18 to your computer and use it in GitHub Desktop.
Save ikishanoza/e9064cd5e553ab507805dbcf0d713a18 to your computer and use it in GitHub Desktop.
<?php
class PushNotification {
// function to send push notification
function push_notification($user_device_tokens, $push_message, $title = "Demo Adventure") {
$api_key_access = '********************'; // API KEY for push notification
$headers = array('Authorization: key=' . $api_key_access, 'Content-Type: application/json');
$msg = array(
"title" => "Notification title",
"body" => "Notification body",
"sound" => "default",
"click_action" => "FCM_PLUGIN_ACTIVITY",
"icon" => "fcm_push_icon"
);
$temp = array(
"a" => "b",
"b" => "c"
);
$fields = array(
'registration_ids' => $user_device_tokens,
'notification' => $msg,
'data' => $temp
);
//var_dump($fields);die;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
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);
echo $result;
}
}
$pushObj = new PushNotification();
// Here is the array of extra parameters which we will receive on notification clicked/received
$device_tokens = array("evQ91cyEM1w:************************");
$push_message = "Testing of firebase push notification 8866319427 www";
$push_title = "";
$pushObj->push_notification($device_tokens, $push_message, $push_title);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment