<?php
include 'connection.php';
define('API_ACCESS_KEY','AAAAVIY7yQ8:APA91bFaDlKO4dORVjZJ3FBSttKWC8ImLFRSbGjBLeLIugF7a1IClxtRWKjjWLV75fvTLluLbozvPNDzdzoBssANzNLdSOa0WLZ1zMd_mPorjHXHp4C8LVMPM_vwtKwolYSgEb_frGRz');
 $fcmUrl = 'https://fcm.googleapis.com/fcm/send';

$token='d_zP8fQiRz-HG1zOQgepTu:APA91bEpuUoe3hnAgPlTb-0GBnpGd3ecQM0fV6KMAEvtVJ-VL10cMFaV931g74qYmcdbU2oi7r9RJXGqvYAMW9dMIg-qAOkafUpmzgpy3VTNSVZ4hFVQwl4kVTB_TmVSOA4wGnmpr2Ze';
//  $query = "SELECT token from n_b_d_token";
	$result = mysqli_query($conn,$query);
	$tokens = array();
	if(mysqli_num_rows($result) > 0 ){
		while ($row = mysqli_fetch_assoc($result)) {
			$tokens[] = $row["token"];
		}
	}

	// mysqli_close($conn);

     $notification = [
            'title' =>'server',
            'body' => 'test of message.',
            'icon' =>'myIcon', 
            'sound' => 'mySound'
        ];
     //   $extraNotificationData = ["message" => $notification,"moredata" =>'dd'];
     $extraNotificationData = ["message" =>'hello madi',"moredata" =>'dd'];

        $fcmNotification = [
           // 'registration_ids' => $tokens, //multple token array
            'to'        => $token, //single token
            'notification' => $notification,
            'data' => $extraNotificationData
        ];

        $headers = [
            'Authorization: key=' . API_ACCESS_KEY,
            'Content-Type: application/json'
        ];

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$fcmUrl);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
        $result = curl_exec($ch);
        curl_close($ch);

       // echo $result;
        ?>