定制 amos97/laravel-firebase 二次开发

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

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

amos97/laravel-firebase

Composer 安装命令:

composer require amos97/laravel-firebase

包简介

Laravel Firebase integration

README 文档

README

Build Status Packagist Packagist Packagist

Laravel Firebase integration

This package includes:

  • Firebase OAuthV2.0 authentication, with token caching
  • Centralized ServiceAccount credential management
  • Firebase FCM Http V1 API and Firebase Realtime database REST api via OAuth authentication
  • Firebase JWT token generator (via php-jwt)
  • Automatic sync for Eloquent models to Firebase Realtime db
  • Automatic sync triggers on related model changes

Installation

Install via composer

composer require amos97/laravel-firebase

The package will be auto registered in laravel >=5.5; If you use laravel <5.5 follow the next two steps

  1. Add service provider to config/app.php in providers section
Plokko\LaravelFirebase\ServiceProvider::class,
  1. Register package facade in config/app.php in aliases section
Plokko\LaravelFirebase\Facades\LaravelFirebase::class,

Your file in config/laravel-firebase.php should now look like this:

<?php

return [
    'read_only' => env('FIREBASEDB_READONLY',false),//DEBUG

    /**
     * Firebase service account information, can be either:
     * - string : absolute path to serviceaccount json file
     * - string : content of serviceaccount (json string)
     * - array : php array conversion of the serviceaccount
     * @var array|string
     */
    'service_account' => base_path('.firebase-credentials.json'),

    /**
     * If set to true will enable Google OAuth2.0 token cache storage
     */
    'cache' => true,

    /**
     * Cache driver for OAuth token cache,
     * if null default cache driver will be used
     * @var string|null
     */
    'cache_driver' => null,

    /**
     * Specify if and what event to trigger if an invalid token is returned
     * @var string|null
     */
    'FCMInvalidTokenTriggerEvent' => null,
];

Configuration

Publish the configuration file via

php artisan vendor:publish --provider="Plokko\LaravelFirebase\ServiceProvider" --tag="config"

Usage

JWT token

You can easly create a Firebase JWT token (for auth) with FirebaseJWT::encode:

FirebaseJWT::encode($uid,['optional'=>'custom-claims-array']);

FCM

This package allows you to send FCM messages via FCM http v1 api

Message builder

You can easly build FCM Messages via the FCM facade:

FCM::notificationTitle('My notification title')
  ->notificationBody('my notification body...');
  ->data(['notification' => 'data'])
  ->highPriority()//note: not all devices may use all the fields like priority or ttl
  ->ttl('20.5s')
  ->toDevice('my-device-fcm-token') // or toTopic('topic-name') or toCondition('condition-name') or toTarget(Target)
  ->send();//Submits the message

FCM Notification channel

You can also send the FCM messages via the FcmNotificationChannel channel:

class TestFcmNotification extends Notification implements ShouldQueue
{
    use Queueable;
    
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [FcmNotificationChannel::class];
    }

    public function toFcm($notifiable)
    {
        return FCM::notificationTitle('Test notification')
                    ->notificationBody('notification body...')
                    ->toDevice($notifiable->deviceToken);
    }
}

Real time database

Settings:

You can enable read-only access to database setting

FIREBASEDB_READONLY=true

on your .env file, this is usefull for testing purpuses, the writes will not return any error but will not be executed on Firebase.

Query the Realtime database

To get an instance of the database use the FirebaseDb facade:

$test = FirebaseDb::getReference('test'); //get the reference for item /test
$test->get('01');//Get /test/01 as an array
$test01 = $test->getReference('01');//Get a reference for /test/01
$test01->set('label','value');//Set /test/01/label = value

Sync models to Firebase

see Firebase database sync

amos97/laravel-firebase 适用场景与选型建议

amos97/laravel-firebase 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 07 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-28