semyonchetvertnyh / laravel-apn-notification-channel
适用于 Laravel 6 的 Apple Push Notification Service (APNs) 通知通道,使用新的 APNs HTTP/2 协议和基于令牌(JWT 与 p8 私钥)
此包的规范仓库似乎已丢失,因此该包已被冻结。
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-02-28 14:58:27 UTC
README
此包使得使用 Laravel 6 通过新的 APNs HTTP/2 协议和基于令牌(JWT 与 p8 私钥)向 iOS 发送通知变得简单。
内容
功能
- 使用新的 Apple APNs HTTP/2 连接
- 支持基于 JWT 的身份验证
- 支持基于证书的身份验证
- 支持新的 iOS 10 功能,如折叠 ID、子标题和可变通知
- 使用对 APNs 的并发请求
- 已在 APNs 生产环境中测试并运行
要求
- PHP >= 7.2
- lib-curl >= 7.46.0(启用 http/2 支持)
- lib-openssl >= 1.0.2e
安装
使用 Composer 安装此包
composer require semyonchetvertnyh/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)。请参阅许可证文件获取更多信息。