PHP code example of juniorlemes / fcm-php-http-v1

1. Go to this page and download the library: Download juniorlemes/fcm-php-http-v1 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

juniorlemes / fcm-php-http-v1 example snippets




$FCMPHP = new \FCMPHP\FCMPHP([
    'fcm_server_key' => '{server-key}'
]);

$FCMNotification = new \FCMPHP\FCMNotification();

$FCMNotification->setTitle('{push-title}');
$FCMNotification->setBody('{push-description}');
$FCMNotification->setPriority('{push-priority}'); //high or normal
$FCMNotification->setDevices([ 
     '{device-id}'
    ,'{device-id}'
]); //One or more devices

$request = $FCMPHP->send($FCMNotification);

//Http error
if($request->getHttpStatusCode() != 200){
    $code = $request->getHttpStatusCode();
    $body = $request->getBody();
}

//One or more failure on send push to FCM
if($failure = $request->hasFailure()){
    $count = $failure['count'];
    $error = $failure['error'];
}