agent/firepush-php

一个用于在客户端用户代理中使用 Firebase 发送实时推送通知的 PHP 包

dev-master 2022-02-04 16:54 UTC

This package is not auto-updated.

Last update: 2024-09-29 06:20:27 UTC


README

一个用于发送 云消息 的小型 PHP 库

安装库

composer require agent/firepush-php

访问 Google Firebase 控制台

Firebase 为您提供分析、数据库、消息和崩溃报告等功能,让您能够快速开发并专注于用户。(见 启用项目

启动 Agent 对象

$firepush = new Agent\Firepush\Service('AAAAWj6Hc4E:LONG-SERVER-CLOUD-MESSAGE-KEY');

💻 该类将通过 API 连接到 console.firebase.google.com 中的项目

向客户端发送单个设备推送通知

$firepush->to('client_token');

$notify = array(
           'title' => 'FCM Message',
           'body' => 'FCM Message Text',
           'icon' => 'http://myproject.com/icon.png',
           'link' => 'http://myproject.com'
         );

$firepush->notification($notify);
                    
$firepush->send();     

//or concatenate:

$firepush->to('client_token')->notification($notify)->send()
               

🚀 系统将在 to() 中设置的设备上发送通知

向客户端发送多个设备推送通知


$clients_token = array(
// array of token to send
);

$firepush->to($clients_token);

$notify = array(
           'title' => 'FCM Message',
           'body' => 'FCM Message Text',
           'icon' => 'http://myproject.com/icon.png',
           'link' => 'http://myproject.com'
         );

$firepush->notification($notify);
                    
$firepush->send();     

//or concatenate:

$firepush->to($clients_token)->notification($notify)->send()
               

🚀 系统将在 to array() 中设置的 ALL 设备上发送通知

检索单个/多个消息 ID


CODE FOR SEND NOTIFICETION
                    
$firepush->send();     

// After send:

$firepush->getMessageIds();
               

🚀 系统从调用中检索所有消息 ID