smileythane / laravel-apn-notification-channel
Laravel 6使用的Apple推送通知服务(APNs)通知通道,采用基于令牌的新APNs HTTP/2协议(使用JWT和p8私钥)
v1.2.0
2021-08-09 11:48 UTC
Requires
- php: ^7.2
- edamov/pushok: ^0.10
- illuminate/notifications: ~5.3|~5.4|~5.5|~5.6|~5.7|~5.8|^6.0
- illuminate/support: ~5.1|~5.2|~5.3|~5.4|~5.5|~5.6|~5.7|~5.8|^6.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^8.4
- squizlabs/php_codesniffer: ^3.4
This package is auto-updated.
Last update: 2024-09-09 18:49:00 UTC
README
此包使您能够轻松使用Laravel 6通过新的APNs HTTP/2协议和基于令牌的方式(使用JWT和p8私钥)向iOS发送通知。
内容
功能
- 使用新的Apple APNs HTTP/2连接
- 支持基于JWT的身份验证
- 支持基于证书的身份验证
- 支持新的iOS 10功能,如Collapse IDs、Subtitles和可变通知
- 使用并发请求到APNs
- 已在APNs生产环境中测试并工作
要求
- PHP >= 7.2
- lib-curl >= 7.46.0(启用http/2支持)
- lib-openssl >= 1.0.2e
安装
使用Composer安装此包
composer require SmileyThane/laravel-apn-notification-channel
如果您在Laravel 5.4或更低版本中安装此包,必须导入服务提供程序
// config/app.php 'providers' => [ // ... SmileyThane\ApnNotificationChannel\ApnServiceProvider::class, ],
设置APN服务
将凭证添加到您的 config/broadcasting.php
如果您使用JWT身份验证
// config/broadcasting.php 'connections' => [ ... 'apn' => [ 'driver' => 'jwt', 'is_production' => env('APP_ENV') === 'production', 'key_id' => env('APN_KEY_ID'), // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/authkey/) 'team_id' => env('APN_TEAM_ID'), // The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/) 'app_bundle_id' => env('APN_APP_BUNDLE_ID'), // The Bundle ID of your application. For example, "com.company.application" 'private_key_path' => env('APN_PRIVATE_KEY', storage_path('apns-private-key.p8')), 'private_key_secret' => env('APN_PRIVATE_KEY_SECRET'), ], ... ],
如果您使用基于证书的身份验证
// config/broadcasting.php 'connections' => [ ... 'apn' => [ 'driver' => 'certificate', 'is_production' => env('APP_ENV') === 'production', 'app_bundle_id' => env('APN_APP_BUNDLE_ID'), // The Bundle ID of your application. For example, "com.company.application" 'certificate_path' => env('APN_CERTIFICATE_PATH', storage_path('apns-certificate.pem')), 'certificate_secret' => env('APN_CERTIFICATE_SECRET'), ], ... ],
使用方法
现在您可以在通知中的 via() 方法中使用该通道
use Illuminate\Notifications\Notification; use SmileyThane\ApnNotificationChannel\ApnMessage; class AccountApproved extends Notification { /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['apn']; } /** * Get the APN representation of the notification. * * @param mixed $notifiable * @return ApnMessage */ public function toApn($notifiable) { return ApnMessage::create() ->badge(1) ->title('Account approved') ->body("Your {$notifiable->service} account was approved!"); } }
在您的 notifiable 模型中,请确保包含一个 routeNotificationForApn() 方法,该方法返回一个或多个设备令牌。
/** * Route notifications for the APN channel. * * @return string|array */ public function routeNotificationForApn() { return $this->apn_token; }
可用的消息方法
title($str)subtitle($str)body($str)badge($int)sound($str)category($str)launchImage($str)threadId($str)
安全
如果您发现任何与安全相关的问题,请通过电子邮件 semyon.chetvertnyh@gmail.com 而不是使用问题跟踪器。
贡献
有关详细信息,请参阅 CONTRIBUTING
致谢
许可证
MIT许可证(MIT)。请参阅 许可证文件 以获取更多信息。