Created
January 7, 2020 16:39
-
-
Save CristalT/bcda52bfe1943e6e24855ccd2830849e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$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