File: //var/www/html/taxicamera/pmw_live_testing/old/application/libraries/PushNotification.php
<?php
class PushNotification {
private $CI;
function __construct() {
$this->CI =& get_instance();
}
public function send_android_notification($fcmtoken,$data) {
$url = "https://fcm.googleapis.com/fcm/send";
$token = $fcmtoken;
$serverKey = 'AIzaSyCbdlmTvYnFJYCDX0BtuWnIMqZ4yGFfQm0';
$title = $data['title'];
$body = $data['message'];
$notification = array('title' =>$title , 'text' => $body, 'sound' => 'default', 'badge' => '1');
$arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high');
$json = json_encode($arrayToSend);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key='. $serverKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
//Send the request
$response = curl_exec($ch);
//Close request
//print_r($response); die;
if ($response === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
}
public function send_ios_notification($fcmtoken,$data){
$url = "https://fcm.googleapis.com/fcm/send";
$token = $fcmtoken;
$serverKey = 'AAAA5hwBGCw:APA91bHEJFIHAomMiZmgpdWJ72pMVyE8RH-Z5fu7okAuYJBsNTSgPGirdQWZfLOvjuQ2dvWCYiwQp_5Kz664U7mSVFghVhnwCmNnA4VrfJLm7ZpU8ppln--mvD7pVSa-R6JlvUs1aXkL';
$title = $data['title'];
$body = $data['message'];
$notification = array('title' =>$title , 'text' => $body, 'sound' => 'default', 'badge' => '1');
$arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high');
$json = json_encode($arrayToSend);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key='. $serverKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
//Send the request
$response = curl_exec($ch);
//Close request
//print_r($response); die;
if ($response === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
}
public function getAllDeviceList(){
$query=$this->CI->db->get('devices');
return $query->result_array();
}
}
?>