PHP code example of khrizt / push-notiphications

1. Go to this page and download the library: Download khrizt/push-notiphications 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/ */

    

khrizt / push-notiphications example snippets


use Khrizt\PushNotiphications\Client\Fcm;
use Khrizt\PushNotiphications\Collection\Collection;
use Khrizt\PushNotiphications\Model\Device;
use Khrizt\PushNotiphications\Model\Fcm\Message as FcmMessage;

$fcmMessage = new FcmMessage();
$fcmMessage->setBody($message)
           ->setTitle($title);

$device = new Device($token);
$collection = new Collection();
$collection->append($device);

$client = new Fcm($apiKey);
$responseCollection = $client->send($fcmMessage, $collection);

foreach ($responseCollection as $response) {
    echo 'Status for notification sent to '.$response->getToken().' was '.($response->isOk() ? 'OK' : ' Error. Error message: '.$response->getErrorMessage());
}


use Khrizt\PushNotiphications\Client\Apns;
use Khrizt\PushNotiphications\Collection\Collection;
use Khrizt\PushNotiphications\Constants;
use Khrizt\PushNotiphications\Model\Device;
use Khrizt\PushNotiphications\Model\Apns\Message as ApnsMessage;

$apnsMessage = new ApnsMessage();
$apnsMessage->setBody($message)
            ->setTopic($topic);

$device = new Device($token);
$collection = new Collection();
$collection->append($device);

$client = new Apns(Constants::DEVELOPMENT, $certificate, $certificatePassphrase);
$responseCollection = $client->send($apnsMessage, $collection);

foreach ($responseCollection as $response) {
    echo 'Status for notification sent to '.$response->getToken().' was '.($response->isOk() ? 'OK' : '. Error message: '.$response->getErrorMessage());
}