farjihacker / fcm-push-notify
此包最新版本(dev-master)没有可用的许可证信息。
Google 推送通知库
dev-master
2019-01-09 12:58 UTC
Requires
- php: >=5.5.0
This package is auto-updated.
Last update: 2024-09-10 06:51:41 UTC
README
这是一个使用 Google Firebase(FCM)推送通知发送推送通知的库。
安装
使用 Composer
安装 FCM-PUSH-Notify 库。
composer require farjihacker/fcm-push-notify
使用方法
步骤 1: 使用以上命令安装。
步骤 2: 导入/使用此命名空间。
use FirebaseNotify\Firebase; // Firebase Utility use FirebaseNotify\Push; // Create Message with JSON Formate
步骤 3: 创建两个对象。
$firebase = new Firebase("FIREBASE_API_KEY"); // Pass Your API Key as Param $push = new Push();
步骤 4: 使用 $push
对象创建 JSON 数据对象。
// optional payload $payload = array(); $payload['team'] = 'India'; $payload['score'] = '5.6'; // notification title $title = "Test Title"; // notification message $message = "MSG"; // push type - single user / topic $push_type = "individual"; // whether to include to image or not $include_image = ""; $push = new Push(); $push->setTitle($title); $push->setMessage($message); if ($include_image) { $push->setImage('http://api.androidhive.info/images/minion.jpg'); } else { $push->setImage(''); } $push->setIsBackground(FALSE); $push->setPayload($payload);
步骤 5: 使用 $firebase
对象发送推送通知。
//Get JSON Object $json = $push->getPush(); //echo "<pre>"; //print_r($json); // User Token $regId = "USER_TOKEN"; $response = $firebase->send($regId, $json); // Enable this line to check firebase success/error response. //print_r($response);
贡献
欢迎提交拉取请求。对于重大更改,请先打开一个问题来讨论您希望更改的内容。
请确保适当更新测试。