Skip to content

Instantly share code, notes, and snippets.

@CristalT
Created January 7, 2020 16:39
Show Gist options
  • Save CristalT/bcda52bfe1943e6e24855ccd2830849e to your computer and use it in GitHub Desktop.
Save CristalT/bcda52bfe1943e6e24855ccd2830849e to your computer and use it in GitHub Desktop.
$ch = curl_init();
$options = [
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_ENCODING => "", // handle compressed
CURLOPT_USERAGENT => "test", // name of client
CURLOPT_AUTOREFERER => true, // set referrer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // time-out on connect
CURLOPT_TIMEOUT => 120, // time-out on response
CURLOPT_URL => 'https://fcm.googleapis.com/fcm/send',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($msg),
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: key=' . $apiKey
]
];
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
if (curl_errno($ch)) {
return ['error' => true, 'message' => curl_error($ch)];
}
curl_close($ch);
return json_decode($content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment