將批次直接傳送至裝置控制碼的集合
將通知批次直接傳送至裝置控制碼集合, (以通知類型表示的有效權杖) 。 此 API 適用于 基本層和標準層通知中樞命名空間。 此 API 的使用者不需要使用註冊或安裝。 相反地,此 API 的使用者會自行管理所有裝置,並使用通知中樞作為傳遞服務來與各種推播通知服務通訊。
目前,Direct Batch Send 支援每個要求最多 1000 部裝置。
注意
只要 Google 透過其 Firebase 雲端通訊 (FCM) 舊版 API支援 Google 雲端通訊) ,我們就會繼續支援 Google 雲端通訊 (GCM。 此 API 尚不支援 Firebase 雲端通訊 (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 、 apple 、、 gcm 、 windowsphone 、 nokiax adm 、 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 | 已建立。 |
400 | 找不到所提供之多部分內容的一部分。 |
401 | 授權失敗。 存取金鑰不正確。 |
403 | 超過配額或訊息太大;訊息遭到拒絕。 |
404 | URI 沒有訊息分支。 |
413 | 要求的實體太大。 訊息大小不能超過 64 Kb。 |
如需狀態碼的相關資訊,請參閱 狀態和錯誤碼。
回應標頭
回應標頭 | 描述 |
---|---|
Content-Type | application/xml;charset=utf-8 |
位置 | 此標頭僅適用于標準層通知中樞。 此標頭將包含通知訊息識別碼。 它會與每個訊息遙測搭配使用:取得通知訊息遙測,並讓 PNS 意見反應相互關聯。 位置標頭使用下列格式: https://{your namespace}.servicebus.windows.net/{your hub name}/messages/{notification message id}?api-version=2015-04 |
回應本文
None