分組推播 API
最新更新:2023-03-03
功能說明
該 API 用於應用程式分組創建推播,一次調用則可對該分組下的所有應用程式進行訊息推播。
- 暫不支援 option 中 override_msg_id 的屬性。
- 分組推播僅在控製台推播時支援設定定時任務,不支援調用 Schedule API 設定定時任務。
調用驗證
HTTP Header(頭)裏加一個字段(Key/Value對):
Authorization: Basic ${base64_auth_string}
Authorization: Basic ${base64_auth_string}
此代碼塊在浮窗中顯示
即上述 base64_auth_string 的生成算法為:base64(username:password)
Header 名稱是 "Authorization",值是 base64 轉換過的 "username:password" 對(中間有個冒號)。
在分組推播 API 的場景裏,username 是 “group-” 前綴加上 GroupKey,password 是 Group Master Secret。這二者可以在控製台【分組管理】-【編輯】中查看。
調用地址
POST v4/grouppush
請求示例
curl --insecure -X POST -v https://push.api.engagelab.cc/v4/grouppush
-H "Content-Type: application/json"
-u "c96f42e0d2e662e45d035ab1:df4d59e84eac2f9d53b36f12"
-d '{
"from": "push",
"to": "all",
"body": {
"platform": "all",
"notification": {
"android": {
"alert": "Hi, Push!",
"title": "Send to Android",
"builder_id": 1,
"extras": {
"newsid": 321
}
},
"ios": {
"alert": "Hi, MTPush!",
"sound": "default",
"badge": "+1",
"extras": {
"newsid": 321
}
}
},
"message": {
"msg_content": "Hi,MTPush",
"content_type": "text",
"title": "msg",
"extras": {
"key": "value"
}
},
"options": {
"time_to_live": 60,
"apns_production": false
}
},
"request_id": "12345678",
"custom_args": "business info"
}'
> POST /v4/grouppush HTTP/1.1
> Authorization: Basic Yzk2ZjQyZTBkMmU2NjJlNDVkMDM1YWIxOmRmNGQ1OWU4NGVhYzJmOWQ1M2IzNmYxMg==
curl --insecure -X POST -v https://push.api.engagelab.cc/v4/grouppush
-H "Content-Type: application/json"
-u "c96f42e0d2e662e45d035ab1:df4d59e84eac2f9d53b36f12"
-d '{
"from": "push",
"to": "all",
"body": {
"platform": "all",
"notification": {
"android": {
"alert": "Hi, Push!",
"title": "Send to Android",
"builder_id": 1,
"extras": {
"newsid": 321
}
},
"ios": {
"alert": "Hi, MTPush!",
"sound": "default",
"badge": "+1",
"extras": {
"newsid": 321
}
}
},
"message": {
"msg_content": "Hi,MTPush",
"content_type": "text",
"title": "msg",
"extras": {
"key": "value"
}
},
"options": {
"time_to_live": 60,
"apns_production": false
}
},
"request_id": "12345678",
"custom_args": "business info"
}'
> POST /v4/grouppush HTTP/1.1
> Authorization: Basic Yzk2ZjQyZTBkMmU2NjJlNDVkMDM1YWIxOmRmNGQ1OWU4NGVhYzJmOWQ1M2IzNmYxMg==
此代碼塊在浮窗中顯示
請求參數
請求參數參考 創建推播 API 。
返回示例
成功回響
{
"0c3de43c6a6b68c9f4261b06": {"request_id":"12345678","msg_id":"2460001"},
"35c424abde12f475566ca8af": {"request_id":"12345678","msg_id":"2460001"},
"8f02a4fa717a6235734d92de": {"request_id":"12345678","msg_id":"2460001"},
"group_msgid": "cbou2uum98lps87rtic0"
}
{
"0c3de43c6a6b68c9f4261b06": {"request_id":"12345678","msg_id":"2460001"},
"35c424abde12f475566ca8af": {"request_id":"12345678","msg_id":"2460001"},
"8f02a4fa717a6235734d92de": {"request_id":"12345678","msg_id":"2460001"},
"group_msgid": "cbou2uum98lps87rtic0"
}
此代碼塊在浮窗中顯示
失敗回響
{
"code":400,
"data":"",
"message":"錯誤信息"
}
{
"code":400,
"data":"",
"message":"錯誤信息"
}
此代碼塊在浮窗中顯示
錯誤碼
詳情參考 「創建推播 API - 調用返回」。