你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

将批处理直接发送到设备句柄集合

将一批通知直接发送到设备句柄集合, (由通知类型) 表示的有效令牌。 此 API 适用于 基本层和标准层通知中心命名空间。 此 API 的用户不需要使用注册或安装。 相反,此 API 的用户自行管理所有设备,并仅将通知中心用作传递服务来与各种推送通知服务进行通信。

目前,Direct Batch Send 支持每个请求最多 1000 台设备。

注意

只要 Google 通过 Firebase Cloud Messaging (FCM) 旧 API 支持 Google Cloud Messaging (GCM) ,我们一直支持它。 此 API 尚不支持 Firebase Cloud Messaging (FCM) 。

请求

方法 请求 URI HTTP 版本
POST https://{namespace}.servicebus.windows.net/{NotificationHub}/messages/$batch?direct&api-version=2015-08 HTTP/1.1

请求标头

下表介绍必需的和可选的请求标头。

请求标头 说明
授权 服务总线的共享访问签名身份验证中指定的方式生成的 SAS 令牌。 有关详细信息,请参阅 基本概念
Content-Type multipart/mixed; boundary="boundary-string"

边界字符串用于根据 RFC1341 中定义的多部分内容类型分隔每个部分。 每个部件都以封装边界开头,然后包含由标头区域、空白线和正文区域组成的正文部分。
ServiceBusNotification-Format 将 设置为以下有效的 PlatformType 值之一:windows、、applegcmwindowsphoneadmnokiax、、 。 baidu
x-ms-version 2015-04 (2015-01 及更高版本支持)

请求正文

请求正文是 RFC1341 中定义的多部分。 每个部件都以封装边界开头,然后包含由标头区域、空白线和正文区域组成的正文部分。 空白链接不得包含任何空格。 请参阅下面的请求示例。

根据目标平台类型,通知部件的正文格式将更改为符合以下本机发送 API 中所述的每个单独的平台。

请求正文的设备部分必须是将接收通知的设备句柄的 JSON 数组。

请求示例

下面是一个 WNS 示例:

POST https://{namespace}.servicebus.windows.net/{Notification Hub}/messages/$batch?direct&api-version=2015-08 HTTP/1.1
Content-Type: multipart/mixed; boundary = "simple-boundary"
Authorization: SharedAccessSignature sr=https%3a%2f%2f{Namespace}.servicebus.windows.net%2f{Notification Hub}%2fmessages%2f%24batch%3fdirect%26api-version%3d2015-08&sig={Signature}&skn=DefaultFullSharedAccessSignature
ServiceBusNotification-Format: windows
X-WNS-Type: wns/toast
Host: {Namespace}.servicebus.windows.net
Content-Length: 514
Expect: 100-continue
Connection: Keep-Alive


--simple-boundary
Content-type: text/xml
Content-Disposition: inline; name=notification

<toast><visual><binding template="ToastText01"><text id="1">Hello there!</text></binding></visual></toast>
--simple-boundary
Content-type: application/json
Content-Disposition: inline; name=devices

['https://db5.notify.windows.com/?token={Token1}','https://db5.notify.windows.com/?token={Token2}','https://db5.notify.windows.com/?token={Token3}']
--simple-boundary--

下面是一个 GCM 示例:

POST https://{Namespace}.servicebus.windows.net/{Notification Hub}/messages/$batch?direct&api-version=2015-08 HTTP/1.1
Content-Type: multipart/mixed; boundary="simple-boundary"
Authorization: SharedAccessSignature sr=https%3a%2f%2f{Namespace}.servicebus.windows.net%2f{Notification Hub}%2fmessages%2f%24batch%3fdirect%26api-version%3d2015-08&sig={Signature}&skn=DefaultFullSharedAccessSignature
ServiceBusNotification-Format: gcm
Host: {Namespace}.servicebus.windows.net
Content-Length: 431
Expect: 100-continue
Connection: Keep-Alive


--simple-boundary
Content-Type: application/json
Content-Disposition: inline; name=notification

{"data":{"message":"Hello via Direct Batch Send!!!"}}
--simple-boundary
Content-Type: application/json
Content-Disposition: inline; name=devices

['Device Token1','Device Token2','Device Token3']
--simple-boundary--

下面是 APNS 示例:

POST https://{Namespace}.servicebus.windows.net/{Notification Hub}/messages/$batch?direct&api-version=2015-08 HTTP/1.1
Content-Type: multipart/mixed; boundary="simple-boundary"
Authorization: SharedAccessSignature sr=https%3a%2f%2f{Namespace}.servicebus.windows.net%2f{Notification Hub}%2fmessages%2f%24batch%3fdirect%26api-version%3d2015-08&sig={Signature}&skn=DefaultFullSharedAccessSignature
ServiceBusNotification-Format: apple
Host: {Namespace}.servicebus.windows.net
Content-Length: 511
Expect: 100-continue
Connection: Keep-Alive


--simple-boundary
Content-Type: application/json
Content-Disposition: inline; name=notification

{"aps":{"alert":"Hello using APNS via Direct Batch Send!!!"}}
--simple-boundary
Content-Type: application/json
Content-Disposition: inline; name=devices

['Device Token1','Device Token2','Device Token3']
--simple-boundary--

响应

响应包括 HTTP 状态代码和一组响应标头。 成功时不会返回响应正文。

响应代码

代码 说明
201 Created.
400 找不到提供的多部分内容的一部分。
401 授权失败。 访问密钥不正确。
403 已超出配额或消息太大;消息被拒绝。
404 URI 中没有消息分支。
413 请求的实体太大。 消息大小不能超过 64 Kb。

有关状态代码的信息,请参阅 状态和错误代码

响应头

响应标头 说明
Content-Type application/xml;charset=utf-8
位置 此标头仅适用于标准层通知中心。

此标头将包含通知消息 ID。 它与按消息遥测:获取通知消息遥测和关联 PNS 反馈一起使用。 位置标头使用以下格式:

https://{your namespace}.servicebus.windows.net/{your hub name}/messages/{notification message id}?api-version=2015-04

响应正文

另请参阅

直接发送
发送 APNS 本机通知
发送 GCM 本机通知
发送 MPNS 本机通知
发送 WNS 本机通知