mirovit/onesignal

OneSignal API 的 PHP 封装。

0.0.3 2019-06-23 16:23 UTC

README

Build Status

OneSignal API

参考 - [https://documentation.onesignal.com/reference](OneSignal 文档)。

仍在开发中。

安装

使用 Composer

composer require mirovit/onesignal

贡献

欢迎贡献,对我来说最重要的是表达式的语法,并在某些时候我写完测试 - 测试。

使用方法

此包使用流畅的语法,因此非常易于阅读和理解底层代码。

<?php

require __DIR__ . '/vendor/autoload.php';

// By default, if a token is not passed in the constructor,
// the class will try to load the token from
// ONESIGNAL_API_KEY environment variable. The second param,
// the API endpoint is set as default value to
// https://onesignal.com/api/v1, which is the current endpoint:
$sdk = new Mirovit\OneSignal\OneSignal();
// or explicitly them:
$sdk = new Mirovit\OneSignal\OneSignal(
    'rest api key',
    'api endpoint'
);

// Retrieve player
$user = $sdk
            ->players()
            ->get('player-id', ['app_id' => 'app-id']);

可用端点

players()

<?php
// https://documentation.onesignal.com/reference
$sdk
    ->players()
    ->all();

// https://documentation.onesignal.com/reference#view-device
$sdk
    ->players()
    ->get('player-id', ['app_id' => 'app-id']);

// https://documentation.onesignal.com/reference#edit-device
$sdk
    ->players()
    ->update([
        // required
        'id'      => 'player-id',
        'app_id'     => 'app-id',
        // optional
        'identifier'      => '',
        'language'  => '',
        'test_type' => 1,
        // ... and more
    ]);

notifications()

<?php
// https://documentation.onesignal.com/reference#create-notification
$sdk
    ->notifications()
    ->create([
        'app_id'   => 'app-id',
         'filters'  => (new \Mirovit\OneSignal\Filters())
             ->tag('key', 'value')
             ->orWhere()
             ->tag('key', 'relation', 'value')
             ->country('bg')
             ->email('test@test.com'),
         'contents' => [
             'en' => 'test',
         ],
     ]);