问题描述
我正在使用Firebase Cloud Messaging(FCM),并且每次在客户设备上生成新令牌时,都按照下面的缩写代码...将此新令牌发送到我的SERVER DB(云)中,按顺序将其保存以便将来能够使用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 Cloud Messaging-如何验证令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!