File: /var/www/nclive/technc/push_notifications.php
<?php
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
function sendMessage($title, $message, $url, $app_url)
{
$content = array(
"en" => $message
);
$headings = array(
"en" => $title
);
$fields = array(
'app_id' => "d83058f0-1d20-4f2f-9853-159d136c735a",
'included_segments' => array(
'All'
),
'data' => array(
"foo" => "bar"
),
'contents' => $content,
'headings' => $headings,
'web_url' => $url,
'app_url' => $app_url,
'chrome_web_icon' => 'http://staging.naukriconnect.org/images/ncsignal_icon.png'
);
$fields = json_encode($fields);
//print("\nJSON sent:\n");
//print($fields);
//echo $fields;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic ODViNGE0OWQtMDU1YS00NzY1LWFmZGYtMDFhNjNjOGQxMTJl'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
?>