muchg0di / larafcm-http-v1
为 Laravel 5 (PHP 5.6) 实现的 FCM http v1
Requires
- php: ^5.6
- google/auth: ^1.19
- guzzlehttp/guzzle: ^6.3
- illuminate/support: 5.*|^6
Requires (Dev)
- laravel/laravel: 5.2.*
- laravel/tinker: ^1.0
- mockery/mockery: 0.9.*
- phpunit/phpunit: 4.7.*
- satooshi/php-coveralls: 2.2.x-dev
This package is auto-updated.
Last update: 2024-09-28 16:36:22 UTC
README
为 Laravel 5 (PHP 5.6) 实现的 FCM http v1
目录
免责声明
这是一个针对非常旧的设置的实施方案,如果您需要良好实现和更新的东西,请检查 https://github.com/kreait/firebase-php 和 https://github.com/kreait/laravel-firebase。也许我以后有时间,我会改进它。
简介
此包为 Laravel 5 (PHP 5.6) 提供了 Firebase Cloud Messaging (FCM) HTTP v1 协议的实现。它允许您使用 FCM 服务向 Android 和 iOS 设备发送推送通知。
安装
要安装此包,请在您的终端中运行以下命令
composer require muchg0di/larafcm-http-v1
Laravel
在您的 app 配置文件 config/app.php 中直接注册提供者
Laravel >= 5.5 提供了包自动发现功能,归功于 rasmuscnielsen 和 luiztessadri,他们帮助在 Laravel-FCM 中实现了此功能,因此现在不需要注册提供者和外观。
'providers' => [ // ... Muchg0di\LarafcmHttpV1\LarafcmHttpV1ServiceProvider::class, ]
在同一个文件中添加外观别名
'aliases' => [ // ... 'LarafcmHttpV1' => Muchg0di\LarafcmHttpV1\Facades\LarafcmHttpV1::class, ]
使用方法
要使用此包,您可以导入外观 LarafcmHttpV1
,调用 createFirebaseDriver
方法以创建 Firebase 驱动程序。然后,您可以使用该驱动程序发送推送通知。
use LarafcmHttpV1; use Muchg0di\LarafcmHttpV1\DataTransferObjects\NotificationPayloadDto; use Muchg0di\LarafcmHttpV1\DataTransferObjects\RequestOptionsDto; $payload = new NotificationPayloadDto('Title', 'Body'); $options = new RequestOptionsDto(30); // timeout in seconds LarafcmHttpV1::driver('firebase') ->sendToTopic('topic-name', $payload, $options);
配置
您需要通过发布配置文件并设置 FCM 凭据来配置此包。
php artisan vendor:publish --provider="Muchg0di\LarafcmHttpV1\LarafcmHttpV1ServiceProvider"
然后,使用您的 FCM 凭据更新 config/larafcm-http-v1.php
文件。
'drivers' => [ 'firebase' => [ 'driver' => 'firebase', 'project_id' => env('FIREBASE_PROJECT_ID', 'your project id'), 'credentials' => env('FIREBASE_CREDENTIALS', 'path/to/your/firebase-credentials.json'), 'scope' => env('FIREBASE_SCOPE', 'your-firebase-scope'), ],
许可协议
此包采用 MIT 许可协议。