M
M
Michael2018-04-08 03:25:55
PHP
Michael, 2018-04-08 03:25:55

Successfully sending push notifications, but not coming to the browser, how to fix it?

Good day, I want to add notifications to my corporate website.
I'm testing this code, everything seems to be fine, but notifications are not displayed in the browser, although everything has been sent.
Maybe there are some ideas?

$YOUR_API_KEY = '111111111111111111111111111'; // Server key
        $YOUR_TOKEN_ID = '11111111111111111111111111111';

        $header = array();
        $header[] = 'Content-type: application/json';
        $header[] = 'Authorization: key=' . $YOUR_API_KEY;

        $payload = [
            'to' => $YOUR_TOKEN_ID,
            'notification' => [
                "title" => "Background Message Title",
                "body" => "Background message body",
                "click_action" => "https://dummypage.com"
            ]
        ];

        $crl = curl_init();
        curl_setopt($crl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($crl, CURLOPT_POST, true);
        curl_setopt($crl, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
        curl_setopt($crl, CURLOPT_POSTFIELDS, json_encode($payload));

        curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);

        $rest = curl_exec($crl);
        if ($rest === false) {
            return curl_error($crl);
        }
        curl_close($crl);

string(143) "{"multicast_id":5610005296187892937,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1523146332213697%e609af1cf9fd7ecd"}]} "

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question