8

Tôi gặp phải vấn đề lạ khi gửi thông báo đẩy tới android bằng FCM.Vấn đề về thông báo đẩy FCM: - "lỗi": "NotRegistered"

Mục tiêu: - Có lỗi khi gửi push thông báo

Dưới đây là kịch bản tôi có chức năng gửi thông báo push to android

public static function SendMultipleNotificationAndroid($groups) 
    { 
     //your api key SERVER API KEY 
     $apiKey = Yii::$app->params['android_api_key']; 
     $url = 'https://fcm.googleapis.com/fcm/send';  
     $headers = array(
      'Authorization:key=' . $apiKey, 
      'Content-Type: application/json' 
     ); 

     $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_SSL_VERIFYPEER, false); 

     foreach($groups as $resG){ 
      $users = $resG['users'];       
      $msg = $resG['message']; 
      $type = $resG['notification_type']; 
      $notification_data = $resG['notification_data']; 

      $deviceTokens = []; 
      foreach($users as $resUser){ 
       $deviceTokens[] = $resUser['device_token']; 
       //Add Friend badge count +1 
       Common::AddRemoveBadgeCount($resUser['user_id']); 
      } 
      if(!empty($deviceTokens)){ 
       $fields = array(
        'registration_ids' => $deviceTokens, 
        'priority'  => 'high', 
        'collapse_key' => $resG['notification_type'], 
        'time_to_live' => 2419200,  
        "click_action" =>"NotificationListingActivity",  
        'data'   => [     
         "title"    => "ProjectName", 
         "body"    => $resG['message'], 
         "action_tag"  => $resG['notification_type'], 
         "message"   => $resG['message'], 
         'notification_type' => $type, 
         'notification_data' => $notification_data, 
         'sound'    => 'default', 
        ] 
       ); 
       //Print result 
       p($ch,0); 
       curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 
       curl_exec($ch); 
      }    
     } 
     curl_close($ch); 
    } 

Vì vậy, vấn đề là khi tôi gửi thông báo duy nhất nó hoạt động tốt nhưng khi tôi gửi nhiều thông báo tôi đã nhận lỗi mỗi lần

<pre>Resource id #5</pre>{"multicast_id":4818908994630396118,"success":1,"failure":1,"canonical_ids":0,"results":[{"error":"NotRegistered"},{"message_id":"0:1487136045570022%c3bae3c6002e9358"}]} 

<pre>Resource id #5</pre>{"multicast_id":5218359780835228544,"success":1,"failure":1,"canonical_ids":0,"results":[{"error":"NotRegistered"},{"message_id":"0:1487136046618669%c3bae3c6002e9358"}]} 

Khi chúng tôi gỡ lỗi mã, chúng tôi có mã thông báo thiết bị trong cơ sở dữ liệu của chúng tôi không có tường lửa dừng gửi thông báo đẩy.

Mỗi lần tôi gọi trên chức năng tôi đã nhận

"lỗi": "NotRegistered"

Bất kỳ trợ giúp sẽ được đánh giá cao.

Xin cảm ơn trước.

Trả lời

5

Không biết nhiều về php, nhưng gần đây tôi đã phải đối mặt với cùng một vấn đề trong một dự án khác và tôi đã được giải quyết theo cách này:

refere này đầu tiên: Where can I find the API KEY for Firebase Cloud Messaging?

và nhận khóa API được cập nhật như được hiển thị bên dưới ảnh chụp nhanh enter image description here

+0

Có thể là trường hợp, hãy để tôi xem xét vấn đề và thử! Tôi sẽ lấy lại cho bạn sớm! Cảm ơn! –

+0

Bravo! đang làm việc! –

+0

@maddy điều này đã không làm việc cho tôi. Tôi đã thay đổi phím máy chủ khi thực hiện yêu cầu nhưng tôi vẫn gặp lỗi tương tự. – AIon

Các vấn đề liên quan