Firebase Cloud Messaging Http v1 for PHP
composer require kedniko/firebase-cloud-messaging-http-v1-php
<?php
$authKeyContent = json_decode(file_get_contents(__DIR__ . '/appname-30xfgre76.json'), true);
$projectID = 'my-project-1';
$body = [
'message' => [
'token' => '<token:string>',
'notification' => [
'title' => 'Breaking News',
'body' => 'New news story available.',
],
'data' => [
'story_id' => 'story_12345',
],
],
];
$bearerToken = FCM::getBearerToken($authKeyContent);
FCM::send($bearerToken, $projectID, $body);
<?php
$authKeyContent = json_decode(file_get_contents(__DIR__ . '/appname-30xfgre76.json'), true);
$projectID = 'my-project-1';
$tokens = [
'<token1:string>',
'<token2:string>',
'<token3:string>',
];
$bearerToken = FCM::getBearerToken($authKeyContent);
foreach ($tokens as $token) {
$body = [
'message' => [
'token' => $token,
'notification' => [
'title' => 'Breaking News',
'body' => 'New news story available.',
],
'data' => [
'story_id' => 'story_12345',
],
],
];
FCM::send($bearerToken, $projectID, $body);
}
<?php
$authKeyContent = json_decode(file_get_contents(__DIR__ . '/appname-30xfgre76.json'), true);
$tokens = [
'<token1:string>',
'<token2:string>',
'<token3:string>',
];
$bearerToken = FCM::getBearerToken($authKeyContent);
FCM::subscribeToTopic($bearerToken, 'my-topic-1', $tokens);
<?php
$authKeyContent = json_decode(file_get_contents(__DIR__ . '/appname-30xfgre76.json'), true);
$tokens = [
'<token1:string>',
'<token2:string>',
'<token3:string>',
];
$bearerToken = FCM::getBearerToken($authKeyContent);
FCM::unsubscribeFromTopic($bearerToken, 'my-topic-1', $tokens);