Skip to content

Instantly share code, notes, and snippets.

@The-LoneWolf
Last active August 12, 2018 07:55
Show Gist options
  • Save The-LoneWolf/9d7ce92ea4c86d20837825e4b2ed6987 to your computer and use it in GitHub Desktop.
Save The-LoneWolf/9d7ce92ea4c86d20837825e4b2ed6987 to your computer and use it in GitHub Desktop.
<?php
public function push($user_id, $message)
{
define('API_ACCESS_KEY', '');
define('SENDER_ID', '');
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Sender: id=' . SENDER_ID,
'Content-Type: application/json; charset=utf-8'
);
$fcmMsg = array(
'text' => ($message),
'title' => ('title'),
'sound' => "default",
'color' => "#203E78"
);
$fields = array(
'to' => $singleID->firebase_token,
'priority' => 'high',
'data' => $fcmMsg
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://android.googleapis.com/gcm/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);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment