การลงทะเบียนไม่ถูกต้องขณะส่งการแจ้งเตือนแบบพุชใน php

ฉันกำลังติดตาม การใช้งานฝั่งเซิร์ฟเวอร์ Firebase Cloud Messaging (FCM) นี้. แต่ได้รับข้อผิดพลาด invalidregistrationid

เข้ากูเกิ้ลแล้วไม่พบอะไรเลย ฉันยังพบปัญหาที่เกี่ยวข้องซึ่งได้รับการตอบไปแล้วใน StackOverflow แต่ไม่มีวิธีแก้ปัญหา ลิงค์ต่อไปนี้ที่ฉันเยี่ยมชมเพื่อดูวิธีแก้ปัญหา

  1. ลิงก์
  2. ลิงก์ 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"}]}

ความช่วยเหลือใด ๆ ที่จะได้รับการชื่นชม. ขอบคุณ


person Developer    schedule 05.06.2019    source แหล่งที่มา
comment
stackoverflow.com/ คำถาม/39614607/   -  person Karan Sadana    schedule 05.06.2019
comment
สวัสดี @Dharman ฉันไม่ได้ใช้ไฟล์ pem ฉันใช้โทเค็นการเข้าถึง firebase สำหรับการแจ้งเตือนแบบพุช   -  person Developer    schedule 08.06.2019
comment
ฉันไม่ใช่ผู้เชี่ยวชาญเกี่ยวกับ Firebase แต่อย่างใดฉันรู้ว่าคุณไม่ควรปิดการใช้งานทั้งสองตัวเลือกนี้ อ่านบทความที่ลิงก์แบบเต็ม บางทีอาจช่วยให้คุณตั้งค่า cUrl บน firebase ได้อย่างถูกต้องเช่นกัน   -  person Dharman    schedule 08.06.2019
comment
@Dharman ขอบคุณสำหรับข้อเสนอแนะของคุณ แต่ข้อผิดพลาดของฉันได้รับการแก้ไขแล้ว   -  person Developer    schedule 08.06.2019


คำตอบ (1)


ฉันกำลังติดตั้งโค้ดของคุณ

ใช้ firebase registration token ที่สร้างขึ้นในอุปกรณ์ (ios/android) แทนโทเค็นอุปกรณ์ 'registration_ids' => (array)$token,

หวังว่ามันจะเป็นประโยชน์

person Community    schedule 05.06.2019