CristalT
1/7/2020 - 4:39 PM

Curl Request

$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);