overthink/laravel-push-notifications
Composer 安装命令:
composer require overthink/laravel-push-notifications
包简介
Send push notifications to Android and iOS
README 文档
README
This is a helper that takes away the pain of setting specific calls for Android and iOS pushes. It works with Laravel 8.0.
Installation
You can install the package via composer:
composer require overthink/laravel-push-notifications
You can publish the config file with:
php artisan vendor:publish --provider="Overthink\Push\PushServiceProvider"
This is the contents of the published config file:
return [ 'general' => [ 'keep_alive' => true, ], 'ios' => [ 'certificate-path' => env('PUSH_IOS_AUTH_KEY_PATH'), 'secret' => env('PUSH_IOS_SECRET'), 'team-id' => env('PUSH_IOS_TEAM_ID'), ], 'android' => [ 'authorization-key' => env('PUSH_ANDROID_AUTH_KEY'), 'google_application_credentials' => env('GOOGLE_APPLICATION_CREDENTIALS'), 'project_id' => env('PUSH_ANDROID_PROJECT_ID'), ], ];
iOS
You have to setup certificate from Apple and link its path in PUSH_IOS_AUTH_KEY_PATH. You can check the instructions here.
For the PUSH_IOS_SECRET you can follow this stack overflow answer, you are looking for kid value.
PUSH_IOS_TEAM_ID can be found in Apple Developer account as a part of mobile developers data.
Android
PUSH_ANDROID_AUTH_KEY is no longer used in this project, and will be removed in the next version.
GOOGLE_APPLICATION_CREDENTIALS can be created if you follow instructions here.
PUSH_ANDROID_PROJECT_ID is a unique identifier for your Firebase project, used in requests to the FCM v1 HTTP endpoint. This value is available in the Firebase console Settings pane.
Usage
We need a device object from where we get all the data that we use for sending a push. In most cases this can be Laravel model.
use Overthink\Push\Contracts\DeviceContract; class Device implements DeviceContract { public function getOperatingSystem(): string { return 'android'; // or 'ios' } public function getPushToken(): string { // Push token should be provided by mobile application return '8516cdd38e63170237df6e7eb6f22d875a5e07c10082...'; } public function isDevelopment(): bool { // With this value you can set development or production api when sending iOS push return false; } public function getTopic(): string { // Mobile applications unique identifier used when sending iOS push return 'com.example.test' } }
Here we combine all the parts to send push to either Android or iOS device.
$androidExamplePush = [ 'message' => [ 'android' => [ 'priority' => 'normal', 'data' => [ 'title' => 'Example Android title', 'body' => 'Example Android body', 'extra_data' => 'Some extra data that you want to pass to mobile app' ], ], ], ]; $iosExamplePush = [ 'aps' => [ 'sound' => 'short_sound.caf', // sound file needs to present in the app 'alert' => [ 'title' => 'Example iOS title', 'body' => 'Example iOS body' ], ], 'extra_data' => 'Some extra data that you want to pass to mobile app' ]; $pushPayload = (new PushPayload()) ->setAndroidPayload($androidExamplePush) ->setIosPayload($iosExamplePush); // We need collection of objects that implement Overthink\Push\Contracts\DeviceContract $devices = collect([new Device()]); $push = (new Overthink\Push\Push()) ->setPushPayload($pushPayload) ->setDevices($devices) ->send();
Credits
License
The MIT License (MIT). Please see License File for more information.
overthink/laravel-push-notifications 适用场景与选型建议
overthink/laravel-push-notifications 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 154 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「apns」 「FCM」 「google push」 「apple push」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 overthink/laravel-push-notifications 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 overthink/laravel-push-notifications 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 overthink/laravel-push-notifications 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP library to send push notification through Firebase Cloud Messaging
PHP framework for easy interaction with Apple's Push Notification Service.
Yii 2 Apns and Gcm together
Firebase cloud messaging http v1 php
Apple Push Notification & Feedback Provider
Yii2 Extension for sending push notification with both Firebase Cloud Messaging (FCM) HTTP Server Protocols (APIs).
统计信息
- 总下载量: 154
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-13