laravel-notification-channels/pusher-push-notifications
Composer 安装命令:
composer require laravel-notification-channels/pusher-push-notifications
包简介
Pusher native Push Notifications driver.
README 文档
README
This package makes it easy to send Pusher Beams push notifications with Laravel.
Please note that this notification channel should not be confused with Pusher Channels.
Also please note that prior to version 2.0, this package integrated with Pusher's beta push notifications service that was part of Pusher Channels. Please see Pusher's migration guide for more information.
Contents
Installation
You can install the package via composer:
composer require laravel-notification-channels/pusher-push-notifications
Setting up your Pusher account
Before using this package you should set up a Pusher Beams account. Here are the steps required.
- Login to https://dash.pusher.com/
- Select the "Beams" product.
- Select your instance from the list or create a new instance.
- Click on the "Settings" tab.
- Upload your APNS Certificate and/or add your FCM Server key.
- Now select the "Keys" tab.
- Copy your
Instance Id, andSecret Key. - Add a new entry to in your
config/services.phpfile:'pusher' => [ 'beams_instance_id' => 'Your Instance Id', 'beams_secret_key' => 'Your Secret Key', ],
- You're now good to go.
Usage
Now you can use the channel in your via() method inside the Notification class.
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!"); } }
Available Message methods
platform(''): Accepts a string value ofiOS,Androidorweb.iOS(): Sets the platform value to iOS.android(): Sets the platform value to Android.web(): Sets the platform value to web.link(): Accepts a string value which will lead to URI specified on notification click.title(''): Accepts a string value for the title.body(''): Accepts a string value for the body.sound(''): Accepts a string value for the notification sound file. Notice that if you leave blank the default sound value will bedefault.icon(''): Accepts a string value for the icon file. (Android Only)badge(1): Accepts an integer value for the badge. (iOS Only)setOption($key, $value): Allows you to set any value in the message payload. See the request body section of the Pusher Beam docs for more information.
Sending to multiple platforms
You can send a single message to an iOS device and an Android device at the same time using the withiOS() and withAndroid() method:
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') ); }
- Notice that iOS is the default platform, which means you don't have to call
->iOS().- When using
withAndroid(),withiOS()orwithWeb()you don't have to define the platform, it's done behind the scenes for you.
Routing a message
By default, the pusher "interest" messages will be sent to will be defined using the {notifiable}.{id} convention, for example App.User.1,
however you can change this behaviour by including a routeNotificationFor() in the notifiable class.
I.e. if you are pushing notification on User model, you can go to App\Models\User class and implement method:
public function routeNotificationForPusherPushNotifications($notification): string { return 'your.custom.interest.string'; }
PusherPushNotifications() in the notifiable class method returns the interest name.
Publish to users
You can publish to users in the same way that you publish to interests but you must add the following variable to the notifiable model:
class Client extends Model
{
use Notifiable;
public $pushNotificationType = 'users';
}
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Security
If you discover any security related issues, please email themsaid@gmail.com instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
laravel-notification-channels/pusher-push-notifications 适用场景与选型建议
laravel-notification-channels/pusher-push-notifications 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 784.42k 次下载、GitHub Stars 达 281, 最近一次更新时间为 2016 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notifications」 「laravel」 「pusher」 「pusher-push-notifications」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 laravel-notification-channels/pusher-push-notifications 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravel-notification-channels/pusher-push-notifications 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 laravel-notification-channels/pusher-push-notifications 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
Standalone PHP library for easy devices notifications push.
Module handling the real time notifications
Pusher Beams is a push notification service from Pusher.
Captures outgoing SMS notifications
Send push notification to android|ios devices , support APNs, FCM
统计信息
- 总下载量: 784.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 282
- 点击次数: 27
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-10