PHP code example of sureshchand / onesignal-notification

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

    

sureshchand / onesignal-notification example snippets


composer 


_id = 'API_ID';
$rest_api_key = 'REST_API_KEY';

$pushNotification = new \Suresh\Onesignal\Notification($api_id, $rest_api_key);


$pushNotification->setBody('English Message')
                 ->setSegments('All')
                 ->prepare()
                 ->send();


$pushNotification->setBody('English Message')
                 ->setSegments('Active Users')
                 ->prepare()
                 ->send();


$pushNotification->setBody('English Message')
                 ->setFilter([
                     ['field' => 'tag', 'key' => 'level', 'relation' => '>', 'value' => '10'],
                     ['operator' => 'OR'],
                     ['field' => 'amount_spent', 'relation' => '>', 'value' => '0']
                 ])
                 ->prepare()
                 ->send();


$pushNotification->setBody('English Message')
                 ->setPlayersId([
                    'PLAYER_ID',
                    'ANOTHER_PLAYER_ID' 
                 ])
                 ->prepare()
                 ->send();