2017 © Pedro Peláez
 

library php-fcm-wrapper

PHP wrapper for FCM

image

talalm/php-fcm-wrapper

PHP wrapper for FCM

  • Tuesday, July 11, 2017
  • by TalalM
  • Repository
  • 1 Watchers
  • 0 Stars
  • 18,274 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 1 Versions
  • 3 % Grown

The README.md

php-fcm-wrapper

PHP Wrapper for the FCM API, (*1)

Installation

You can install the wrapper using Composer:, (*2)

composer require talalm/php-fcm-wrapper

Usage

Using the wrapper is pretty straightforward., (*3)

The first thing you need to do is create a client with your API key, (*4)

$client = new FCM\Client("YOUR_API_KEY");

Send a simple notification

The tokens are put in an array on the registration_ids parameter., (*5)

And the notification title is put in the parameter notification.body_loc_key, (*6)

Example:, (*7)

$client->send([
    'registration_ids' => ['token1', 'token2', ...],
    'notification' => ['body_loc_key' => 'This is a notification sent via php-fcm-wrapper']
]);

Add notification parameters

You can add additional parameters to the notification :, (*8)

  • The badge value (defaults to 1)
  • The sound value (defaults to 'notif.caf')

Example:, (*9)

$client->send([
    'registration_ids' => ['token1', 'token2', ...],
    'notification' => ['body_loc_key' => 'This is a revolution',
                       'badge' => 1789
                       'sound' => 'la-marseillaise.caf'],
]);

Additional data

Also, if you have additional data that you want to add to your notification, just add it to the data parameter, (*10)

$client->send([
    'registration_ids' => ['token1', 'token2', ...],
    'notification' => ['body_loc_key' => 'This is a revolution',
                       'badge' => 1789
                       'sound' => 'la-marseillaise.caf'],
    // Additional data
    'data' => ['king' => 'Louis XVI',
               'location' => 'La Bastille']
]);

Change notification priority

The default notification priority is set to high (to always be sent). You can put it to normal if you want (then the receiving client system will choose when to display it)., (*11)

$client->send([
    'registration_ids' => ['token1', 'token2', ...],
    'notification' => ['body_loc_key' => 'This is a revolution',
                       'badge' => 1789
                       'sound' => 'la-marseillaise.caf'],
    // Additional data
    'data' => ['king' => 'Louis XVI',
               'location' => 'La Bastille'],
    'priority' => 'normal'
]);

And that's it!, (*12)

APNS Batch import

If you are migrating from another service (Parse for example) and you already have APNS tokens on your database, you can batch import them to Firebase., (*13)

To do so, just call the batchImport method with the following parameters:, (*14)

  • application: Bundle id of the application
  • sandbox: Boolean to indicate sandbox environment (TRUE) or production (FALSE) - default to true
  • apns_tokens: The array of APNs tokens for the app instances you want to add or remove. Maximum 100 tokens per request.

Example:, (*15)

$client->batchImport([
    'application' => "com.french.revolution",
    'apns_tokens' => ["Robespierre's token", "Danton's token", "Louis XVI's token", ...],
    'sandbox' => false,
]);

The Versions

11/07 2017

dev-master

9999999-dev

PHP wrapper for FCM

  Sources   Download

MIT

The Requires