<?php
    /*function sendGCM($message, $id) {


    $url = 'https://fcm.googleapis.com/fcm/send';

    $fields = array (
            'registration_ids' => array (
                    $id
            ),
            'notification' => array (
                    "title" => "Nuevo servicio",
                    "body" => "Hola"
            ),
            'data' => array(
                "message" => $message
            )
    );
    $fields = json_encode ( $fields );

    $headers = array (
            'Authorization: key=' . "AAAAgsyK5Eo:APA91bEr7X8FnRRO3KT5HUgvSUWqLSQJ1MechwBjhn3xWT1oaYO33zaZofmWkj44dnw4UBNEXK_UJII7eZB4Em1CiUEK01kXeh3WdGqTduMF_iMsYNW2hMZCiy48yZbiSF4qFTtVSZ_c",
            '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 );
    echo $result;
    curl_close ( $ch );
}

sendGCM("hola mundo", "cN9GnwTEJEl7q0neHpC7tv:APA91bFsa2o7tFbTTKjmi2Rea-BoFaQ6-kSbe4-PipjbvvMWmGbCg87HBQG8BDZWP9KX3XSw7jls_a0k5iyto5FNFqT3uRkogm9lZosGQrqfbJworZ6zoaont43w1ZXXBnliL2glw3XK");*/

include_once('../gapiclient/vendor/autoload.php');

$client = new Google_Client();

$client->setAuthConfig('dreamersfactory-bf800-b1067d8786fc.json');
$client->addScope('https://www.googleapis.com/auth/firebase.messaging');
$client->useApplicationDefaultCredentials();
$token = $client->fetchAccessTokenWithAssertion();
$accessToken = $token['access_token'];

$projectId = 'dreamersfactory-bf800';

/*$message = [
 'token' => 'dfmbZ389Hk5akh5fWcIinH:APA91bH6GPzaJlujPRJynXFGF1SQXDuux4qxH1yj_wLRJ3YXnBLtCHqXLa6tcJLPOR24OUXfReoTY7c8Nu5_A-FKAXIU5Pn014BhfbXbyxumVW4WvwSBEVlNP9dW-HEfDxgWH7wUqOG9',
 'notification' => [
 'title' => 'Hello',
 'body' => 'World',
 'priority' => 'high',
 'android' => [
        'notification' => [
                'sound' => 'default'
            ],
        'priority' => 'high',
     ],
  'apns' => [
        'header' => [
             'apns-priority'=>'1'
            ],
        'payload' => [
                'aps' => [
                        'sound' => 'default',
                        'alert' => [
                                'title' => 'Hello',
                                'body' => 'World'
                            ],
                        'badge' => '2'
                    ]
            ]
      ],
 ],
];*/

$message = 
[
    'message' => [
         'token' => 'dfmbZ389Hk5akh5fWcIinH:APA91bH6GPzaJlujPRJynXFGF1SQXDuux4qxH1yj_wLRJ3YXnBLtCHqXLa6tcJLPOR24OUXfReoTY7c8Nu5_A-FKAXIU5Pn014BhfbXbyxumVW4WvwSBEVlNP9dW-HEfDxgWH7wUqOG9',
         'notification' => [
             'title' => 'Hello',
             'body' => 'World',
             ],
         'android' => [
              'priority' => 'high'
             ],
         'apns' => [
              'headers' => [
                   'apns-priority' => '10'
                  ]
             ],
    ]
];



echo json_encode($message);



$url = 'https://fcm.googleapis.com/v1/projects/' . $projectId . '/messages:send';
  $headers = [
   'Authorization: Bearer ' . $accessToken,
   'Content-Type: application/json',
   ];
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($message));
  $response = curl_exec($ch);
   if ($response === false) {
   throw new Exception('Curl error: ' . curl_error($ch));
   }
  curl_close($ch);
  print_r(json_decode($response, true));




?>