edwinhoksberg/php-fcm

一个用于发送Firebase云消息并管理用户主题订阅、设备组和设备的库。

v1.2.0 2021-01-19 01:15 UTC

This package is auto-updated.

Last update: 2024-09-07 14:57:21 UTC


README

一个用于发送Firebase云消息并管理用户主题订阅、设备组和设备的PHP库。

安装

使用composer安装

composer require edwinhoksberg/php-fcm

快速入门

<?php

// Load composer
require 'vendor/autoload.php';

// Instantiate the client with the project api_token and sender_id.
$client = new \Fcm\FcmClient($apiToken, $senderId);

// Instantiate the push notification request object.
$notification = new \Fcm\Push\Notification();

// Enhance the notification object with our custom options.
$notification
    ->addRecipient($deviceId)
    ->setTitle('Hello from php-fcm!')
    ->setBody('Notification body')
    ->addData('key', 'value');

// Send the notification to the Firebase servers for further handling.
$client->send($notification);

完整文档

请在此阅读文档或查看docs目录。

测试

使用PHPUnit运行单元测试

composer test

在第一次运行之前,你可能需要运行

composer install

Windows测试

对于本地的Windows测试,你需要安装xdebug并添加

zend_extension=xdebug
xdebug.mode=coverage

并设置composer.json脚本行到

    "scripts": {
        "test": ["vendor/bin/phpunit -c phpunit.dist.xml"]
    },

xUX测试

对于本地的xUX或在线github/codeforce测试,在composer.json中设置脚本行到

    "scripts": {
        "test": ["XDEBUG_MODE=coverage vendor/bin/phpunit -c phpunit.dist.xml"]
    },

许可证

MIT