PHP code example of namnv609 / php-onesignal-sdk

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

    

namnv609 / php-onesignal-sdk example snippets


$players = $player->all();

foreach ($players->response->players as $player) {
    echo $player->id . PHP_EOL;
}

use NNV\OneSignal\OneSignal;

$oneSignal = new OneSignal(<User Auth key> [, <App ID>, <App REST key>, <Extra options for GuzzleHttp Client>])

use NNV\OneSignal\API\App;

$app = new App($oneSignal);

$app->all();

$app->get("<App ID>");

$appData = [
    'name' => '<App name>',
    'apns_env' => 'sandbox',
];

$app->create($appData);

$appData = [
    'apns_env' => 'production',
];

$app->update("<App ID>", $appData);

use NNV\OneSignal\API\Player;

$player = new Player($oneSignal [, <App ID>, <App REST key>]);

$player->all([<Limit>, <Offset>]);

$player->get("<Player ID>");

use NNV\OneSignal\Constants\DeviceTypes;

$playerData = [
    'language' => 'en',
    'tags' => [
        'for' => 'bar',
        'this' => 'that'
    ]
];

$player->create(DeviceTypes::CHROME_WEBSITE, $playerData);

use NNV\OneSignal\Constants\NotificationTypes;
use NNV\OneSignal\Constants\TestTypes;

$playerData = [
    'test_type' => TestTypes::DEVELOPMENT,
    'notification_types' => NotificationTypes::UNSUBSCRIBED
];

$player->update("<Player ID>", $playerData);

$sessionData = [
    'tags' => [
        'new' => 'session',
    ],
];
$player->onSession("<Player ID>", $sessionData);

$purchaseData = [
    'sku' => 'SKU123',
    'iso' => 'USD',
    'amount' => '0.99',
];

$player->onPurchase("<Player ID>", $purchaseData, [<Is existing>]);

$focusData = [
    'state' => 'ping',
    'active_time' => 1,
];

$player->onFocus("<App ID>", $focusData);

$extraFields = ['rooted'];

$player->csvExport($extraFields);

use NNV\OneSignal\API\Notification;

$notification = new Notification($oneSignal[, <App ID>, <App REST key>]);

$notificationData = [
    '  'en' => 'Hello, world',
    ],
    'headings' => [
        'en' => 'Hello',
    ],
    'buttons' => [
        [
            'id' => 'button_id',
            'text' => 'Button text',
            'icon' => 'button_icon',
        ],
    ],
    'filters' => [
        [
            'field' => 'tag',
            'key' => 'level',
            'relation' => '>',
            'value' => '10',
        ],
    ],
    'send_after' => 'Sep 24 2017 14:00:00 GMT-0700',
    'isChromeWeb' => true,
];

$notification->create($notificationData);

$notification->cancel("<Notification ID>");

$notification->get("<Notification ID>");

$notification->all([<Limit>, <Offset>]);

$notification->trackOpen("<Notification ID>");