<?php
 
 sendToAndroid("body wit hsoundsdsd","title wit hsound",$sPostID = '',"eVutHC2yBbk:APA91bH3Y_UN14V64fff4mve3Lsoywe2mrXpxyGalLM89oH8Jbhw4Y8JNHZhrA5VE5ZemvyVMbqta7VdOuHTkI13slJgWqdlzSdr1dLEy098kv2_I5b4Jkd27xbixBKJR3EWQlb6JDsd");


function sendToAndroid($sAlert,$sTitle,$sPostID = '',$sToken){
	$path_to_fcm = "https://fcm.googleapis.com/fcm/send";
	$server_key = "AAAAK_zKfvo:APA91bG94AYxo-sZ2Sge_cWgh7iZp3GWSIicELEoSkspwPnxDgAGfzo0lILgwbhZMeKH844xgHlmRc1GOTxpzxmQ3PwyBr8SU6J52_qS7Zk1vqoWAa7IvXaK4k6Y1i5ERdn7BMsZ6etm";

	$header = array(
				'Authorization:key=' . $server_key,
				'Content-Type: application/json'
	);
	
	
	$exdeviceIDsArr = explode(',',$sToken);
	$deviceIDsArr =  array_values(array_unique(array_filter($exdeviceIDsArr)));
	$input_deviceIDs = array_chunk($deviceIDsArr, 950);/// split array into 950 each

	foreach($input_deviceIDs as $array_deviceIDs){
		$fields = array(
					'registration_ids' => $array_deviceIDs,
					'notification' => array(
						'title' => $sTitle, 
						'body' => $sAlert,
						"priority" => "high",
						"force-start" => 1,
						"sound" => "default",
						"vibrate" => "true",
						"icon" => "icon"
					)	
		);


		$ch = curl_init();
		curl_setopt( $ch,CURLOPT_URL, $path_to_fcm );
		curl_setopt( $ch,CURLOPT_POST, true );
		curl_setopt( $ch,CURLOPT_HTTPHEADER, $header );
		curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
		curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
		curl_setopt( $ch,CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
		curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode($fields, true));
		$result = curl_exec($ch );
		curl_close( $ch );
		//$resultArr = (array) json_decode($result);
		echo "<pre>";print_r($result);
	}
}


die;


 
?>
