Skip to content
PHP Firebase Messaging
PHP
Branch: master
Clone or download

Latest commit

kbielenberg Merge pull request #18 from IIISpikerIII/master
Add multiple send topics with &&
Latest commit 49876eb Jul 2, 2018

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src add multiple send topics with && Feb 4, 2017
tests add multiple send topics with && Feb 4, 2017
.gitignore test restart Feb 6, 2017
.travis.yml travis, composer update for fix comparator Feb 4, 2017
LICENSE Initial commit May 25, 2016
README.md add multiple send topics with && Feb 4, 2017
composer.json Update version constraint Aug 8, 2016
composer.lock added tags Jun 3, 2016
phpunit.xml.dist added coverage reporting Jun 3, 2016

README.md

phpFCM

Build Status Coverage Status Latest Stable Version Total Downloads License

PHP application server implementation for Firebase Cloud Messaging.

#Setup The recommended way of installing is using Composer.

command line

composer require paragraph1/php-fcm

composer.json

"require": {
    "paragraph1/php-fcm": "*"
}

#Send to Device also see https://firebase.google.com/docs/cloud-messaging/downstream

use paragraph1\phpFCM\Client;
use paragraph1\phpFCM\Message;
use paragraph1\phpFCM\Recipient\Device;
use paragraph1\phpFCM\Notification;

require_once 'vendor/autoload.php';

$apiKey = 'YOUR SERVER KEY';
$client = new Client();
$client->setApiKey($apiKey);
$client->injectHttpClient(new \GuzzleHttp\Client());

$note = new Notification('test title', 'testing body');
$note->setIcon('notification_icon_resource_name')
    ->setColor('#ffffff')
    ->setBadge(1);

$message = new Message();
$message->addRecipient(new Device('your-device-token'));
$message->setNotification($note)
    ->setData(array('someId' => 111));

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

#Send to topic also see https://firebase.google.com/docs/cloud-messaging/topic-messaging

use paragraph1\phpFCM\Client;
use paragraph1\phpFCM\Message;
use paragraph1\phpFCM\Recipient\Topic;
use paragraph1\phpFCM\Notification;

require_once 'vendor/autoload.php';


$apiKey = 'YOUR SERVER KEY';
$client = new Client();
$client->setApiKey($apiKey);
$client->injectHttpClient(new \GuzzleHttp\Client());

$message = new Message();
$message->addRecipient(new Topic('your-topic'));
//select devices where has 'your-topic1' && 'your-topic2' topics
$message->addRecipient(new Topic(['your-topic1', 'your-topic2']));
$message->setNotification(new Notification('test title', 'testing body'))
    ->setData(array('someId' => 111));

$response = $client->send($message);
var_dump($response->getStatusCode());
You can’t perform that action at this time.