silverd / laravel-apn-notification-channel
使用基于令牌的(JWT与p8私钥)的新APNs HTTP/2协议的Laravel 6 Apple推送通知服务(APNs)通知通道
v1.1.0
2020-04-11 20:09 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-18 04:47:06 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 silverd/laravel-apn-notification-channel
如果您在Laravel 5.4或更低版本中安装此包,您必须导入服务提供者
// config/app.php 'providers' => [ // ... SemyonChetvertnyh\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', 'certificate_path' => env('APN_CERTIFICATE_PATH', storage_path('apns-certificate.pem')), 'certificate_secret' => env('APN_CERTIFICATE_SECRET'), ], ... ],
用法
现在您可以在通知中的via()方法中使用该通道
use Illuminate\Notifications\Notification; use SemyonChetvertnyh\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)custom($key, $value)setCustom($array)titleLocKey($str)titleLocArgs($array)actionLocKey($str)setLocKey($str)setLocArgs($array)launchImage($str)contentAvailability($bool)mutableContent($bool)threadId($str)
待办事项
- 修复Travis CI
- 修复Scrutinizer CI代码覆盖率
- 添加测试
更新日志
请参阅更新日志以获取更多有关最近更改的信息。
测试
$ composer test
安全
如果您发现任何安全相关的问题,请通过电子邮件semyon.chetvertnyh@gmail.com联系,而不是使用问题跟踪器。
贡献
有关详细信息,请参阅贡献。
致谢
许可协议
MIT许可(MIT)。有关更多信息,请参阅许可文件。