Giter Club home page Giter Club logo

php-gcm's Introduction

php-gcm

Build Status Total Downloads

Why

Google Cloud Messaging for Android is very powerful, but there are a lot of details to handle. This library takes care of the details and makes GCM very easy to use with PHP.

Support

php-gcm supports the HTTP server protocol for GCM. There is not currently support for XMPP, but implementations and pull requests for XMPP are welcome. See #3 for more details.

php-gcm supports PHP versions >= 5.3.10. php-gcm may work on older versions of PHP, but has not been tested on them.

Install

Composer is the easiest way to manage dependencies in your project. Create a file named composer.json with the following:

{
    "require": {
        "php-gcm/php-gcm": "^1.1.1"
    }
}

And run Composer to install php-gcm:

$ curl -s http://getcomposer.org/installer | php
$ composer.phar install

Latest

php-gcm follows SEMVER. If you would like to try out the latest, possibly unstable or incorrect code, the dependency can be pointed to dev-master.

{
    "require": {
        "php-gcm/php-gcm": "dev-master"
    }
}

Usage

$sender = new Sender($gcmApiKey);
$message = new Message($collapseKey, $payloadData);

try {
    $result = $sender->send($message, $deviceRegistrationId, $numberOfRetryAttempts);
} catch (\InvalidArgumentException $e) {
    // $deviceRegistrationId was null
} catch (PHP_GCM\InvalidRequestException $e) {
    // server returned HTTP code other than 200 or 503
} catch (\Exception $e) {
    // message could not be sent
}

License

php-gcm is licensed under the Apache 2.0 License. See the LICENSE file for more details.

php-gcm's People

Contributors

cainmi avatar chancezeus avatar charl13 avatar lkorth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-gcm's Issues

Usage guide

Hi thanks a lot for this but I'm hoping I can ask a newbie question:

I know I have to create the files in my server's folder. But how would I implement sending, would I incorporate the "Usage" section of the readme in my regular php file? If so what are the $collapsekey and $payloaddata supposed to be? I'm assuming payloaddata is the actual message, but not sure what collapsekey would be.

Support for Firebase Cloud Messaging (FCM)

Google has introduced Firebase Cloud Messaging (FCM) as a replacement of GCM and started to strongly encourage to upgrade:

Is GCM going to be deprecated?

We will continue to support the current version of GCM Android and iOS SDKs because we know a lot of developers are using GCM SDKs today to handle notifications, and client app upgrade takes time.

But all new client-side features will be added to FCM SDKs only moving forward. You are strongly encouraged to upgrade to FCM SDKs.

Do you think Firebase Cloud Messaging will be supported by your library or as a new php-fcm project?

Full port of Java GCM code with tests

Apparently we both embarked on the same mission to port the GCM code at around the same time.

Instead of doing a loosly port I did a full port including the unittests.

Would you be interested to see if we can merge the two efforts?

About your class

Hello
There is many class for send gcm push but is different
I searched in google and knew that if device no receive push,maybe json data is invalid
do you have idea for this problem?

I have a question about php-gcm.

I'm using the PHP CI framework should be sure to use the composer?
Is there any way to run without using the composer?

If you have more detailed usage it seems to be good.

$ Sender = new Sender ($ gcmApiKey);
$ Message = new Message ($ collapseKey, $ payloadData);

try {
$ Result = $ sender-> send ($ message, $ deviceRegistrationId, $ numberOfRetryAttempts);
} Catch (\ InvalidArgumentException $ e) {
// $ DeviceRegistrationId was null
} Catch (PHP_GCM \ InvalidRequestException $ e) {
// Server returned HTTP code other than 200 or 503
} Catch (\ Exception $ e) {
// Message could not be sent
}

What methods can be used to add a phrase in getBodyLocKey?

Simultaneous sending limit

GCM has a hard limit of 1000 device ids per request to their server. Just wondering if your library has taken care of this details? Or do we need to array_chunk ourselves?

Cheers
Ken

Complex data in push message

The following code:

<?php
    $message = new \PHP_GCM\Message();
    $message->addData('test', ['xxx' => 'yyy']);
    $client = new \PHP_GCM\Sender($this->apiKey);
    $client->send($message, $token, $this->retryTimes);

generates an error: Expecting string but array id found.

The other function:

<?php
    $message = new \PHP_GCM\Message();
    $message->addData('test', ['xxx' => 'yyy']);
    $client = new \PHP_GCM\Sender($this->apiKey);
    $client->sendMulti($message, $token, $this->retryTimes);

works with no exceptions, but the JSON object comes as a string:

{
    "test": "{\"xxx\":\"yyy\"}"
}

Example usage

Hi,
your example usage doesn't work anymore.
Please can you update your docs?

Another question: How can I get the registration IDs which reproduce an InvalidRegistration error to remove these IDs of my database. It worked well in a former version.

Best regards
Tobias

Composer installs old version

Hey there,

when I use require lkorth "php-gcm/php-gcm": "^1.1.1" I always get an old version from 2013 with no support for multi-device push messages. Is the package name correct?

Thanks,
Henning

Support for Web Push Payload Encryption

Hello, as you know Google Chrome Push Notifications use GCM. But there is a downside:

A downside to the current implementation of the Push API in Chrome is that you can’t send any data with a push message. Nope, nothing. The reason for this is that in a future implementation, payload data will have to be encrypted on your server before it’s sent to a push messaging endpoint. This way the endpoint, whatever push provider it is, will not be able to easily view the content of the push message. This also protects against other vulnerabilities like poor validation of HTTPS certificates and man-in-the-middle attacks between your server and the push provider. However, this encryption isn’t supported yet, so in the meantime you’ll need to perform a fetch to get information needed to populate a notification.

In those months Google has implemented a solution that will be available in the new version Chrome 50 at the end of April 2016.

Do you think this kind of encrypted payload can be implemented into your library?

Assign errors to the registration id

I send notification to multiple users via the sendMulti()-function. Then I get the response and process through the results with the getResults()-method.
But if a registration id is no longer registered (error NotRegistered), how can I figure out which registration id is no longer registered?

Put a release onto composer?

There have been a lot of changes to this repo since the last composer release. Could maintainers drop a release by chance? @lkorth

I do see the "master" note in README, but would be good to actually bump this. Latest release is over a year old

Google Cloud Messaging (GCM) Notification receiving with logs detail

I have implement the gcm to send notification to my application and its really working perfect.

I am getting notification on device but issue is that I am getting logs detail may be in notification message instead of only human readable message that I am pushing.

screenshot_2015-11-12-09-07-04

Here is my code that I am using to send notification:

$gcmApiKey = GOOGLE_API_KEY;
$pushApi = new PushAPI();
$sender = new \PHP_GCM\Sender($gcmApiKey);
$message = new \PHP_GCM\Message("1", $messsageVal);
try {
    $multicastResult = $sender->sendMulti($message, $deviceRegistrationId, 2);
    $results = $multicastResult->getResults();
    for ($i = 0; $i < count($deviceRegistrationId); $i++) {
        $regId = $deviceRegistrationId[$i];
        $result = $results[$i];
        $messageId = $result->getMessageId();
        if ($messageId != null) {
            $canonicalRegId = $result->getCanonicalRegistrationId();
            if ($canonicalRegId != null) {
                // same device has more than on registration id: update it
            }
        } else {
            $error = $result->getErrorCodeName();
            if ($error == \PHP_GCM\Constants::$ERROR_NOT_REGISTERED) {
                $pushApi->clearDeviceByDeviceId($regId);
            }
        }
    }
} catch (\InvalidArgumentException $e) {
    // $deviceRegistrationId was null
} catch (PHP_GCM\InvalidRequestException $e) {
    // server returned HTTP code other than 200 or 503
} catch (\Exception $e) {
    // message could not be sent
}

Any help will be appreciated.

Thanks in Advance.

Firebase server sends old messages

PHP_GCM was working fine for a couple of weeks. During this time we collected more than 6000 subscribers on our website. Then suddenly Chrome users were getting the same old message again and again. Sending new messages caused the delivery of the same old message. Android users are not affected, only Chrome Web users.

We tried to contact Firebase support but they are not willing to support a third-party library or to provide any debugging support.

We are sending notifications without payload which is much quicker than the encryption needed for each single message. We also tried it with encrypted payloads but our production process dies after sending about 1300 messages. So far we could not find the root cause of this issue. However, in this case Firebase was sending the correct messages to our Chrome users.

In my opinion this is a clear bug in Firebase because the payload we send does not contain a two week old message. Does anyone else have similar issues?

Thanks,
Christoph

Composer.json

I'm trying out your php port of Google GCM, i copy pasted the files in the src directory to my servers directory where all my other php files are housed. I've added the line:

"require": {
    "php-gcm/php-gcm": "1.1.0"
}

in the composer.json file you already had created. I am stuck in the step that says run composer.json

How do I run it when its housed in my server? I've tried opening it in the browser but that just gives me the date within it.

Release 1.1.1 has outdated end point

File src/Constants.php Line number: 28

This https://android.googleapis.com/gcm/send url getting 302. I think url should be https://gcm-http.googleapis.com/gcm/send like this

sending multidimensional in sendNoRetry()

Why i can send multidimensional array in sendNoRetryMulti and I can't in sendNoRetry? I think you can change the code to send json enconded arrays in sendNoRetry too. If you doesn't have time, maybe, i can do i pull request to you.

Thank you.

Migration to FCM

As GCM is now deprecated and will be disabled on April 2019, will we have a new release 1.1.2 with FCM support?
I see that we already have an updated URL to FCM in master branch.

Why PHP version 5.3.29?

Hi,

It is not a issue, just a question.

I need to run this package on a PHP 5.3.10 installation. Then, before doing anything, could anyone tell me why this package requires PHP 5.3.29?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.