level51 / silverstripe-onesignal
OneSignal PHP SDK 的 Silverstripe 模块包装器
1.0.0
2020-11-02 00:00 UTC
Requires
- norkunas/onesignal-php-api: ^2.1
- nyholm/psr7: ^1.3
- silverstripe/framework: ^4
- symfony/http-client: ^5.1
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-08-29 05:31:14 UTC
README
Silverstripe 模块包装器,用于 OneSignal PHP SDK。
提供 OneSignalService
类以创建/发送通知。使用便利类 Notification
和 NotificationResponse
处理请求和响应有效负载。
需求
- Silverstripe ^4.0
- OneSignal PHP SDK
norkunas/onesignal-php-api
- PSR-18 HTTP 客户端(例如
symfony/http-client
) - PSR-17 HTTP 工厂(例如
nyholm/psr7
)
安装
composer require level51/silverstripe-onesignal
文档
该模块基于 OneSignal PHP API。
目前,仅使用 Notifications API。
本项目遵守 PSR-2。
配置
初始化 OneSignalService
时,必须提供两个环境变量和一个配置值。OneSignalException
将在配置不正确时抛出。
环境
在您的 .env
文件中定义以下变量。
ONESIGNAL_AUTH_KEY
(在账户/个人资料级别定义)ONESIGNAL_APP_AUTH_KEY
由于认证密钥是敏感数据,建议不要将它们包含在任何 VCS 中。
配置 API
app_id
示例
Level51\OneSignal\OneSignalService: app_id: 'xxxxxx-0000-xxxx-0000-xxxxxxxxxx'
用法
发送简单的通知。
try { $notification = Notification::create() ->addHeading('en', 'My first notification') ->addContent('en', 'Yay, my Silverstripe app created this') ->addData('myVar', 'foo'); $response = OneSignalService::singleton()->createNotification($notification); if (!$response->isError()) { echo 'Notification with id ' . $response->getId() . ' was sent to ' . $response->getRecipientsCount() . ' recipients'; } } catch (OneSignalException $e) {}
确保为 addHeading()
和 addContent()
提供受支持的 区域设置。
维护者
- Julian Scheuchenzuber js@lvl51.de