kedu / onesignal-laravel
该软件包最新版本(1.0.2)没有可用的许可证信息。
OneSignal的Laravel框架包装器。
1.0.2
2020-11-10 00:08 UTC
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ^6.3@dev
- illuminate/support: 4.*|5.*|6.*|7.*|8.*
Requires (Dev)
- itsgoingd/clockwork: ~1.10
- mockery/mockery: ^1.0
- phpmd/phpmd: @stable
- phpunit/phpunit: ^5.7|6.2|^7.0
- squizlabs/php_codesniffer: 3.*
This package is auto-updated.
Last update: 2024-09-10 08:53:31 UTC
README
使用OneSignal轻松发送推送通知 OneSignal
内容
安装
要将Laravel OneSignal添加到您的项目中,只需添加
composer require kce/onesignal-laravel
Composer自动发现将注册提供者。如果不使用它,请将以下行添加到“config/app.php”
'providers' => [
...
.
.
KCE\OneSignal\OneSignalServiceProvider::class
]
...
.
.,
'aliases' => [
...
..
.
'OneSignalClient' => KCE\OneSignal\Facades\OneSignalClient::class
]
发布配置
php artisan vendor:publish --provider="KCE\OneSignal\OneSignalServiceProvider"
使用
配置
此软件包需要您更改“config/onesignal.php”文件中的字段
return array ( /* |-------------------------------------------------------------------------- | One Signal App Id |-------------------------------------------------------------------------- | | You can find in : Project > Settings > Key & ID's > ONESIGNAL APP ID | */ 'app_id' => env("ONESIGNAL_APP_ID", 'default_app_id'), /* |-------------------------------------------------------------------------- | Rest API Key |-------------------------------------------------------------------------- | | You can find in : Project > Settings > Key & ID's > REST API KEY | */ 'rest_api_key' => env("ONESIGNAL_REST_API_KEY", 'rest_api_key'), /* |-------------------------------------------------------------------------- | User Auth Key |-------------------------------------------------------------------------- | | You can find in : Profile > ACCOUNT & API KEYS > AUTH KEY | */ 'user_auth_key' => env("ONESIGNAL_USER_AUTH_KEY", 'user_auth_key'), );
发送给所有人
向所有订阅设备发送通知
\KCE\OneSignal\Facades\OneSignalClient::sendToAll('Notification message');
发送到国家
向特定国家发送通知
\KCE\OneSignal\Facades\OneSignalClient::sendToCountry('Notification message', 'TR'); // Country ISO Code
发送到位置
向特定区域发送通知。使用米为单位测量半径
\KCE\OneSignal\Facades\OneSignalClient::sendToLocation('Notification message', 10000, 37.4247, 41.33933); // Use Lat, Long and Radius
向单个用户或用户发送
向玩家ID发送通知
\KCE\OneSignal\Facades\OneSignalClient::sendToUser('Notification message', "player_id"); // Single player id
或
\KCE\OneSignal\Facades\OneSignalClient::sendToUser('Notification message', ["player_id1", 'player_id2]); // Multiple player ids
发送到分段
向一个或多个分段发送通知
\KCE\OneSignal\Facades\OneSignalClient::sendToSegment('Notification message', "segment"); //or \KCE\OneSignal\Facades\OneSignalClient::sendToSegment('Notification message', ["segment", "segment2"]);
发送到标签
通过标签筛选通知
\KCE\OneSignal\Facades\OneSignalClient::sendToTags('Notification message', ["user_id", "=", 15]); //will send the notification to user that tagges as user_id 15
向通知添加数据和/或标题
\KCE\OneSignal\Facades\OneSignalClient::setTitle("Notification Title")->setData([ 'key' => 'value' ])->sendToAll("Example Message");
调度
您可以安排在未来的日期和时间发送通知。
\KCE\OneSignal\Facades\OneSignalClient::setSchedule("2018-10-29 10:00")->sendToAll("Cumhuriyet Bayramı Kutlu Olsun!");
基于用户的时区调度
通知将在每个用户自己的时区中的特定时间发送。
\KCE\OneSignal\Facades\OneSignalClient::scheduleByUserTimezone("04:44PM")->sendToAll("This message will deliver based on user timezone on 04:44PM!");
addTag / addOrTag
如果您使用addTag或addTags方法,它将在标签之间放置AND。如果您想使用具有“OR”连接器的多个标签,则应使用addOrTag方法。
$client = app('onesignal'); $client->addTag(['fav_color', 'green'])->addOrTag(['fav_color', 'red'])->sendToAll("Users like yellow or red");
通过首次/最后会话发送
通常过滤器有3个参数(键,关系,值),但某些过滤器(如last_session,first session)有自己的值键。您可以添加特定的值键作为第四个参数。如果您想通过用户的最后或首次活跃时间发送通知,则可以使用通过值键的addFilter方法。
$client = app('onesignal'); $client->addFilter('last_session', '>', '48', 'hours_ago')->sendToAll("Notification by last active"); // Users who last session time more than 48 Hours. $client->addFilter('last_session', '<', '48', 'hours_ago')->sendToAll("Notification by last active"); // Users who last session time less than 48 Hours. $client->addFilter('first_session', '>', '48', 'hours_ago')->sendToAll("Notification by last active"); // Users who first session time more than 48 Hours. $client->addFilter('first_session', '<', '48', 'hours_ago')->sendToAll("Notification by last active"); // Users who last session time less than 48 Hours.
多语言通知
默认通知语言为英语。但如果你想,你可以向每个用户发送通知,使用他们自己的语言。只需将语言 => 消息数组作为消息添加到任何发送方法中。
$client = app('onesignal'); $client ->setTitle([ 'en' => 'English Title', 'tr' => 'Türkçe Başlık', ]) ->sendToAll([ 'en' => 'English notification message', 'tr' => 'Türkçe bildirim mesajı' ]);
更多选项
您可以使用方法链...
$client = app('onesignal'); $client->addTag(['user_id', 15)->addTag('notifiable', 1)->setTitle("Test Notif")->sendToAll("New Message");
许可证
Laravel OneSignal是免费软件,根据MIT许可证的条款分发。
请随时发送pull请求。