Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kero's avatar
Level 1

firebase - which user received message and which user didn't?

i have the following function to send firebase messages to some tokens

 public function Send(array $tokens): bool
    {
        $header = [
            'Authorization: Key= Your API_KEY' ,
            'Content-Type: Application/json'
        ];
        $payload = [
            'registration_ids' => $tokens,
            'notification' => [
                'title' => 'Testing Notification',
                'body' => 'Testing Notification from localhost',
                'icon' => 'img/icon.png',
                'image' => 'img/d.png',
                "click_action" => "http://localhost/RealTimeLaravelApp/public/"
            ],
        ];
        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => "https://fcm.googleapis.com/fcm/send",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => json_encode($payload),
            CURLOPT_HTTPHEADER => $header
        ));
        $response = curl_exec($curl);
        $response = json_decode($response, TRUE);
        $err = curl_error($curl);

        curl_close($curl);
        dd($response);
        if ($err) {
//            echo "cURL Error #:" . $err;
            return false;
        } else {
            return ($response['success'] ?? 0) > 0;
        }

    }

when i call the api it returns

array:5 [
  "multicast_id" => 1234646
  "success" => 3
  "failure" => 0
  "canonical_ids" => 0
  "results" => array:1 [
    0 => array:1 [
      "message_id" => "0:21321321"
    ]
  ]
]

i want to know which user received message and which user didn't ?

at least which token is valid and which is invalid ?

0 likes
0 replies

Please or to participate in this conversation.