PHP code example of getmo / smartpush-php-connector

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

    

getmo / smartpush-php-connector example snippets


$platforms = ['IOS', 'ANDROID', 'WINDOWS', 'CHROME', 'SAFARI', 'FIREFOX'];

use Smartpush\Push;
use Smartpush\Notification; // optional, use only if you will consult data from server

$push = new Push(string $devid, string $when = 'now', string $alias = '');

$push->setEnvironment(string $envinronment = '1'); # This method return $this, so you can chain it.

$this; # so you can chain methods! 

$push->addNotification(string $appid, string $platform, array $params);
# or
$push->addNotification(string $appid, string $platform, object $params);

$this; # so you can chain methods! 

$notifications = $push->getNotifications();
foreach ($notifications as $notification) {
    echo $notification->appid;
    echo $notification->platform;
    var_dump($notification->params);
}

array; # of objects 

$push->setFilterRange(string $range);

$this; # so you can chain methods! 

$push->setFilterOperator(string $operator);

$this; # so you can chain methods! 

$push->addTag(string $key, string $value);
# or
$push->addTag(string $key, string $comparator, string $value);

$this; # so you can chain methods! 

$tags = $push->getTags();
foreach ($tags as $tag) {
    var_dump($tags);
}

array; # of tags 

var_dump($push->getPayload()); # array
# or
var_dump($push->getPayload(true)); # JSON string

'{...}' || array; # JSON string or array

if ($push->send()) {
    # ...
} else {
    # ...
}

true || false;

$result = $push->getResult();
$data = json_decode($result);
echo $data->pushid;

'{...}'; # JSON string

$info = $push->getInfo(string $pushid);
$data = json_decode($info);

var_dump($data->notifications); # array of information about all notifications of this push.
foreach ($data->notifications as $notification) {
    echo $notification->appid;
    echo $notification->status;
    # if push was sent the follow property will be available.
    echo $notification->sent_at;
}
...
# if push was configured to be sent at a future moment in time, this two properties will be available.
echo $data->{'time-left'};
echo $data->date;

'{...}'; # JSON string

$push->cancel(string $pushid);
# or
$info = $push->cancel(string $pushid);
# Here, $info get the same result as getInfo() mention above.

'{...}'; # JSON string

$push->hide(string $pushid);
# or
$info = $push->hide(string $pushid);
# Here, $info get the same result as getInfo() mention above.

'{...}'; # JSON string

$notification = new Notification(string $devid, string $appid, string $platform);

$result = $notification->getLastNotifications(string $hwid, array $options);

'{...}'; # JSON string

$result = $notification->getLastUnreadNotifications(string $hwid, array $options);

'{...}'; # JSON string

$result = $notification->getExtraPayload(string $pushid);

'{...}'; # JSON string

$notification->readOneNotification(string $hwid, string $pushid);

$notification->readAllNotifications(string $hwid);

$notification->hideHwidNotification(string $hwid, string $pushid);
shell
composer 
array
array
array
array