laravel-notification-channels/pushwoosh
Composer 安装命令:
composer require laravel-notification-channels/pushwoosh
包简介
Pushwoosh notification channel for Laravel
README 文档
README
This package makes sending notifications using Pushwoosh a breeze.
Contents
Requirements
This make use of this package you need:
- Laravel 5.5 or higher
- PHP 7.1 or higher
- An active Pushwoosh subscription (and use at least one Pushwoosh SDK)
Installation
To install this package run the following command:
composer require laravel-notification-channels/pushwoosh
Next, add the following lines to your config/services.php:
'pushwoosh' => [ 'application' => env('PUSHWOOSH_APP_CODE'), 'token' => env('PUSHWOOSH_TOKEN'), ],
You can now add the PUSHWOOSH_APP_CODE (found here) and the
PUSHWOOSH_TOKEN (found here) to your environment file.
Usage
Using this package, you can use Pushwoosh just like any other notification channel within Laravel. For more information about Laravel's notification system, see the official documentation.
Note that before you can start sending pushes you must first register users to your application using one of Pushwoosh's SDKs.
Routing notifications
In order for Pushwoosh to know to what devices it needs to send to, you will need to add the
routeNotificationForPushwoosh to your notifiable model(s), for example:
class Customer extends Model { use Notifiable; public function routeNotificationForPushwoosh() { // In this example 'device_id' is a token previously // retrieved from Pushwoosh using one of their SDKs return (new PushwooshRecipient)->device($this->device_id); } }
The routeNotificationForPushwoosh method may return a string, an array of strings or a PushwooshRecipient instance.
For more information about the PushwooshRecipient class refer to the available methods section.
Sending notifications
Sending a pushwoosh message is easy, add pushwoosh to your notification's via method and implement the toPushwoosh
method, for example:
class WishlistItemOnSale extends Notification { public function via($notifiable) { return ['pushwoosh']; } public function toPushwoosh($notifiable) { return (new PushwooshMessage) ->content('Your wishlist item ' . $this->product->name . ' is on sale, get it now!') ->url(route('products.show', $this->product)) ->deliverAt(Carbon::now()->addMinutes(10)); } }
The
toPushwooshmethod may return a string or an instance of thePushwooshMessageclass, for more information on thePushwooshMessageclass refer to the available methods section.
You can then send a push to one user:
$customer->notify(new WishlistItemOnSale($product));
Or to multiple users:
Notification::send($customers, new WishlistItemOnSale($product));
Unknown devices
When you reference devices that do not exist (anymore), a NotificationChannels\Pushwoosh\Events\UnknownDevices event
will be dispatched.
You can easily hook into this event like so:
Event::listen( NotificationChannels\Pushwoosh\Events\UnknownDevices::class, function ($event) { // Handle the event } );
Available methods
This section details the public API of this package.
PushwooshMessage
Below is a list of available methods on the PushwooshMessage class.
| Method | Description |
|---|---|
campaign($campaign) |
Set the Pushwoosh campaign code |
content($content[, $language]) |
Set the message content (optionally for a specific language) |
deliverAt($when[, $timezone]) |
Set the delivery moment |
identifier($identifier) |
Set the Pushwoosh unique identifier (defaults to the notification ID) |
preset($preset) |
Set the Pushwoosh preset code |
throttle($limit) |
Throttle the rollout (100-1000 pushes per second) |
title($title) |
Set the message title (only on Chrome, Firefox, iOS and Safari) |
url($url[, $shorten]) |
Set the URL the message should link to |
useRecipientTimezone() |
Respect the recipients' timezone when delivering the message |
with($key, $value[, $platform]) |
Add a root level parameter. |
PushwooshRecipient
Below is a list of available methods on the PushwooshRecipient class.
| Method | Description |
|---|---|
device($device[, ...]) |
Limit the delivery to the given device(s) |
platform($platform[, ...]) |
Limit the delivery to the given platform(s) |
user($user[, ...]) |
Limit the delivery to the given user(s) |
within($lat, $lng, $range) |
Limit the delivery to the given geo zone |
Platforms
Below is a list of supported platforms, for the PushwooshRecipient::platform method.
- Amazon
- Android
- Blackberry
- Chrome
- Firefox
- iOS
- Mac
- Safari
- Windows
- Windows Phone
Changelog
Please see the changelog for more information on what has changed recently.
Testing
composer test
Contributing
If you want to contribute to this package, take a look at the contribution guide.
Credits
License
This product is licensed under the MIT License (MIT). Please see the License File for more information.
laravel-notification-channels/pushwoosh 适用场景与选型建议
laravel-notification-channels/pushwoosh 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39.53k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 laravel-notification-channels/pushwoosh 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravel-notification-channels/pushwoosh 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 39.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-09-26