Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matthewpattell/yii2-fcm-component
Very simple fcm component for yii2
https://github.com/matthewpattell/yii2-fcm-component
Last synced: about 1 month ago
JSON representation
Very simple fcm component for yii2
- Host: GitHub
- URL: https://github.com/matthewpattell/yii2-fcm-component
- Owner: MatthewPattell
- Created: 2018-05-11T11:45:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-19T11:38:25.000Z (almost 5 years ago)
- Last Synced: 2024-09-19T03:14:22.681Z (4 months ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Firebase cloud messaging for Yii2
===========================
Very simple FCM component for yii2Installation
------------The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Add
```
"matthew-p/yii2-fcm-component": "^1.0"
```to the require section of your `composer.json` file.
and
```
{
"type": "git",
"url": "https://github.com/MatthewPattell/yii2-fcm"
},
{
"type": "git",
"url": "https://github.com/MatthewPattell/php-fcm"
}
```to the repositories section of your `composer.json` file.
Usage
-----Once the extension is installed, simply use it in your code by:
In config main.php:
```php
...
'components' => [
...
'fcm' => [
'class' => \MP\Fcm\FcmComponent::class,
'apiKey' => 'sampleKey',
],
...
],
...
```Use:
```php
// Send to topic
$message = [
'topic' => 'sampleChannelID',
'data' => [
'sample1' => 'test'
],
];$notification = ['key' => 'samplePushMessageKey'];
Yii::$app->fcm->pushTopic($message, $notification);
// Send to device
$message = [
'device' => 'sampleDeviceToken',
'data' => [
'sample1' => 'test'
],
];
Yii::$app->fcm->pushDevice($message, $notification);
```See $notification configuration in \MP\Fcm\FcmComponent::NOTIFICATION_DEFAULT
That's all. Check it.