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/old/application/libraries/Notification.php
<?php
	class Notification { 
		private $CI;
		function __construct() {
	       $this->CI =& get_instance();
   		}
		public function send_android_notification($registration_ids, $data) { 
		        //echo json_encode($data); die;
			    $fields = array(
				  'registration_ids' => array($registration_ids),
				  'data'=> $data,
			    );
				$headers = array(
		      	  'Authorization: key=AAAAHL-YUGw:APA91bESO1wFFK-r2wNsUf1ajZLRK14eOe2HX3WSZ4CSfDbkUKeBhkMyXisXR6_f8ZUJKhsGnHyC142KLy3zvVzwkZrXoTK20XgL6UclNhNosiQ9LngO4akvnus4q2HyeR1AHiftDx8F', // FIREBASE_API_KEY_FOR_ANDROID_NOTIFICATION
		          'Content-Type: application/json'
		      );
			  // Open connection
			  $ch = curl_init();
			  // Set the url, number of POST vars, POST data
			  curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
			  curl_setopt( $ch,CURLOPT_POST, true );
			  curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); 
			  curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
			  // Disabling SSL Certificate support temporarly
			  curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
			  //echo json_encode( $fields );exit;
			  curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
			  // Execute post
			  $result = curl_exec($ch );
		      //echo $result ; die; 
			  $response=0;
			  if($result === false){
		    	  //die('Curl failed:' .curl_errno($ch));
				   $response=0;
			  }else{
			       $response=1;
				  // Close connection
				  //curl_close( $ch );
			  }
			  curl_close( $ch );
			  return $response;
		}
		public function send_ios_notification($devicetoken,$data){ 
			 	 //$passphrase='met123';
			 	 $passphrase='123';
				 $deviceToken = $devicetoken;    
				 $ctx = stream_context_create();
			     // ck.pem is your certificate file ssl://gateway.sandbox.push.apple.com:2195  PushDistCertificates ssl://gateway.push.apple.com:2195
			     //stream_context_set_option($ctx, 'ssl', 'local_cert', './public/PushDevelopmentCertificates.pem');
			    //ssl://gateway.sandbox.push.apple.com:2195
			    //stream_context_set_option($ctx, 'ssl', 'local_cert', './public/PushDevCertificates.pem');
			     stream_context_set_option($ctx, 'ssl', 'local_cert', './public/PushLiveAdvantage.pem');
			    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 
			    // Open a connection to the APNS server 
			    $fp = stream_socket_client(
			   		'ssl://gateway.push.apple.com:2195', $err,
			   		$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
			  	if (!$fp){ 
			   		//exit("Failed to connect: $err $errstr" . PHP_EOL);
			   		return 0; 
			  	}else{
			   		// Create the payload body
			   		$body['aps'] = array(
						 'alert' => array(
							 'title' => 'Advantagecard',
							 'body' => $data['message'],
						  ),
						 'sound' => 'default',
						 'data'=>$data
			   		);
				   // Encode the payload as JSON
				   $payload = json_encode($body);
				   // Build the binary notification
				   $msg = chr(0) . pack('n', 32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack('n', strlen($payload)) . $payload;  //
				   //$msg = chr(0) . pack('n', 32) . pack('H*',str_replace(' ', '', sprintf('%u', CRC32($deviceToken)))) . pack('n', strlen($payload)) . $payload;   
				   //str_replace(' ', '', sprintf('%u', CRC32($deviceToken)))
				   //$msg = chr(0) . pack('n', 32) . pack('H*', str_replace(' ', '', sprintf('%u', CRC32($deviceToken)))) . pack('n', strlen($payload)) . $payload
				   // Send it to the server
				   $result = fwrite($fp, $msg, strlen($msg));
				   // Close the connection to the server
				   fclose($fp);
				   if (!$result){
						//return 'Message not delivered' . PHP_EOL;
						return 0; 
				   }else{
						//return  'Message successfully delivered' . PHP_EOL; 
						return 1;
				   }
			  } 
		}
		public function getAllDeviceList(){
			$query=$this->CI->db->get('devices');
			return $query->result_array();   
		} 
	}
?>