定制 code-of-brain/firebase-messaging-php 二次开发

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

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

code-of-brain/firebase-messaging-php

Composer 安装命令:

composer require code-of-brain/firebase-messaging-php

包简介

This is simple to use PHP package for sending firebase messages.

README 文档

README

Installation using composer

composer require code-of-brain/firebase-messaging-php

Send Notification to Client

use FirebaseMessagingPhp\FirebaseClient;
use FirebaseMessagingPhp\FirebaseNotification;

$client = new FirebaseClient(SERVER_KEY);

$notification = new FirebaseNotification();

$notification->setTitle('title')
    ->setBody('body');

$clientToken = ['CLIENT_ID_1' => 'CLIENT_TOKEN_1'];

$response = $client->send($notification, $clientToken);

var_dump($response);

Send Notification to Multiple Clients

use FirebaseMessagingPhp\FirebaseClient;
use FirebaseMessagingPhp\FirebaseNotification;

$client = new FirebaseClient(SERVER_KEY);

$notification = new FirebaseNotification();

$notification->setTitle('title');
    ->setBody('body');

$clientTokens = ['CLIENT_ID_1' => 'CLIENT_TOKEN_1', 'CLIENT_ID_2' => 'CLIENT_TOKEN_2', 'CLIENT_ID_3' => 'CLIENT_TOKEN_3'];

$response = $client->send($notification, $clientTokens);

var_dump($response);

Clients Token Verification

use FirebaseMessagingPhp\FirebaseClient;
use FirebaseMessagingPhp\FirebaseNotification;

$client = new FirebaseClient(SERVER_KEY);

$clientTokens = ['CLIENT_ID_1' => 'CLIENT_TOKEN_1', 'CLIENT_ID_2' => 'CLIENT_TOKEN_2', 'CLIENT_ID_3' => 'CLIENT_TOKEN_3'];

$response = $client->verifyTokens($clientTokens);

var_dump($response);

Optional Parameters

$notification = new FirebaseNotification();

// You can add priority to notification by using setPriority method 
// Priority can be 'high' and 'normal' 
// By default priority is 'normal'

$notification->setPriority('high');

// You can add extra data to notification by using setData method 
// Data should be a array of string key-value pair

$notification->setData(array('name' => 'user', 'id' => '1111'));

// This method is use to specifies how long (in seconds) the message should be kept in FCM storage if the device is offline
// The maximum time to live supported is 4 weeks, and the default value is 4 weeks

$notification->setTimeToLive( 60 * 60 ); // 60 * 60 = 3600 means message should be kept in FCM storage for 3600 seconds (1 hour)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固