<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Notifications{

	function __constructor()
	{

	}

	function sendFCM($KEY, $message, $id) {
	    //return 'hello';exit;

            $url = 'https://fcm.googleapis.com/fcm/send';
            
            $notification = array('title' =>$message['title'] , 'body' => $message['body'], 'sound' => 'default', 'badge' => '1');
    $arrayToSend = array('to' => $id, 'notification' => $notification,'priority'=>'high');
    $fields = json_encode($arrayToSend);
    //print_r($fields);
    //echo $KEY;exit;

//            $fields = array (
//                    'registration_ids' => array (
//                            $id
//                    ),
//                    'data' => array (
//                            "message" => $message,
//                            'message_info' => $message_info,
//                    ),                
//                    'priority' => 'high',
//                    'notification' => array(
//                                'title' => $message['title'],
//                                'body' => $message['body'],                            
//                    ),
//            );
//            $fields = json_encode ( $fields );
            
            $headers = array (
                    'Authorization: key=' . $KEY,
                    'Content-Type: application/json'
            );
            $ch = curl_init ();
            curl_setopt ( $ch, CURLOPT_URL, $url );
            curl_setopt ( $ch, CURLOPT_POST, true );
            curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
            curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
            curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
            $result = curl_exec ( $ch );
            curl_close ( $ch );
            return $result;
        }
        
       
}
?>