<?php 

include '../../conn.php';
include 'message.php';


$message=$_GET['message'];
$recevier=$_GET['recevier']; 
$sender=$_GET['sender']; 

$resultdata =$con->query("select * from `doctors` where phone='$recevier'");
$fcmtoken=null;


while($row = mysqli_fetch_array($resultdata)){
    $fcmtoken=$row['fcmToken'];
     

    
$data = array("to" => $fcmtoken,
                  "notification" => array( "code"=> $chatcodefcm,"title" => "$titlefcm", "body" => $message,"icon" => $logofcm),
                  "data"=>array("code"=> $chatcodefcm, "key1"=> $sender,"key2"=> $message )
                  );                                                                    
            $data_string = json_encode($data); 
            
             "The Json Data : ".$data_string; 
            
            $headers = array
            (
                 'Authorization: key=' . API_ACCESS_KEY, 
                 'Content-Type: application/json'
            );                                                                                 
                                                                                                                                 
            $ch = curl_init();  
            
            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 );
            curl_setopt( $ch,CURLOPT_POSTFIELDS, $data_string);                                                                  
                                                                                                                                 
            $result = curl_exec($ch);
}
?>