jp / firebase-notification-bundle
用于发送通过 Firebase Cloud Messaging API 到移动设备的通知的 Symfony2 项目 Bundle
3.0.0
2020-05-15 13:45 UTC
Requires
- php: >=5.6
- symfony/config: ^4.0
- symfony/dependency-injection: ^4.0
- symfony/framework-bundle: ^4.0
- symfony/http-foundation: ^4.0
- symfony/http-kernel: ^4.0
- symfony/options-resolver: ^4.0
- symfony/security: ^4.0
- symfony/validator: ^4.0
This package is auto-updated.
Last update: 2024-09-15 23:02:38 UTC
README
用于 Symfony4 项目的 Bundle,通过 Firebase Cloud Messaging API 发送移动设备通知
配置
步骤 1: 使用 composer 下载 FirebaseNotificationBundle
在 composer.json 中添加 Firebase 通知
{ "require": { "jp/firebase-notification-Bundle": "^2.0.0" } }
现在运行以下命令让 composer 下载 Bundle
$ php composer.phar update "jp/firebase-notification-Bundle"
步骤 2: 启用 Bundle
在 kernel 中启用 Bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new JP\FirebaseNotificationBundle\JPFirebaseNotificationBundle() ); }
步骤 3: 添加配置
# app/config/config.yml jp_firebase_notification: firebase_fcm: server_key: XXXXXX
用法
使用服务
<?php $fcm = $this->get('firebase_fcm_client'); ?>
##示例
###创建消息并发送消息
<?php $fcm = $this->get('firebase_fcm_client'); $fcm->createMessage(array( 'to' => 'XXXXXXXX', 'title' => 'New message', 'body' => 'Hello World!', 'badge' => 1, 'data' => array( 'action' => "new_message" ) )); $data = $fcm->sendMessage(); ?>
###创建主题消息并发送消息
<?php $fcm = $this->get('firebase_fcm_client'); $fcm->createMessage(array( 'topic' => '/topics/TOPIC_NAME', 'title' => 'New message', 'body' => 'Hello World!', 'badge' => 1, 'data' => array( 'action' => "new_message" ) )); $data = $fcm->sendMessage(); ?>