2017 © Pedro Peláez
 

library gcm-message

Google Cloud Messaging (GCM) PHP Server Library

image

codemonkeys-ru/gcm-message

Google Cloud Messaging (GCM) PHP Server Library

  • Saturday, January 14, 2017
  • by iVariable
  • Repository
  • 9 Watchers
  • 58 Stars
  • 19,675 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 23 Forks
  • 2 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

Google Cloud Messaging (GCM) PHP Server Library

A PHP library for sending messages to devices registered through Google Cloud Messaging Build Status, (*1)

See: http://developer.android.com/guide/google/gcm/index.html, (*2)

Example usage


use \CodeMonkeysRu\GCM; $sender = new GCM\Sender("YOUR GOOGLE API KEY"); $message = new GCM\Message( array("device_registration_id1", "device_registration_id2"), array("data1" => "123", "data2" => "string") ); $message ->notification(array("title" => "foo", "body" => "bar")) ->setCollapseKey("collapse_key") ->setDelayWhileIdle(true) ->setTtl(123) ->setRestrictedPackageName("com.example.trololo") ->setDryRun(true) ->setPriority(GCM\MessageMessage::PRIORITY_HIGH) ; try { $response = $sender->send($message); if ($response->getNewRegistrationIdsCount() > 0) { $newRegistrationIds = $response->getNewRegistrationIds(); foreach ($newRegistrationIds as $oldRegistrationId => $newRegistrationId){ //Update $oldRegistrationId to $newRegistrationId in DB //TODO } } if ($response->getFailureCount() > 0) { $invalidRegistrationIds = $GCMresponse->getInvalidRegistrationIds(); foreach($invalidRegistrationIds as $invalidRegistrationId) { //Remove $invalidRegistrationId from DB //TODO } //Schedule to resend messages to unavailable devices $unavailableIds = $response->getUnavailableRegistrationIds(); //TODO } } catch (GCM\Exception $e) { switch ($e->getCode()) { case GCM\Exception::ILLEGAL_API_KEY: case GCM\Exception::AUTHENTICATION_ERROR: case GCM\Exception::MALFORMED_REQUEST: case GCM\Exception::UNKNOWN_ERROR: case GCM\Exception::MALFORMED_RESPONSE: //Deal with it break; } }

Also indirect message API available, (*3)


use \CodeMonkeysRu\GCM; $sender = new GCM\Sender("YOUR GOOGLE API KEY"); try { $response = $sender->sendMessage( array("device_registration_id1", "device_registration_id2"), array("data1" => "123", "data2" => "string"), "collapse_key" ); if ($response->getNewRegistrationIdsCount() > 0) { $newRegistrationIds = $response->getNewRegistrationIds(); foreach ($newRegistrationIds as $oldRegistrationId => $newRegistrationId){ //Update $oldRegistrationId to $newRegistrationId in DB //TODO } } if ($response->getFailureCount() > 0) { $invalidRegistrationIds = $GCMresponse->getInvalidRegistrationIds(); foreach($invalidRegistrationIds as $invalidRegistrationId) { //Remove $invalidRegistrationId from DB //TODO } //Schedule to resend messages to unavailable devices $unavailableIds = $response->getUnavailableRegistrationIds(); //TODO } } catch (GCM\Exception $e) { switch ($e->getCode()) { case GCM\Exception::ILLEGAL_API_KEY: case GCM\Exception::AUTHENTICATION_ERROR: case GCM\Exception::MALFORMED_REQUEST: case GCM\Exception::UNKNOWN_ERROR: case GCM\Exception::MALFORMED_RESPONSE: //Deal with it break; } }

Note about cURL SSL verify peer option

Library has turned off CURLOPT_SSL_VERIFYPEER by default, but you can enable it by passing third parameter into constructor of Sender class., (*4)

You need to download root certificates and add them somewhere into your project directory. Then construct Sender object like this:, (*5)


use \CodeMonkeysRu\GCM; $sender = new GCM\Sender("YOUR GOOGLE API KEY", false, "/path/to/cacert.crt");

ChangeLog

  • v0.5 - Added support for "priority" flag (https://github.com/CodeMonkeysRu/GCMMessage/pull/16)
  • v0.4 - Code cleanup, PHP5.5 support dropped
  • v0.3 - Content-available added (https://github.com/CodeMonkeysRu/GCMMessage/pull/11)
  • v0.2 - Notifications added
  • v0.1 - Initial release

Licensed under MIT license., (*6)

The Versions

14/01 2017

dev-master

9999999-dev

Google Cloud Messaging (GCM) PHP Server Library

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

gcm android push message

14/01 2017

v0.5

0.5.0.0

Google Cloud Messaging (GCM) PHP Server Library

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

gcm android push message

08/01 2017

v0.4

0.4.0.0

Google Cloud Messaging (GCM) PHP Server Library

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

gcm android push message

19/09 2016

v0.3

0.3.0.0

Google Cloud Messaging (GCM) PHP Server Library

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

gcm android push message

04/08 2015

0.2.0

0.2.0.0

Google Cloud Messaging (GCM) PHP Server Library

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

gcm android push message

22/04 2013

0.1

0.1.0.0

Google Cloud Messaging (GCM) PHP Server Library

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

gcm android push message