如何在时间发送GCM消息到多个设备多个、消息、时间、设备

2023-09-06 10:30:00 作者:从心动走到古稀

我要发送同样的消息到多个设备使用GCM机器人。目前,我能发送推送通知到我的设备,因为我明确地指定我的注册ID在PHP中code。但我想将它发送到多个设备,这样我怎么能做到这一点??? 任何帮助或想法是非常AP preciated。

I want to send same message to multiple devices in android using GCM. Currently i am able to send push notification to my device as i am explicitly specifying my registration ID in PHP code. But i want to send it to multiple devices so how can i do this??? Any help or idea are highly appreciated.

请指导本 谢谢

推荐答案

你应该做的是发送多个注册ID(最多1000个一次),当您发送邮件到GCM,你将需要使用JSON作为您的请求格式。

What you should do is send multiple registrations Ids (up to 1000 at once) when you send your message to GCM, and you will need to use JSON as your request format.

您可以阅读更多有关在这里: https://developers.google.com/cloud-messaging/server-ref#downstream

You can read more about that here: https://developers.google.com/cloud-messaging/server-ref#downstream

您需要将您的ID的列表添加到 registration_ids 字段:

You will need to add your list of Id's to the registration_ids field:

一个字符串数组与设备(注册编号)接收消息的列表。它必须包含至少1个和至多1000注册的ID。要发送多播消息,您必须使用JSON。要发送一个消息到一台设备,你可以使用一个JSON对象只有1注册ID,或纯文本(见下文)。必选。

A string array with the list of devices (registration IDs) receiving the message. It must contain at least 1 and at most 1000 registration IDs. To send a multicast message, you must use JSON. For sending a single message to a single device, you could use a JSON object with just 1 registration id, or plain text (see below). Required.

下面是从他们的文档为例请求:

Here is an example request from their docs:

下面是一个有效载荷和6收件人的邮件:

Here is a message with a payload and 6 recipients:

{ "data": {
   "score": "5x1",
   "time": "15:10"
  },
  "registration_ids": ["4", "8", "15", "16", "23", "42"]
}