coreproc / gcm
Google Cloud Messaging library for PHP
Installs: 1 526
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 6
Forks: 6
Open Issues: 3
Requires
- guzzlehttp/guzzle: 5.*
This package is auto-updated.
Last update: 2020-09-11 22:20:44 UTC
README
A PHP library that allows you to send messages / push notifications to devices with your Android application installed.
Quick start
Required setup
The easiest way to install this library is via Composer.
Create a composer.json
file and enter the following:
{
"require": {
"coreproc/gcm": "0.1.*"
}
}
If you haven't yet downloaded your composer file, you can do so by executing the following in your command line:
curl -sS https://getcomposer.org/installer | php
Once you've downloaded the composer.phar file, continue with your installation by running the following:
php composer.phar install
Usage
Basic Usage
The example below gives you a bare minimum of what to do to send a message / push notification.
<?php require 'vendor/autoload.php'; use Coreproc\Gcm\GcmClient; use Coreproc\Gcm\Classes\Message; $gcmClient = new GcmClient('your-gcm-api-key-here'); $message = new Message($gcmClient); $message->addRegistrationId('xxxxxxxxxx'); $message->setData([ 'title' => 'Sample Push Notification', 'message' => 'This is a test push notification using Google Cloud Messaging' ]); // More options are available in the Message class try { $response = $message->send(); // The send() method returns a Response object print_r($response); } catch (Exception $exception) { echo 'uh-oh: ' . $exception->getMessage(); }
How to obtain a GCM API key
- Log in to https://console.developers.google.com
- Create a new project and select the project after the project is created.
- Select the "APIs" option on the left menu sidebar.
- Look for "Google Cloud Messaging for Android" and turn it on.
- Next, go to "Credentials" option on the left menu sidebar.
- Click on the "Create new Key" button and make a new "Server Key".
- Enter the IP address of your server and hit "Create".
- Your API key should now appear on the page.
More Information
All options from the [https://developer.android.com/google/gcm/http.html](GCM HTTP Connection) are implemented in this library and they can be found in the Message
class.
For more documentation on what options you can use, please refer to: https://developer.android.com/google/gcm/http.html.