【问题标题】:How to track the FCM push notification whether is is delivered or not using message id如何使用消息 ID 跟踪 FCM 推送通知是否已交付
【发布时间】:2016-09-21 12:19:36
【问题描述】:

我正在使用 PHP Restful 服务通过 Firebase Cloud Messaging(FCM) 向 Android 设备发送推送通知。

使用以下 URL,我能够成功地将消息发布到 FCM 并获得相应的消息 ID。

https://gcm-http.googleapis.com/gcm/send

但是如何使用上面的消息ID知道消息是否传递到设备。

任何帮助将不胜感激。

【问题讨论】:

  • 试试我下面的答案

标签: php android firebase push-notification google-cloud-messaging


【解决方案1】:

这是一个简单的 JSON 消息成功发送给一个收件人的简单案例,但响应中没有规范 ID:

{ "multicast_id": 108,
  "success": 1,
  "failure": 0,
  "canonical_ids": 0,
  "results": [
    { "message_id": "1:08" }
  ]
}

以下是 6 个收件人(ID 分别为 4、8、15、16、23 和 42)的 JSON 结果,其中 3 条消息成功处理,1 个规范注册令牌返回,3 个错误:

{ "multicast_id": 216,
  "success": 3,
  "failure": 3,
  "canonical_ids": 1,
  "results": [
    { "message_id": "1:0408" },
    { "error": "Unavailable" },
    { "error": "InvalidRegistration" },
    { "message_id": "1:1516" },
    { "message_id": "1:2342", "registration_id": "32" },
    { "error": "NotRegistered"}
  ]
}

成功将表明请求已成功处理。它可能无法告知消息的确切传递。

如需全面了解,请read

【讨论】:

  • 如何知道通知是否成功发送给用户?
  • 如果您希望让 Google 保留用于最终将 msg 传递到设备的数据,以防在传递消息时设备处于脱机状态。
  • 当设备确认收到 CCS 发送的消息时,您可以使用上游消息获取送达回执(从 CCS 发送到您的第 3 方应用服务器)。
  • 我们不能使用消息ID跟踪消息吗?
  • 不与您正在使用的 HTTP 连接服务器
【解决方案2】:

试试这个:在 php 端,你会得到 fcm 的响应,比如

{
    "multicast_id":8042731220476088762,
    "success":1,
    "failu‌‌​​re":0,
    "canonical_‌​i‌​ds":0,
    "results":[‌​{"message_id"‌​:"0:‌​1474456734183‌​863%97d‌​a1d69f9fd7e‌​cd"}]
} 

如果成功为 1,则消息将传递到该 id

【讨论】:

  • 是的,我收到了这个回复,虽然消息没有发送到设备,但成功为 1。我想知道通知是否已使用消息 ID 成功发送给用户
  • 你有什么解决办法吗?我已经将节点 js 用于服务器端。它没有在 ios 设备中接收。但我得到了这样的回应。成功发送消息{结果:[{messageId:'0:1615964641473163%473af62ef9fd7ecd'}],canonicalRegistrationTokenCount:0,failureCount:0,successCount:1,multicastId:2860856613764255000}
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-20
  • 2017-03-16
  • 2017-02-23
  • 2020-04-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多