定制 avto-dev/firebase-notifications-laravel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

avto-dev/firebase-notifications-laravel

Composer 安装命令:

composer require avto-dev/firebase-notifications-laravel

包简介

Notifications channel for Firebase service

README 文档

README

Laravel

Here's the latest documentation on Laravel Notifications System: https://laravel.com/docs/master/notifications

Firebase notifications channel for Laravel applications

Version PHP Version Build Status Coverage Downloads count License

This package makes it easy to send notifications using Firebase with Laravel 5.

Contents

Installation

$ composer require avto-dev/firebase-notifications-laravel "^2.0"

Installed composer is required (how to install composer).

You need to fix the major version of package.

Laravel 5.5 and above uses Package Auto-Discovery, so doesn't require you to manually register the service-provider. Otherwise you must add the service provider to the providers array in ./config/app.php:

<?php

return [

    // ...

    'providers' => [
        // ...
        AvtoDev\FirebaseNotificationsChannel\ServiceProvider::class,
    ],

];

Setting up the Firebase service

You need to set up firebase channel in config file ./config/services.php.

To generate a private key file for your service account:

  1. In the Firebase console, open Settings > Service Accounts.
  2. Click Generate New Private Key, then confirm by clicking Generate Key.
  3. Securely store the JSON file containing the key. You'll need this JSON file to complete the next step.

Next select the "driver" file or config contains credintails for Firebase service account in ./config/services.php:

<?php

return [

    // ...

    /*
    |--------------------------------------------------------------------------
    | Firebase Settings section
    |--------------------------------------------------------------------------
    |
    | Here you may specify some configs for FCM.
    |
    */

    'fcm' => [

        /*
         |----------------------------------------------------------------------
         | Firebase service driver
         |----------------------------------------------------------------------
         |
         | Value `file` or `config`:
         |   - Select `file` option to make service read json file
         |   - Select `config` option to set up all section in config file
         |
         */

        'driver' => env('FCM_DRIVER', 'config'),

        /*
         |---------------------------------------------------------------------
         | FCM Drivers
         |---------------------------------------------------------------------
         |
         | Here are each of the firebase.
         |
         */

        'drivers' => [

            'file' => [
                'path' => env('FCM_FILE_PATH', base_path('storage/fcm.json')),
            ],

            'config' => [

                 /*
                 |------------------------------------------------------------
                 | Credentials
                 |------------------------------------------------------------
                 |
                 | Content of `firebase.json` file in config. Using if
                 | `fcm.driver` is `config`. All fields required!
                 |
                 */

                'credentials'=>[
                     'private_key_id'              => env('FCM_CREDENTIALS_PRIVATE_KEY_ID', 'da80b3bbceaa554442ad67e6be361a66'),
                     'private_key'                 => env('FCM_CREDENTIALS_PRIVATE_KEY', '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n'),
                     'client_email'                => env('FCM_CREDENTIALS_CLIENT_EMAIL', 'firebase-adminsdk-mwax6@test.iam.gserviceaccount.com'),
                     'client_id'                   => env('FCM_CREDENTIALS_CLIENT_ID', '22021520333507180281'),
                     'auth_uri'                    => env('FCM_CREDENTIALS_AUTH_URI', 'https://accounts.google.com/o/oauth2/auth'),
                     'token_uri'                   => env('FCM_CREDENTIALS_TOKEN_URI', 'https://oauth2.googleapis.com/token'),
                     'auth_provider_x509_cert_url' => env('FCM_CREDENTIALS_AUTH_PROVIDER_CERT', 'https://www.googleapis.com/oauth2/v1/certs'),
                     'client_x509_cert_url'        => env('FCM_CREDENTIALS_CLIENT_CERT', 'https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-mwax6%40test.iam.gserviceaccount.com'),
                ],
            ],
        ],
    ],

];

Usage

Now you can use the channel in your via() method inside the notification as well as send a push notification:

<?php

use Illuminate\Notifications\Notification;
use AvtoDev\FirebaseNotificationsChannel\FcmChannel;
use AvtoDev\FirebaseNotificationsChannel\FcmMessage;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [FcmChannel::class];
    }

    public function toFcm($notifiable, $notification)
    {
        return (new FcmMessage)
            ->setTitle('Approved!')
            ->setBody('Your account was approved!');
    }
}
<?php

use Illuminate\Notifications\Notifiable;
use AvtoDev\FirebaseNotificationsChannel\Receivers\FcmDeviceReceiver;
use AvtoDev\FirebaseNotificationsChannel\Receivers\FcmNotificationReceiverInterface;

class SomeNotifible
{
    use Notifiable;

    /**
    * Reveiver of firebase notification.
    *
    * @return FcmNotificationReceiverInterface
    */
    public function routeNotificationForFcm(): FcmNotificationReceiverInterface
    {
        return new FcmDeviceReceiver('firebase_token');
    }
}

Available Message methods

This pakage supports all fields from HTTP v1 FCM API. Message class contains setters for all the fields:

Field Type
data array
title string
body string
android AndroidFcmPlatformSettings
webpush WebpushFcmPlatformSettings
apns AppleFcmPlatformSettings

PlatformSettings classes contain platform secific setters

Testing

For package testing we use phpunit framework and docker with compose plugin as develop environment. So, just write into your terminal after repository cloning:

$ git clone git@github.com:avto-dev/firebase-notifications-laravel.git ./firebase-notifications-laravel && cd $_
$ make install
$ make test

Changes log

Release date Commits since latest release

Changes log can be found here.

Support

Issues Issues

If you will find any package errors, please, make an issue in current repository.

Security

If you discover any security related issues, please email jetexe2@gmail.com instead of using the issue tracker.

Credits

License

This is open-sourced software licensed under the MIT License.

avto-dev/firebase-notifications-laravel 适用场景与选型建议

avto-dev/firebase-notifications-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14.69k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「notifications」 「laravel」 「firebase」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 avto-dev/firebase-notifications-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 avto-dev/firebase-notifications-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 avto-dev/firebase-notifications-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-30