Minishlink / web-push-php-example

An example for sending Web Push notifications, using web-push-php
MIT License
252 stars 89 forks source link

Push does not arrive #15

Closed stefanseeger closed 5 years ago

stefanseeger commented 5 years ago

Hello, it was very easy installing you demo app

Unfortunately, after clicking "Send notification" nothing is happening in the browser. I;m using PHP 7.1.12 (cli) on windows with (latest) Chrome Version 69.0.3497.100

I added some logs to sendNotification which might help you to debug.

subscription: Minishlink\WebPush\Subscription Object ( [endpoint:Minishlink\WebPush\Subscription:private] => https://fcm.googleapis.com/fcm/send/cfIDjGLRER0:APA91bFq7aPUHUOPlneOcO0zauX2K4byaEEdd9ge5VBFZ77-y1K5IRJSQFPqOquKk0rZLGUZBd_nlK1p-66i50_kf_hJZe7pydLeHfsDhagDdLTwN1jHJHJ-Rb-l4Y9Razw1MajUqWcX [publicKey:Minishlink\WebPush\Subscription:private] => BL9nvphgzIwCxn3ar2OaMj6IYtJtWoq5x7qnLhHvGvVh3djJxOVOfCuqKpnbtBFEGjFBOLQOGczQbnI0pCF9OWI= [authToken:Minishlink\WebPush\Subscription:private] => QTy6ZYhnXMNsU+HQ0IC8HA== [contentEncoding:Minishlink\WebPush\Subscription:private] => aes128gcm ) payload: Payload Hello auth: Array ( ) notifications: flush: 1

Best regards, Stefan

t1gor commented 5 years ago

Seems like you've got an empty autharrray:

| auth: Array ( )

Check this line for instructions.

dukedrake commented 5 years ago

I ran into the exact same problem. I'm running PHP 7.2 Seems the "auto flush" doesn't work properly, or the example needs to continue and iterate the Generator $res ?

I found that if you change the call sendNotification() to

$res = $webPush->sendNotification(
    $subscription,
    "Hello!",
    false
);

and then manually call the "flush()"(🙄)-method similar to the example in the readme of the library:

foreach ($webPush->flush() as $report) {
    $endpoint = $report->getRequest()->getUri()->__toString();

    if ($report->isSuccess()) {
        echo "[v] Message sent successfully for subscription {$endpoint}.";
    } else {
        echo "[x] Message failed to sent for subscription {$endpoint}: {$report->getReason()}";
    }
}

Also, the $auth-variable is empty because it isn't transmitted in the call to the sendNotification()-function and the function doesn't fallback on the member variable ($this->auth) set in the constructor. (Check this line for reference) However, this doesn't seem to prevent the notification from being sent 🤔

Anyway, very handy library! Keep it up! 👍

stefanseeger commented 5 years ago

I ran into the exact same problem. I'm running PHP 7.2 Seems the "auto flush" doesn't work properly, or the example needs to continue and iterate the Generator $res ?

I found that if you change the call sendNotification() to

$res = $webPush->sendNotification(
    $subscription,
    "Hello!",
    false
);

and then manually call the "flush()"(🙄)-method similar to the example in the readme of the library:

foreach ($webPush->flush() as $report) {
    $endpoint = $report->getRequest()->getUri()->__toString();

    if ($report->isSuccess()) {
        echo "[v] Message sent successfully for subscription {$endpoint}.";
    } else {
        echo "[x] Message failed to sent for subscription {$endpoint}: {$report->getReason()}";
    }
}
  • it works! =) Tested in both chrome and firefox.

Also, the $auth-variable is empty because it isn't transmitted in the call to the sendNotification()-function and the function doesn't fallback on the member variable ($this->auth) set in the constructor. (Check this line for reference) However, this doesn't seem to prevent the notification from being sent 🤔

Anyway, very handy library! Keep it up! 👍

Thanks it works now!