2017 © Pedro Peláez
 

library php-firebase-cloud-messaging

PHP API for Firebase Cloud Messaging from Google

image

redjanym/php-firebase-cloud-messaging

PHP API for Firebase Cloud Messaging from Google

  • Monday, July 16, 2018
  • by redjanym
  • Repository
  • 3 Watchers
  • 16 Stars
  • 41,888 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 73 Forks
  • 0 Open issues
  • 8 Versions
  • 29 % Grown

The README.md

PHP Firebase Cloud Messaging

SensioLabsInsight Buy Me a Coffee at ko-fi.com, (*1)

PHP API for Firebase Cloud Messaging from Google., (*2)

Currently this app server library only supports sending Messages/Notifications via HTTP., (*3)

See original Firebase docs: https://firebase.google.com/docs/, (*4)

Setup

Install via Composer:, (*5)

composer require redjanym/php-firebase-cloud-messaging

Or add this to your composer.json and run "composer update":, (*6)

"require": {
    "redjanym/php-firebase-cloud-messaging": "1.*"
}

Send message to one or multiple Devices

use sngrl\PhpFirebaseCloudMessaging\Client;
use sngrl\PhpFirebaseCloudMessaging\Message;
use sngrl\PhpFirebaseCloudMessaging\Recipient\Device;
use sngrl\PhpFirebaseCloudMessaging\Notification;

$server_key = '_YOUR_SERVER_KEY_';
$client = new Client();
$client->setApiKey($server_key);

$message = new Message();
$message->setPriority('high');
$message->addRecipient(new Device('_YOUR_DEVICE_TOKEN_'));
$message
    ->setNotification(new Notification('some title', 'some body'))
    ->setData(['key' => 'value'])
;

$response = $client->send($message);
var_dump($response->getStatusCode());
var_dump($response->getBody()->getContents());

Send message to Topic

Currently sending to topics only supports a single topic as recipient. Mutliple topic as outlined in the google docs don't seem to work, yet., (*7)

use sngrl\PhpFirebaseCloudMessaging\Client;
use sngrl\PhpFirebaseCloudMessaging\Message;
use sngrl\PhpFirebaseCloudMessaging\Recipient\Topic;
use sngrl\PhpFirebaseCloudMessaging\Notification;

$server_key = '_YOUR_SERVER_KEY_';
$client = new Client();
$client->setApiKey($server_key);

$message = new Message();
$message->setPriority('high');
$message->addRecipient(new Topic('_YOUR_TOPIC_'));
$message
    ->setNotification(new Notification('some title', 'some body'))
    ->setData(['key' => 'value'])
;

$response = $client->send($message);
var_dump($response->getStatusCode());
var_dump($response->getBody()->getContents());

Subscribe user to the topic

use sngrl\PhpFirebaseCloudMessaging\Client;

$server_key = '_YOUR_SERVER_KEY_';
$client = new Client();
$client->setApiKey($server_key);

$response = $client->addTopicSubscription('_SOME_TOPIC_ID_', ['_FIRST_TOKEN_', '_SECOND_TOKEN_']);
var_dump($response->getStatusCode());
var_dump($response->getBody()->getContents());

Remove user subscription to the topic

use sngrl\PhpFirebaseCloudMessaging\Client;

$server_key = '_YOUR_SERVER_KEY_';
$client = new Client();
$client->setApiKey($server_key);

$response = $client->removeTopicSubscription('_SOME_TOPIC_ID_', ['_FIRST_TOKEN_', '_SECOND_TOKEN_']);
var_dump($response->getStatusCode());
var_dump($response->getBody()->getContents());

Interpreting responses

Responses given on the HTTP requests are standard according to the FCM documentations. You may find detailed specifications in this links: * https://firebase.google.com/docs/cloud-messaging/http-server-ref#interpret-downstream * https://firebase.google.com/docs/cloud-messaging/http-server-ref#error-codes, (*8)

The Versions

16/07 2018

dev-master

9999999-dev https://github.com/sngrl/php-firebase-cloud-messaging

PHP API for Firebase Cloud Messaging from Google

  Sources   Download

MIT

The Requires

 

The Development Requires

by Redjan Ymeraj
by Avatar Sngrl

php cloud google ios android firebase chrome notifications fcm

21/04 2018

v1.1.4

1.1.4.0 https://github.com/sngrl/php-firebase-cloud-messaging

PHP API for Firebase Cloud Messaging from Google

  Sources   Download

MIT

The Requires

 

The Development Requires

by Redjan Ymeraj
by Avatar Sngrl

php cloud google ios android firebase chrome notifications fcm

21/04 2018

dev-develop

dev-develop https://github.com/sngrl/php-firebase-cloud-messaging

PHP API for Firebase Cloud Messaging from Google

  Sources   Download

MIT

The Requires

 

The Development Requires

by Redjan Ymeraj
by Avatar Sngrl

php cloud google ios android firebase chrome notifications fcm

18/09 2017

v1.1.3

1.1.3.0 https://github.com/sngrl/php-firebase-cloud-messaging

PHP API for Firebase Cloud Messaging from Google

  Sources   Download

MIT

The Requires

 

The Development Requires

by Redjan Ymeraj
by Avatar Sngrl

php cloud google ios android firebase chrome notifications fcm

21/08 2017

v1.1.2

1.1.2.0 https://github.com/sngrl/php-firebase-cloud-messaging

PHP API for Firebase Cloud Messaging from Google

  Sources   Download

MIT

The Requires

 

The Development Requires

by Redjan Ymeraj
by Avatar Sngrl

php cloud google ios android firebase chrome notifications fcm

04/05 2017

v1.1.1

1.1.1.0 https://github.com/sngrl/php-firebase-cloud-messaging

PHP API for Firebase Cloud Messaging from Google

  Sources   Download

MIT

The Requires

 

The Development Requires

by Redjan Ymeraj
by Avatar Sngrl

php cloud google ios android firebase chrome notifications fcm

13/03 2017

v1.1

1.1.0.0 https://github.com/sngrl/php-firebase-cloud-messaging

PHP API for Firebase Cloud Messaging from Google

  Sources   Download

MIT

The Requires

 

The Development Requires

by Redjan Ymeraj
by Avatar Sngrl

php cloud google ios android firebase chrome notifications fcm

25/02 2017

v1.0

1.0.0.0 https://github.com/sngrl/php-firebase-cloud-messaging

PHP API for Firebase Cloud Messaging from Google

  Sources   Download

MIT

The Requires

 

The Development Requires

by Redjan Ymeraj
by Avatar Sngrl

php cloud google ios android firebase chrome notifications fcm