0

I have written an API in PHP which will receive Firebase token and will send push notification to Android device.

I have tested Android side code and it receiving sample notification from Firebase console using token. But when I am trying to send from PHP api then it's not sending notification.

Here is my php API.

// send firebase push notifcaiton
            $url = 'https://fcm.googleapis.com/fcm/send';
                $api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx';

                $fields = array (
                    'registration_ids' => array (
                    $pnsToken
                ),
                    'data' => array (
                        "message" => $message,
                        "guestId" => $guestId,
                        "guestEntryId" => $guestEntryId,
                        "guestName" => $guestName,
                        "guestAddress" => $guestAddress,
                        "reason" => $reason
                    )
                );

            //header includes Content type and api key
            $headers = array(
                'Content-Type:application/json',
                'Authorization:key='.$api_key
            );

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
            $result = curl_exec($ch);
            if ($result === FALSE) {
                die('FCM Send Error: ' . curl_error($ch));
            }
            curl_close($ch);

I don't know why it's not sending push notification from PHP api.

Edit

Here is fcm error which I am receiving :

"fcmResult": "{\"multicast_id\":7084003691931660410,\"success\":0,\"failure\":1,\"canonical_ids\":0,\"results\":[{\"error\":\"NotRegistered\"}]}",
halfer
  • 19,824
  • 17
  • 99
  • 186
Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160

0 Answers0