PHP code example of carloswgama / php-onesignal

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

    

carloswgama / php-onesignal example snippets


composer 

{
    "  "carloswgama/php-onesignal": "1.*"
    }
}
 php

OneSignal\OneSignal;
use CWG\OneSignal\Device;

$appID = '92b9c6bb-89d2-4cbc-8862-a80e4e81a251';
$authorizationRestApiKey = 'MWRjMTg2MjEtNTBmYS00ODA4LWE1M2EtM2YyZjU5ZmRkNGQ5';

$api = new OneSignal($appID, $authorizationRestApiKey);

//Criando o Dispositivo
$retorno = $api->device->setLanguage('pt')
                ->setIdentifier('12312312313')
                ->setDevice(Device::ANDROID)
                ->addTag('matricula', '11111111')
                ->addTag('curso', '12312312')
                ->addTag('turma', '1111')
                ->create();


print_r($retorno);
 php

OneSignal\OneSignal;
use CWG\OneSignal\Device;

$appID = '92b9c6bb-89d2-4cbc-8862-a80e4e81a251';
$authorizationRestApiKey = 'MWRjMTg2MjEtNTBmYS00ODA4LWE1M2EtM2YyZjU5ZmRkNGQ5';
$deviceID = '69aeecc1-7b58-44d1-8000-7767de437adf';

$api = new OneSignal($appID, $authorizationRestApiKey);

//Novas informações do Dispositivo
$retorno = $api->device->setLanguage('pt')
                ->setIdentifier('12312312313')
                ->setDevice(Device::ANDROID)
                ->addTag('matricula', '11')
                ->update($deviceID);


print_r($retorno);
 php

neSignal\OneSignal;

$appID = '92b9c6bb-89d2-4cbc-8862-a80e4e81a251';
$authorizationRestApiKey = 'MWRjMTg2MjEtNTBmYS00ODA4LWE1M2EtM2YyZjU5ZmRkNGQ5';

$api = new OneSignal($appID, $authorizationRestApiKey);


//Enviando notificação para todo mundo
$retorno = $api->notification->setBody('Ola')
                            ->setTitle('Titulo')
                            ->send();
print_r($retorno);
 php

neSignal\OneSignal;

$appID = '92b9c6bb-89d2-4cbc-8862-a80e4e81a251';
$authorizationRestApiKey = 'MWRjMTg2MjEtNTBmYS00ODA4LWE1M2EtM2YyZjU5ZmRkNGQ5';

$api = new OneSignal($appID, $authorizationRestApiKey);


//Enviando notificação para quem usa tag categorias esporte ou natação
$retorno = $api->notification->setBody('Ola')
                            ->setTitle('Titulo')
                            ->addTag('categoria', 'esporte')
                            ->addTag('categoria', 'natacao')
                            ->send();
print_r($retorno);
 php

neSignal\OneSignal;

$appID = '92b9c6bb-89d2-4cbc-8862-a80e4e81a251';
$authorizationRestApiKey = 'MWRjMTg2MjEtNTBmYS00ODA4LWE1M2EtM2YyZjU5ZmRkNGQ5';
$deviceID = '69aeecc1-7b58-44d1-8000-7767de437adf';
$api = new OneSignal($appID, $authorizationRestApiKey);


//Enviando notificação para um dispositivo
$retorno = $api->notification->setBody('Ola')
                            ->setTitle('Titulo')
                            ->addDevice($deviceID)
                            ->send();