pluritech/fcm-php

此包具有与 Firebase Cloud Message 相反的功能。将使用 CURL 通过 REST 模式与 Firebase API 进行 HTTP 通信,以向一个或多个设备发送推送通知。

2.0.15 2019-07-11 18:57 UTC

README

此存储库包含允许您从您的 PHP 应用程序访问 Google FCM 平台的开放源代码 PHP SDK。

安装

可以使用 Composer 安装 Google FCM PHP SDK。运行以下命令

composer require pluritech/fcm-php

用法

注意:此版本的 Google FCM SDK for PHP 需要 PHP 5.4 或更高版本。

简单发送推送示例。

require_once __DIR__ . '/vendor/autoload.php'; // change path as needed

$FCMPHP = new \FCMPHP\FCMPHP([
    'fcm_server_key' => '{server-key}'
]);

$FCMNotification = new \FCMPHP\FCMNotification();

$FCMNotification->setTitle('{push-title}');
$FCMNotification->setBody('{push-description}');
$FCMNotification->setPriority('{push-priority}'); //high or normal
$FCMNotification->setDevices([ 
     '{device-id}'
    ,'{device-id}'
]); //One or more devices

$request = $FCMPHP->send($FCMNotification);

//Http error
if($request->getHttpStatusCode() != 200){
    $code = $request->getHttpStatusCode();
    $body = $request->getBody();
}

//One or more failure on send push to FCM
if($failure = $request->hasFailure()){
    $count = $failure['count'];
    $error = $failure['error'];
}

文档

进行中。

测试

进行中。

贡献

请随意提交您的拉取请求,提出建议或报告问题。

许可证

MIT © Guilherme Valentim