namnv609 / php-onesignal-sdk
此包已被弃用且不再维护。未建议替代包。
OneSignal RESTful API 的 PHP SDK
v1.0.1
2017-07-03 03:22 UTC
Requires
- php: >=5.5
- guzzlehttp/guzzle: ^6.1
- symfony/options-resolver: ^3.2
Requires (Dev)
- mykehowells/dotenv: ^1.0
- psy/psysh: ^0.7
- symfony/var-dumper: ^3.0
This package is not auto-updated.
Last update: 2021-11-05 06:24:53 UTC
README
OneSignal 是一个为网站和移动应用提供高容量和可靠的推送通知服务。我们通过为每个平台提供专门的 SDK、RESTful 服务器 API 和营销人员的在线仪表板来支持所有主要原生和移动平台,以便设计并发送推送通知。
系统要求
- PHP >= 5.5
安装
使用 Composer composer require namnv609/php-onesignal-sdk
或者你可以在你的 composer.json
中包含以下内容 "namnv609/php-onesignal-sdk": "1.0"
响应格式
{"status":true,"code":200,"response":<OneSignal result>}
status
: 布尔型。true
或false
(状态码为 200 或其他)code
: 整数。状态码response
: 混合型。你可以查看每个 API 的 OneSignal 结果详情,请访问:https://documentation.onesignal.com/reference
$players = $player->all(); foreach ($players->response->players as $player) { echo $player->id . PHP_EOL; }
使用说明
首先,创建一个新的 OneSignal
实例以配置库以供使用。
use NNV\OneSignal\OneSignal; $oneSignal = new OneSignal(<User Auth key> [, <App ID>, <App REST key>, <Extra options for GuzzleHttp Client>])
一旦注册了 OneSignal
实例,你可以这样使用它
应用
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);
玩家(设备)
玩家(设备)正文参数: 创建、更新、新会话、新购买、增加会话时长 和 CSV 导出
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);
- CSV 导出
$extraFields = ['rooted']; $player->csvExport($extraFields);
通知
通知正文参数: 创建
use NNV\OneSignal\API\Notification; $notification = new Notification($oneSignal[, <App ID>, <App REST key>]);
- 创建通知
$notificationData = [ 'included_segments' => ['All'], 'contents' => [ '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>");