dev-master
9999999-devPHP wrapper for FCM
MIT
The Requires
PHP wrapper for FCM
PHP Wrapper for the FCM API, (*1)
You can install the wrapper using Composer:, (*2)
composer require talalm/php-fcm-wrapper
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");
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'] ]);
You can add additional parameters to the notification :, (*8)
Example:, (*9)
$client->send([ 'registration_ids' => ['token1', 'token2', ...], 'notification' => ['body_loc_key' => 'This is a revolution', 'badge' => 1789 'sound' => 'la-marseillaise.caf'], ]);
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'] ]);
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)
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)
Example:, (*15)
$client->batchImport([ 'application' => "com.french.revolution", 'apns_tokens' => ["Robespierre's token", "Danton's token", "Louis XVI's token", ...], 'sandbox' => false, ]);
PHP wrapper for FCM
MIT