本文介绍了在使用PHP发送推送通知之前,FCM验证设备令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有fcm令牌,有些令牌用于发送推送通知.

I have fcm tokens in my database and for some tokens are used to send push notifications.

一切正常.但是需要优化,因为我得到了一些设备令牌

Everything is working fine as required.But there is optimization required since some device token I am getting

string(116)
"{
"multicast_id": 1234,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [{
  "error": "NotRegistered"
}]
}
"

是否可以帮助我在发送推送通知之前验证设备令牌(如果已注册)?

Could any help me verify device token if registered already before sending push notification?

推荐答案

您可以使用实例ID服务器参考GET API .如果您收到类似以下的响应,则表明该令牌仍然有效.

You can verify if a token in your database is still valid or not using the Instance ID Server Reference GET API. If you got a response similar to below, it means that the token is still valid.

示例GET请求:

https://iid.googleapis.com/iid/info/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA?details=true
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

示例结果

HTTP 200 OK
{
  "application":"com.iid.example",
  "authorizedEntity":"123456782354",
  "platform":"Android",
  "attestStatus":"ROOTED",
  "appSigner":"1a2bc3d4e5",
  "connectionType":"WIFI",
  "connectDate":"2015-05-12
  "rel":{
    "topics":{
      "topicname1":{"addDate":"2015-07-30"},
      "topicname2":{"addDate":"2015-07-30"},
      "topicname3":{"addDate":"2015-07-30"},
      "topicname4":{"addDate":"2015-07-30"}
    }
  }
}

这篇关于在使用PHP发送推送通知之前,FCM验证设备令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 13:21