英文:
How to verify received token from firebase for device in php/laravel?
问题
我有一个移动应用程序,我从Firebase获取设备令牌,通过用户的设备令牌向设备发送通知。
我没有使用Firebase/Google身份验证等。
我只是使用云消息传递来发送通知,我需要设备令牌,以便向特定用户发送通知。现在,我需要在将令牌存储到数据库之前验证接收到的令牌。
如何验证从Firebase接收到的设备令牌,以确保该令牌存在/真实?
英文:
I have a mobile application which I'm getting device token from firebase, to send notification to device by user's device token.
I'm not using firebase/google authentication or etc.
I'm just using cloud messaging to send notification, which I need device token, to send notifications to specific users and right now, I need to validate the token before application store token in DB.
How to verify received device token from firebase to make sure the token is exist/real?
答案1
得分: 0
以下是翻译好的部分:
最简单的方法是使用令牌发送一个基本的空消息。
如果输入错误的令牌,你会收到以下响应:
成功响应的情况下,你的结果将是:
所以一般来说,需要解码 JSON 响应并检查结果。
英文:
Easiest way was to send a basic and empty message using the token.
$response = Http::withHeaders(['Authorization' => 'key=token'])
->post('https://fcm.googleapis.com/fcm/send', [
'registration_ids' => [ tokens here ],
]);
If you enter wrong token, you'll get response like below :
{
"multicast_id": xxxxxxxxxxxxxxxxx,
"success": 0,
"failure": 1,
"canonical_ids": 0,
"results": [
{
"error": "InvalidRegistration"
}
]
}
Which in case of success response your result will be :
{
"multicast_id": xxxxxxxxxxxxxxxxx,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "x:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}
]
}
So in general, need to decode json response and just check the result.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论