在php中发送推送通知时注册无效 [英] Invalid registration while sending push notification in php

查看:32
本文介绍了在php中发送推送通知时注册无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注这个 Firebase 云消息传递 (FCM) 服务器端执行..但得到 invalidregistrationid 的错误.

I am following this Firebase Cloud Messaging (FCM) Server Side Implementation. . but got an error of invalidregistrationid.

使用谷歌搜索但一无所获.我还发现了一些已经在 StackOverflow 上回答的相关问题.但没有解决方案.我访问了以下链接以获取解决方案.

Did googling but found nothing. I also found some related problem which already answered on StackOverflow. but got no solutions. the following link I visited for the solution.

  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"}]}

任何帮助将不胜感激.谢谢

Any help will be appreciated. thanks

推荐答案

我正在实施您的代码.

使用在设备(ios/android)中生成的firebase注册令牌而不是设备令牌.'registration_ids' =>(array)$token,

Use firebase registration token it generated in device (ios/android) instead of the Device token . 'registration_ids' => (array)$token,

希望对你有帮助

这篇关于在php中发送推送通知时注册无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆