antonyz89/yii2-fcm

Yii2 Firebase Cloud Messaging适配器(最初由understeam创建)

维护者

详细信息

github.com/AntonyZ89/yii2-fcm

源代码

安装: 1

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 6

类型:yii2-extension

0.2.2 2021-06-15 02:05 UTC

This package is auto-updated.

Last update: 2024-09-15 09:18:47 UTC


README

此组件封装了paragraph1/php-fcm库。

安装

推荐通过Composer进行安装

$ composer require understeam/yii2-fcm:~0.1 --prefer-dist 

配置

将组件添加到您的应用程序配置中

...
'components' => [
    'fcm' => [
        'class' => 'understeam\fcm\Client',
        'apiKey' => 'your API key', // Server API Key (you can get it here: https://firebase.google.com/docs/server/setup#prerequisites) 
    ],
],
...

使用方法

您可以在这里找到更多使用示例。

$note = Yii::$app->fcm->createNotification("test title", "testing body");
$note->setIcon('notification_icon_resource_name')
    ->setColor('#ffffff')
    ->setBadge(1);

$message = Yii::$app->fcm->createMessage();
$message->addRecipient(new Device('your-device-token'));
$message->setNotification($note)
    ->setData(['someId' => 111]);

$response = Yii::$app->fcm->send($message);
var_dump($response->getStatusCode());