Ph3nol / NotificationPusher

Standalone PHP library for easy devices notifications push.
MIT License
1.18k stars 273 forks source link

400 Bad Request error in case of Android push #184

Open maedamin opened 5 years ago

maedamin commented 5 years ago

I am sure that it worked before, but recently I found the following log in laravel.log.

local.ERROR: exception 'Sly\NotificationPusher\Exception\PushException' with message '400 Bad Request; invalid message' in /mnt/home/apache/....../vendor/sly/notification-pusher/src/Sly/NotificationPusher/Adapter/Gcm.php:72

I tested it by creating a simple program, and I confirmed that it works for iOS, meaning that the contents of the message would be OK. But I faced the same error of '400' in case of Android.

I found the following source code in the server.

    public function push(PushInterface $push)
    {
        $client        = $this->getOpenedClient();
        $pushedDevices = new DeviceCollection();
        $tokens        = array_chunk($push->getDevices()->getTokens(), 100);

        foreach ($tokens as $tokensRange) {
            $message = $this->getServiceMessageFromOrigin($tokensRange, $push->getMessage());

            try {
                $this->response = $client->send($message);
            } catch (ServiceRuntimeException $e) {
                throw new PushException($e->getMessage());
            }

            if ((bool) $this->response->getSuccessCount()) {
                foreach ($tokensRange as $token) {
                    $pushedDevices->add($push->getDevices()->get($token));
                }
            }
        }

        return $pushedDevices;
    }

The error occurred at $this->response = $client->send($message); (When I checked the source code in GitHub, and I found that the source code is slightly different. Should I update it??)

This is my first time to open an issue in GitHub, so I am not sure how I should do... Anyway, any information is very helpful because I am now in stuck ....

maedamin commented 5 years ago

Well. After the investigation, I found that GCM would be terminated... We need to use Firebase? If so, how should I update it?

maedamin commented 5 years ago

I updated the all to the new one and the error message has gone. But, push message does not reach devices though there is no error log. I also tried $params['notificationData'] method described in https://github.com/Ph3nol/NotificationPusher/issues/181. (I have not changed any in Android App. It still just supports GCM.)

centotaure commented 5 years ago

Up ! I have exactly the same error when i send pushnotification for android ! And it's works before !!! Have you find a solution @maedamin ?

zeeshanaslam78 commented 5 years ago

GCM is not working anymore. It needs to update accordingly FCM. Getting same 400 bad request error