jaebe / jetifier
该软件包最新版本(v1.0.0)没有提供许可证信息。
PHP Firebase Cloud Messaging 库
v1.0.0
2017-12-23 11:41 UTC
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is not auto-updated.
Last update: 2024-09-28 00:38:08 UTC
README
Jetifier
Jetifier 是一个简单的 PHP 库,用于通过 Firebase Cloud Messaging 发送推送通知和消息。
- 支持通知有效负载、数据有效负载和混合类型。
- 支持不同类型的接收者
- 设备令牌
- 主题
- 条件(见: 文档)
- 目前仅支持 PHP 7.1 及以上版本
- 支持通过 curl、file_get_contents 发送消息,并允许您进行自定义实现(默认为 curl)
- 简单的快速通知,或自定义一切
用法
简单发送
try { $response = (new \Jetifier\Jetifier('API_KEY')) ->setTitle('title') // title of notification ->setTopic('topic') // topic recipient ->send(); }catch (\Jetifier\Exceptions\JetifierException $ex){ //Exception }
发送到设备
$client = new Client('API_KEY'); $message = new Message(); $recipient = new Device('TOKEN'); $notification = new Notification(); $notification->setTitle('title'); $message->setRecipient($recipient) ->setNotification($notification) $client->send($message);
发送到主题
$client = new Client('API_KEY'); $message = new Message(); $recipient = new Topic('topic_name'); $notification = new Notification(); $notification->setTitle('title'); $message->setRecipient($recipient) ->setNotification($notification) $client->send($message);
发送到主题条件
$client = new Client('API_KEY'); $message = new Message(); $recipient = new Condition(new Topic('topic_name')); $recipient->orTopic(new Topic('second_topic'); $notification = new Notification(); $notification->setTitle('title'); $message->setRecipient($recipient) ->setNotification($notification) $client->send($message);
嵌套条件
... $recipient = new Condition(new Topic('topic_name')); $subCondition = new Condition(new Topic('second_topic')); $subCondition->orTopic(new Topic('third_topic'); $recipient->andCondition($subCondition); ...
更改发送方法
$client = new Client('API_KEY'); $client->setSender(new \Jetifier\Sender\Post()); ...