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

查看:79
本文介绍了在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链接.
  1. a link.
  2. B link.

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

推荐答案

我正在实现您的代码.

I am implementing your code.

使用在设备(ios/android)中生成的firebase registration token 而不是设备令牌. '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天全站免登陆