clementblanco / pusher-push-notifications
Pusher 原生推送通知驱动程序。
1.1.0
2018-11-16 14:50 UTC
Requires
- php: >=5.6.4
- illuminate/events: 5.3.* || 5.4.* || 5.5.* || 5.6.*
- illuminate/notifications: 5.3.* || 5.4.* || 5.5.* || 5.6.*
- illuminate/queue: 5.3.* || 5.4.* || 5.5.* || 5.6.*
- illuminate/support: 5.3.* || 5.4.* || 5.5.* || 5.6.*
- pusher/pusher-php-server: 3.*
Requires (Dev)
- mockery/mockery: ^0.9.5
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2024-09-17 10:01:06 UTC
README
此包简化了使用 Laravel 5.3 - 5.6 发送 Pusher 推送通知的过程。
内容
安装
您可以通过 composer 安装此包。
composer require clementblanco/pusher-push-notifications:^1.0
您必须安装服务提供者。
// config/app.php 'providers' => [ ... NotificationChannels\PusherPushNotifications\PusherPushNotificationsServiceProvider::class, ],
设置 Pusher 账户
在开始使用此包之前,您应设置 Pusher 账户。以下是所需步骤。
- 登录到 https://dashboard.pusher.com/
- 从侧边栏选择您的应用或创建一个新应用。
- 点击“推送通知”选项卡。
- 上传您的 APNS 证书或添加您的 GCM API 密钥。
- 现在选择“应用密钥”选项卡。
- 复制您的
app_id
、key
和secret
。 - 更新
config/broadcasting.php
文件中 pusher 连接下的值。 - 现在您可以开始了。
用法
现在您可以在通知类中的 via()
方法中使用该频道。
use NotificationChannels\PusherPushNotifications\PusherChannel; use NotificationChannels\PusherPushNotifications\PusherMessage; use Illuminate\Notifications\Notification; class AccountApproved extends Notification { public function via($notifiable) { return [PusherChannel::class]; } public function toPushNotification($notifiable) { return PusherMessage::create() ->iOS() ->badge(1) ->sound('success') ->body("Your {$notifiable->service} account was approved!"); } }
可用的消息方法
platform('')
: 接受字符串值iOS
或Android
。iOS()
: 将平台值设置为 iOS。android()
: 将平台值设置为 Android。title('')
: 接受用于标题的字符串值。body('')
: 接受用于正文的字符串值。sound('')
: 接受用于通知声音文件的字符串值。请注意,如果留空,则默认声音值为default
。icon('')
: 接受用于图标文件的字符串值。(仅限 Android)badge(1)
: 接受用于徽章的整数值。(仅限 iOS)setOption($key, $value)
: 允许您在消息有效负载中设置任何值。有关更多信息,请参阅iOS或Android。
发送到多个平台
您可以使用 withiOS()
和 withAndroid()
方法同时向 iOS 设备和 Android 设备发送单个消息。
public function toPushNotification($notifiable) { $message = "Your {$notifiable->service} account was approved!"; return PusherMessage::create() ->iOS() ->badge(1) ->body($message) ->withAndroid( PusherMessage::create() ->title($message) ->icon('icon') ); }
- 请注意,iOS 是默认平台,这意味着您不需要调用
->iOS()
。- 当使用
withAndroid()
或withiOS()
时,您不需要定义平台,它将在幕后为您完成。
路由消息
默认情况下,Pusher 的“兴趣”消息将使用 {notifiable}.{id} 约定定义,例如 App.User.1
,但是您可以通过在可通知类中包含一个返回兴趣名称的 routeNotificationForPusherPushNotifications()
方法来更改此行为。
更新日志
有关最近更改的更多信息,请参阅更新日志。
测试
$ composer test
安全
如果您发现任何安全相关的问题,请通过电子邮件themsaid@gmail.com而不是使用问题跟踪器。
贡献
有关详细信息,请参阅贡献。
致谢
许可证
麻省理工学院许可协议(MIT)。请参阅许可文件获取更多信息。