PHP code example of autoxloo / yii2-fcm
1. Go to this page and download the library: Download autoxloo/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/ */
autoxloo / yii2-fcm example snippets
$token = 'some device token';
$name = 'Some name';
$title = 'Some title';
$body = 'Some body';
$data = [
'some key1' => 'some value1',
'some key2' => 'some value2',
];
// sending push notification:
$target = FCMFacade::createTargetToken($token); // only target is a($data)
->setNotification($notification)
->setAndroidConfig($androidConfig);
$response = Yii::$app->firebaseNotification->send($message); // $response is instance of \GuzzleHttp\Psr7\Response
$messageConfig = [
// => $token, // or Message::FIELD_TOPIC => $topic or Message::FIELD_CONDITION => $condition
// not n($title, $body),
Message::FIELD_ANDROID => FCMFacade::createAndroidConfig([
AndroidConfig::FIELD_PRIORITY => AndroidConfig::PRIORITY_HIGH
]),
];
$message = FCMFacade::createMessage($messageConfig);
$response = Yii::$app->firebaseNotification->send($message); // $response is instance of \GuzzleHttp\Psr7\Response
$targetToken = FCMFacade::createTargetToken('some token');
$targetTopic = FCMFacade::createTargetTopic('some topic');
$targetCondition = FCMFacade::createTargetConsition('some condition');
php composer.phar