<?php
function push_notification_php($titulo, $cuerpo) {
$url = 'https://fcm.googleapis.com/fcm/send';
/* authorization_key */
$authorization_key = 'place here yours';
$fields = array(
'to'=>'/topics/general',
'priority'=>'high',
'data'=>array(
'title'=>$titulo,
'body'=> $cuerpo
)
);
$fields = json_encode($fields);
$headers = array (
'Content-Type: application/json',
'Authorization:key=' . $authorization_key
);
$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_POSTFIELDS, $fields);
$result = curl_exec($ch);
curl_close($ch);
if (strpos($result, 'message_id') !== FALSE) {
return true;
}
else {
return false;
}
}
?>