承接 saikatdutta1991/firebasecloudmessaging 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

saikatdutta1991/firebasecloudmessaging

Composer 安装命令:

composer require saikatdutta1991/firebasecloudmessaging

包简介

This is to send push notification with firebase cloud messaging for Laravel. Tested in Laravel 5.2.*

README 文档

README

** Caveat: This package is not maintained anymore.

This Package is to enable sending push notifications to devices with firebase cloud messaging. Tested in Laravel 5.1 and 5.2

#Installation

To install the package simply run this command in Laravel project root folder

php composer.phar require saikatdutta1991/firebasecloudmessaging:1.0.0

add the service provider

    'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
            
        .....
        .....
        \Saikat\FirebaseCloudMessaging\FCMServiceProvider::class 
    ]

to config\app.php providers array

Alias the PushManager class adding it to the aliases array in the config/app.php file.

    'aliases' => [
        ...
        'PushManager' => Saikat\FirebaseCloudMessaging\PushManager::class
    ]

But the alias is not mandatory.

Configuration

publish the package config to your laravel config folder with executing command

php artisan vendor:publish --tag="config"

before executing this command add the service provider first

add the fcm server_key in the config/firebase_cloud_messaging.php file

    return [
        
        "server_key" => env('FIREBASE_CLOUD_MESSAGING_SERVER_KEY'),
        "fcm_push_url" => env("FIREBASE_CLOUD_MESSAING_URL")

    ];

fcm_push_url is not required already included in package. If want to override then add it

Usage

##including PushManager

If added in alias then use it in controller

use PushManager;

IF not added in alias then use it in controller

use Saikat\FirebaseCloudMessaging\PushManager;

##dependency injection in controller constructor

class YourController extends Controller
{
    
    public function __construct(PushManager $pushManager)
    {
        $this->pushManager = $pushManager;
    }

If want to use without injecting then

class YourController extends Controller
{
    
    public function sendPushNotification()
    {
        $pushManager = app('PushManager'); // this will keep the PushManager instance singleton
    }

Example

<?php

namespace App\Http\Controllers;

use Illuminate\Routing\Controller;
use PushManager;

class Controller extends Controller
{
    
    public function __construct(PushManager $pushManager)
    {
        $this->pushManager = $pushManager;
    }

    public function sendPushNotification()
    {
        $response = $this->pushManager
            ->setTitle('Test Title')
            ->setBody('Test Body')
            ->setIcon('icon url')
            ->setClickAction('https://www.google.com')
            ->setCustomPayload(['custom_data' => 'custom_data_array']) 
            ->setPriority(PushNotification::HIGH)
            ->setContentAvailable(true)
            ->setDeviceTokens('--------------------') // this can be an array or string
            ->push();

        dd( $response );
    }

}

To change response

->push(PushManager::STDCLASS)

PushManager::STDCLASS, PushManager::ARRY, PushManager::RAW

by default response is PushManager::RAW set

Error Handle

===============

$this->pushManager->getLastErrorCode() //if no error then 0

and

$this->pushManager->getLastErrorMessage() // if no error then ""

Future Enhancement

======================

Now only raw response works proper. Json and stdClas response doesn't work for all types of fcm response. Returns null if failed to make json decode.

I will make the send push notification send asynchronous so that no wait for the response

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-03-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固