conceptho/yii2-onesignal

用于OneSignal.com集成的Yii2组件

0.1.0 2020-07-09 23:34 UTC

This package is auto-updated.

Last update: 2024-09-10 09:04:07 UTC


README

用于OneSignal.com集成的Yii2组件。任何贡献都受到高度鼓励!

此组件是 rocketfirm/yii2-onesignal 的分支。

安装

推荐通过 Composer 进行安装。

composer require romulo1984/yii2-onesignal

配置

将以下代码添加到您的配置文件(main.php)中

'components' => [
  // ...

  'onesignal' => [
    'appId' => 'ONESIGNAL_APP_ID',
    'apiKey' => 'ONESIGNAL_API_KEY',
  ]
]

用法

运行以下命令以发送通知

$message = [
  "headers" => [
    "en" => "Notification Example"
  ],
  "contents" => [
    "en" => "Click for more info"
  ]
];

$options = [
  "template_id" => "your-template-id",
  "url" => "https://github.com/romulo1984/yii2-onesignal"
];

$filterOne = ["field" => "tag", "key" => "your_tag_here", "relation" => "=", "value" => "your_tag_value_here"];
$filterOne = ["field" => "tag", "key" => "your_tag_here", "relation" => "=", "value" => "your_tag_value_here"];

$notification = \Yii::$app->onesignal->notifications()->create($message["headers"], $message["contents"], $options);
$notification->filter($filterOne);
$notification->operatorOr();
$notification->filter($filterTwo);

$notification->send();

其他方法

// Notifications
\Yii::$app->onesignal->notifications()->getAll($params);
\Yii::$app->onesignal->notifications($id)->getOne();

//Players (device)
\Yii::$app->onesignal->players()->getAll($params);
\Yii::$app->onesignal->players($id)->getOne();
\Yii::$app->onesignal->players($id)->edit($params);
\Yii::$app->onesignal->players($id)->addTag($tagName, $tagValue);
\Yii::$app->onesignal->players($id)->addTag($tagsArray);
\Yii::$app->onesignal->players($id)->removeTag($tagName);

访问官方 onesignal.com 文档 以获取更多详细信息。