Skip to content

Instantly share code, notes, and snippets.

@serhatsezer
Created January 11, 2017 12:36
Show Gist options
  • Save serhatsezer/02adc1cf723dd524d9fd71712dae940b to your computer and use it in GitHub Desktop.
Save serhatsezer/02adc1cf723dd524d9fd71712dae940b to your computer and use it in GitHub Desktop.
<?php
// deneme notif gönder
// ilk parametre kullanıcıdan alınan token
// ikinci başlık
// üçüncü mesaj body
$rs = send_notification(array("eVvDD-zglFo:APA91bEW_KCwpC2vZ4Gndrr4Lk5rYXOMPaCTxC8wwqr6EVIKIixAHuikVM1vTryCCxg2vylikWdQgCBT3WRTun3_-h3glYHVETReQ1-jz9Xt2HtvfoZlOgqQJrYfEoaWqzrPYJje6Qw7"),
array("message" => "Denemee",
"title" => "titleee"));
echo $rs;
function send_notification ($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = AAAAxXgjeBM:APA91bEaJD9yZhbp_oBCI0v4mw2K_349ArAyFDH9Bkb2fiyfvBMlQzlQJM0YGe_wPI-Es45miqF1khqf5XJeLBsXyHBF6C8TzgxWNG82_0bAQuLUNuzscV8cGsFPlTUnVbcFdtIoM5IAhapn1aCPYOZUrcLTKSUfjA',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment