PHP code example of matthew-p / yii2-fcm-component

1. Go to this page and download the library: Download matthew-p/yii2-fcm-component library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

matthew-p / yii2-fcm-component example snippets


...
'components' => [
    ...
    'fcm' => [
        'class'  => \MP\Fcm\FcmComponent::class,
        'apiKey' => 'sampleKey',
    ],
    ...
],
...

// 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);