PHP code example of sinergy84 / push-notification-php-library

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

    

sinergy84 / push-notification-php-library example snippets




use PushNotification\Service\PushService;
use PushNotification\Settings;

$data = array(
    'device' => array(
        'name' => '', // Android or AppleIOS
        'token' => '', // device token | user token , if you want to send to apple device you have to fill this 
        'id' => 'unique id here'),

    'message' => array(
        'action' => 'test',
        'title' => 'this is test title',
        'targets' => array(''), // if you want to use Fcm you can inclue array of targets 
        'body' => 'this is body',
        'type' => '', // AndroidMessages or IOSMessages
        'data' => array('type' => 'testType'))
);

// new Settings('path_to_env_file_if_not_library_root_dir');
new Settings();
$response  = PushService::getInstance()->send($data);




use PushNotification\Service\PushService;

$data = array(
    'device' => array(
        'name' => 'Android',  
        'token' => '', 
        'id' => 'some id here '),

    'message' => array(
        'action' => 'test',
        'title' => 'this is test title',
        'targets' => array('token1', 'token2', 'token3'),
        'body' => 'this is body',
        'type' => 'AndroidMessages',  
        'data' => array('type' => 'testType'))
);

// new Settings('path_to_env_file_if_not_library_root_dir');
new Settings();
$response  = PushService::getInstance()->send($data);
print_r($response);




use PushNotification\Service\PushService;

$data = array(
    'device' => array(
        'name' => 'AppleIOS',
        'token' => 'token',
        'id' => 'BECDSx'),

    'message' => array(
        'action' => 'test',
        'title' => 'this is test title',
        'targets' => array(),
        'body' => 'this is body',
        'type' => 'IOSMessages', 
        'data' => array('type' => 'testType'))
);

// new Settings('path_to_env_file_if_not_library_root_dir');
new Settings();
$response  = PushService::getInstance()->send($data);
print_r($response);