surushchand / onesignal-notification
一个简单的PHP库,用于使用OneSignal服务列出和发送推送通知
1.0
2022-03-18 12:33 UTC
README
安装
composer require sureshchand/onesignal-notification
示例
初始设置
<?php require "vendor/autoload.php"; $api_id = 'API_ID'; $rest_api_key = 'REST_API_KEY'; $pushNotification = new \Suresh\Onesignal\Notification($api_id, $rest_api_key);
创建通知
发送给所有订阅者
<?php $pushNotification->setBody('English Message') ->setSegments('All') ->prepare() ->send();
发送给特定细分市场
<?php $pushNotification->setBody('English Message') ->setSegments('Active Users') ->prepare() ->send();
基于过滤器/标签发送
<?php $pushNotification->setBody('English Message') ->setFilter([ ['field' => 'tag', 'key' => 'level', 'relation' => '>', 'value' => '10'], ['operator' => 'OR'], ['field' => 'amount_spent', 'relation' => '>', 'value' => '0'] ]) ->prepare() ->send();
基于OneSignal PlayerIds发送
<?php $pushNotification->setBody('English Message') ->setPlayersId([ 'PLAYER_ID', 'ANOTHER_PLAYER_ID' ]) ->prepare() ->send();