Pendaftaran tidak valid saat mengirim pemberitahuan push di php

Saya mengikuti Implementasi Sisi Server Firebase Cloud Messaging (FCM).. tetapi mendapat kesalahan invalidregistrationid.

Apakah googling tetapi tidak menemukan apa pun. Saya juga menemukan beberapa masalah terkait yang sudah terjawab di StackOverflow. tapi tidak mendapat solusi. link berikut ini saya kunjungi untuk solusinya.

  1. tautan.
  2. Tautan B.
class abc{
  function send_android_notification($registration_ids="2fa86bbc8bc4aee204255a0d84461c000a26442312d0a9b1df1664d461fd3b7d") {
      $message = array('title' => 'CodeCastra', 'body' => "hi huye" ,'sound'=>'Default','image'=>'Notification Image' );
      define("GOOGLE_API_KEY", "AIzaSyDDvpPcWfOTVkkvA-yQg4yTYzIuh0MNIRw"); //legacy server key
      $fields = array(
          'registration_ids' => (array)$registration_ids,
          'notification' => $message, //note: body & title fileds must be specified for the message or your only get just the vibration but the notification
      );
      $headers = array(
          'Authorization: key=' . GOOGLE_API_KEY, //  FIREBASE_API_KEY_FOR_ANDROID_NOTIFICATION
          'Content-Type: application/json'
      );
      //Open connection
      $ch = curl_init();
      //Set the url, number of POST vars, POST data
      curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      // Disabling SSL Certificate support temporarly
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
      //echo json_encode($fields);
      //print_r($headers);
      //exit;
      //Execute post
      $result = curl_exec($ch);
      if ($result === false) {
          die('Curl failed:' . curl_errno($ch));
      }
      // Close connection
      curl_close($ch);
      return $result;
  }

}

print_r((new abc)->send_android_notification());
die;
{"multicast_id":4707836736661373968,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

Bantuan apa pun akan dihargai. terima kasih


person Developer    schedule 05.06.2019    source sumber
comment
stackoverflow.com/ pertanyaan/39614607/   -  person Karan Sadana    schedule 05.06.2019
comment
hai @Dharman saya tidak menggunakan file pem saya menggunakan token akses firebase untuk pemberitahuan push   -  person Developer    schedule 08.06.2019
comment
Saya bukan ahli Firebase, tapi bagaimanapun saya tahu Anda tidak boleh menonaktifkan kedua opsi ini. Baca artikel terkait selengkapnya, mungkin dapat membantu Anda mengatur cUrl di firebase dengan benar juga.   -  person Dharman    schedule 08.06.2019
comment
@Dharman terima kasih atas saran Anda tetapi kesalahan saya telah terpecahkan   -  person Developer    schedule 08.06.2019


Jawaban (1)


Saya menerapkan kode Anda.

Gunakan firebase registration token yang dihasilkan di perangkat (ios/android) alih-alih token Perangkat. 'registration_ids' => (array)$token,

Semoga bermanfaat

person Community    schedule 05.06.2019