<?php
/**
 * Created by PhpStorm.
 * User: Joseg
 * Date: 30/4/2018
 * Time: 9:30 PM
 */


class Notificacion
{
    public function individual($mensaje,$token){
    $url = 'https://fcm.googleapis.com/fcm/send';
    $fields = array (
            'registration_ids' => array (
                    $token
            ),
            'data' => array (
                    "message" => $mensaje
            )
    );
    $fields = json_encode ( $fields );
    $headers = array (
            'Authorization: key=' . "AAAAoeoKC4U:APA91bGkEePNdEO5iJyuEP3nKbV7Fl0YJCHMqcsmsLjD5-bJJwnehjkhEXd21pV-y_In7gS02kERW1wTArWdCjgzpFB2cfyc_5OasxhuQvuN3XDlEaNX9OW_P97xcCswMlMC_czzN7ys",
            '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 );
    }

    public function grupal($mensaje, $tokens){
        $arreglo = $tokens;
            $url = 'https://fcm.googleapis.com/fcm/send';
    $fields = array (
            'registration_ids' => $arreglo,
            'data' => array (
                    "message" => $mensaje
            )
    );
    $fields = json_encode ( $fields );
    $headers = array (
            'Authorization: key=' . "AAAAoeoKC4U:APA91bGkEePNdEO5iJyuEP3nKbV7Fl0YJCHMqcsmsLjD5-bJJwnehjkhEXd21pV-y_In7gS02kERW1wTArWdCjgzpFB2cfyc_5OasxhuQvuN3XDlEaNX9OW_P97xcCswMlMC_czzN7ys",
            '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 );
    }


}