level51/silverstripe-onesignal

OneSignal PHP SDK 的 Silverstripe 模块包装器

安装: 182

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:silverstripe-vendormodule

1.0.0 2020-11-02 00:00 UTC

This package is auto-updated.

Last update: 2024-08-29 05:31:14 UTC


README

Build Status Scrutinizer Code Quality Code Coverage License: MIT

Silverstripe 模块包装器,用于 OneSignal PHP SDK。

提供 OneSignalService 类以创建/发送通知。使用便利类 NotificationNotificationResponse 处理请求和响应有效负载。

需求

  • 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() 提供受支持的 区域设置

维护者