HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //var/www/html/pmw24/driver_settlement/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();   

		} 

	}

?>