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

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

问题描述

我为 FCM 准备了接收器,并且可以向所有设备发送通知.

I prepared the receiver for FCM and can send a notification to all devices.

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

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

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

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': {

    }
}

会将推送发送到qrgqry34562456"和245346236ef".

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

您在调用中使用的注册 ID 是在应用的此回调中称为令牌"的 ID.

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天全站免登陆