lelush / laravel-apn-notification-channel
Laravel 5.3+ 的 Apple Push Notification Service (APNs) 通知通道,使用基于令牌(JWT 与 p8 私钥)的新 APNs HTTP/2 协议
v0.1.5
2019-02-19 18:40 UTC
Requires
- php: ^7.0
- edamov/pushok: ^0.4.3
- illuminate/notifications: ~5.3|~5.4|~5.5|~5.6|~5.7|~5.8
- illuminate/support: ~5.1|~5.2|~5.3|~5.4|~5.5|~5.6|~5.7|~5.8
Requires (Dev)
- mockery/mockery: ^0.9.5
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-09-29 08:01:01 UTC
README
此包使用 Laravel 5.8 将通知轻松发送到 iOS,使用基于令牌(JWT 与 p8 私钥)的新 APNs HTTP/2 协议。
内容
功能
- 使用新的 Apple APNs HTTP/2 连接
- 支持基于 JWT 的身份验证
- 支持新的 iOS 10 功能,如折叠 ID、副标题和可变通知
- 使用并发请求到 APNs
- 已在 APNs 生产环境中测试并运行良好
- 支持基于证书的身份验证
要求
- PHP >= 7.0
- 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
// config/broadcasting.php 'connections' => [ ... 'apn' => [ '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'), ], ... ],
使用方法
现在您可以在通知内的 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 代码覆盖率
- 添加测试
更新日志
请参阅 CHANGELOG 了解最近更改的详细信息。
测试
$ composer test
安全
如果您发现任何安全相关的问题,请通过电子邮件 semyon.chetvertnyh@gmail.com 联系,而不是使用问题跟踪器。
贡献
有关详细信息,请参阅 CONTRIBUTING。
致谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件。