<?php
//Define Fcm class
class Firebase {
    public $API_SERVER_KEY = '';
    private static $is_background = "TRUE";
    public function __construct() {

    }
    public function sendPushNotificationToFCMSever($token, $message, $notifyID,$title) {
        #API access key from Google API's Console
        if (!defined('API_ACCESS_KEY')) define( 'API_ACCESS_KEY', "AAAAX0xaOZI:APA91bHJVxLeoWswzRGNZSrcW0ZaDpiJxNEmMRAPcFflnoQZqA-niUWWy4dRft7vPGvDpkq29Wnc5bjuIvRSFB-Vn0aRE7d_5Zta_olt2h0iqtI2fpV1dJWjzUXuvkFFHlAjJjQfAAcG" );
        #prep the bundle

        $msg = array
        (
            'body' 	=> $message,
            'title'	=> $title,
            'icon'	=> 'myicon',/*Default Icon*/
            'sound' => 'mySound',/*Default sound*/
            'click_action'=> "com.genovatechnologies.smartbuild.ui.home.NotificationActivity"
        );
        $fields = array
        (
            'to'		=> $token,
            'notification'	=> $msg,
            'data'  => $msg,
            'title'=> $title,
            'priority'=> 'high',
            'click_action'=> "com.genovatechnologies.smartbuild.ui.home.NotificationActivity"
        );
        $headers = array
        (
            'Authorization: key=' . API_ACCESS_KEY,
            'Content-Type: application/json'
        );
        #Send Reponse To FireBase Server
        $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_SSL_VERIFYPEER, false );
        curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
        $result = curl_exec($ch );
        curl_close( $ch );
        #Echo Result Of FireBase Server
        return $result;
    }
}
