PHP code example of danielprrazevedo / fcm-php

1. Go to this page and download the library: Download danielprrazevedo/fcm-php 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/ */

    

danielprrazevedo / fcm-php example snippets




$FCMPHP = new \FCMPHP\FCMPHP(array(
    '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(array(
     '{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'];
}