PHP code example of uzdevid / yii2-fcm

1. Go to this page and download the library: Download uzdevid/yii2-fcm 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/ */

    

uzdevid / yii2-fcm example snippets


return [
    // ...
    'components' => [
        // ...
        'notifier' => [
            'class' => 'uzdevid\fcm\Notifier',
            'serverKey' => '{serverKey}', // Cloud Messaging API (Legacy) ni faollashtirganingizdan so'ng, "Server key" beriladi.
        ],
        // ...
    ],
    // ...
]

$token = "frYfozsx0K7e..."; // Push habar qabul qiluvchi qurilmaning tokeni
$notification = [
    'title' => 'Salom, dunyo!',
    'body' => 'Bu birinchi push habarim',
    'data' => [
        // qo'shimcha ma'lumotlar
    ]
];

$params = [
    // qo'shimcha parametrlar (majburiy emas)
];

Yii::app()->notifier->notify($token, $notification, $params);

return [
    // ...
    'fcm' => [
        'apiKey' => '{apiKey}',
        'authDomain' => '{authDomain}',
        'databaseURL' => '{databaseURL}',
        'projectId' => '{projectId}',
        'storageBucket' => '{storageBucket}',
        'messagingSenderId' => '{messagingSenderId}',
        'appId' => '{appId}',
        'measurementId' => '{measurementId}',
        'vapidKey' => '{vapidKey}',
    ],
    // ...
];

\uzdevid\fcm\FcmAsset::register($this);
bash
php composer.phar 
javascript
function onNotify(payload) {
    // habarni foydalanuvchiga ko'rsatish, yoki boshqa amallarni bajarish uchun kodni yozing
}