Firebase 云消息传递 - 如何验证令牌? [英] Firebase Cloud Messaging - How to validate Tokens?

查看:29
本文介绍了Firebase 云消息传递 - 如何验证令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Firebase Cloud Messaging (FCM),并且每次在客户设备上生成新令牌时都按照下面的缩写代码...我将这个新令牌发送到我的服务器数据库(云),在那里我按顺序保存它能够使用 CFM API 将未来的推送通知从服务器发送到设备.

I am using Firebase Cloud Messaging (FCM) and as per the abreviated code below everytime a new Token is generated on the Customer Device... I send this new TOKEN to my SERVER DB (Cloud) where I save it in order to be able to send future Push Notification from the Server to the Device using the CFM API.

    //public class CFMInstanceIDService extends FirebaseInstanceIdService ...

    public void onTokenRefresh() {
        ...
        String cfmToken = FirebaseInstanceId.getInstance().getToken();        
        ...     
        sendRegistrationToServer(customerGuid, cfmToken);
    }

通过这样做,我在服务器上有一个客户登录的所有(多个)设备的列表.(平板电脑、手机、iPhone、Android 等)

By doing this I have on the Server a list of ALL (multiples) Devices where a Customer is logged-in. (Tablet, Phone, iPhone, Android, etc)

有什么方法可以随时验证/验证令牌吗?

我想知道/确保我与客户关联的所有令牌都属于真实设备.我不想向不存在的令牌发送推送通知.

I would like to know/ensure that all the tokens that I have associated to a Customer belong to real Devices. I don't want to send Push Notifications to not-existing Tokens.

推荐答案

下面是一个示例 curl 请求,它展示了如何在无需实际发送消息的情况下验证令牌:

Here is an example curl request that shows how to validate a token without actually having to send a message:

curl -H "Content-Type: application/json" -H "Authorization: key=$FCM_API_KEY" https://fcm.googleapis.com/fcm/send -d '{"registration_ids":["$FCMTOKEN"]}'

无效响应示例:

{"multicast_id":7452350602151058088,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

示例有效响应:

{"multicast_id":9133870199216310277,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1502817580237626%f590ddc2f9fd7ecd"}]}

我从 google 的 firebase 支持团队那里得到了这个答案.

I got this answer from google's firebase support team.

这篇关于Firebase 云消息传递 - 如何验证令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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