如何使用FCM向特定用户发送通知? [英] How to send notification to specific users with FCM?

查看:90
本文介绍了如何使用FCM向特定用户发送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些关于这个问题的信息。我为FCM准备了接收器,并且可以向所有设备发送通知。 使用此链接的

gcm-http.googleapis.com/gcm/send 可以发送给已注册并发布到目标设备的目标用户像下面的json:

  {
notification:{
title:sample Title ,
text:sample text},
to:[registration id]
}

例如:

  {
notification:{
title:样本标题,
text:示例文本},
转换为:[电子邮件或姓名或性别...]
}

我该怎么做?
我需要创建一个web服务器还是其他的东西?

解决方案


需要创建一个web服务器

是的。您需要一个地方,您可以将名称/电子邮件映射到注册ID。这些注册ID必须包含在对FCM的请求中,例如

  {
'registration_ids':['qrgqry34562456 ','245346236ef'],
'通知':{
'body':'',
'title':''
},
'data' :{

}
}

'qrgqry34562456'和'245346236ef'。



您在调用中使用的注册ID是应用程序中此回调中称为token的注册ID。



$ p $ public class MyService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh(){
}
}


I need some information for this question.I prepared the receiver for FCM and can send a notification to all devices.

gcm-http.googleapis.com/gcm/send with this link can send to target users who is registered and post to the target devices like below json :

 {
     "notification": {
                "title": "sample Title",
                "text": "sample text"   },   
        "to" : "[registration id]"
         }

However, I need to send notifications to target users which I choose, via email or name...etc . For example:

{
     "notification": {
                "title": "sample Title",
                "text": "sample text"   },   
        "to" : "[email or name or sex ...]"
         }

How can I do that? Do I need to create a web server or something else?

解决方案

Did I need to create a web server

Yes. You need a place where you can map name/email to registration IDs. These registration IDs must be included in the request to FCM, for example

{
    'registration_ids': ['qrgqry34562456', '245346236ef'],
    'notification': {
        'body': '',
        'title': ''
    },
    'data': {

    }
}

will send the push to 'qrgqry34562456' and '245346236ef'.

The registration ID you use in the call is the one that's called 'token' in this callback in the app.

public class MyService extends FirebaseInstanceIdService {
    @Override
    public void onTokenRefresh() {
    }
}

这篇关于如何使用FCM向特定用户发送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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