通过 RESTful API发送远程通知
概要
可使用RESTful API ,向用户发送远程通知。
远程通知只能使用模板。
使用RESTful API 发送远程通知的样例见这里。
RemoteNotificationSample-Server_20160112.zip
※ 在 Client Credentials Grant 中发送广播通知的样例。
URI Fragment
Sandbox
https://sb-app.mobage.jp/social/api/restful/v2/remote_notification/@app/\{groupId\}
https://sb-app.mobage.jp/social/api/restful/v2/remote_notification/@app/@all/\{recipientId\}
正式环境
https://app.mobage.jp/social/api/restful/v2/remote_notification/@app/\{groupId\}
https://app.mobage.jp/social/api/restful/v2/remote_notification/@app/@all/\{recipientId\}
参数名 | 类型 | 说明 |
|---|---|---|
| groupId | 字符串 | 可指定@all、@android、@ios 中的任意一项。 |
| recipientId | 用户 ID | 指定单个用户发送远程通知时,发送对象的用户 ID |
签名方式
- Client Credentials Grant
- Authorization Code Grant
在Authorization Code Grant 中,不能使用广播(@all、@android、@ios)发送。
HTTP 方法
- Client Credentials Grant
- POST Remote Notification 发送
- Authorization Code Grant
- POST Remote Notification 发送
请求报头
- Authorization 报头为必须。
- Content-Type: application/json; charset=utf-8
URL 查询参数
无
请求正文
带有下述参数的 JSON 字符串。详情请参见下述实例。
名称 | 类型 | 说明 | 必须 |
|---|---|---|---|
| recipientId | 用户 ID 数组 | 指定用户发送远程通知时,最多可在数组中指定 1000 名用户。 与@all、@android、@iOS 配合使用。 | No |
| payload | 对象 | 包括下述远程通知内容和设置等的对象。 | Yes |
| payload.message | 字符串 | 远程通知的信息内容。会显示在通知栏中。 请使用UTF-8字符串进行指定。 | Yes |
| payload.badge | 数值 | 仅限 iOS 。 向iOS终端发送远程通知后,badge 数值被用作接收端的图标徽章。badge 未指定时,不会发送数字。 对Android终端,可以不发送badge。 | No |
| payload.sound | 字符串 | 仅限 iOS 。 向iOS终端发送远程通知后,被用作接收端的警报声。 sound 是应用软件中的语音文件名。 语音文件不存在时、指定"default"时,播放默认警报声。 对Android终端,即使指定sound 仍会被忽略,不播放声音。 | No |
| payload.collapseKey | 字符串 | 仅限 Android 。 | No |
| payload.style | 字符串 | 仅限 Android 。 向Android终端发送远程通知后,用作通知区的风格。 风格未指定或风格不能使用时,会指定默认风格。有效风格为"normal"和"largeIcon"。 对Native / Unity SDK ,只能在Android 2.3及更高版本中使用。 详细请见这里。对iOS终端,即使指定style 仍会被忽略。 | No |
| payload.iconUrl | 字符串 | 仅限 Android 。 向Android终端发送远程通知后,且 style 指定时,iconUrl 用于决定在Android通知区显示的示意图。 对iOS终端,即使指定iconUrl 仍会被忽略。 | No |
| payload.extras | 对象 | 可使用 Key/Value 的格式,设置任意的1层联想数组。 例){ "foo" : "1", "bar" : "twenty one" } | No |
响应代码
| HTTP 状态代码 | HTTP 状态信息 | 说明 |
|---|---|---|
| 201 | Created | 数据创建成功时 |
| 202 | Accepted | 数据更新成功时 |
| 400 | Bad Request | 客户端请求数据不当 |
| 401 | Unauthorized | 认证错误 |
| 403 | Forbidden | 资源存在,但由于认证错误以外的原因导致不能访问的情况 |
| 404 | Not Found | 资源不存在 |
| 429 | Too Many Requests | 请求数量超出限制 Game to All User 通知只能每小时发送 1 次 |
| 500 | Internal Server Error | API 服务器端错误 |
| 503 | Service Unavailable | 暂时不可用时 |
响应正文
- 远程通知的发送结果。可能是空白。
- Content-Type: application/json; charset=utf-8
实例
向全部应用用户发送广播通知(Client Credentials Grant)
HTTP 请求
POST /social/api/restful/v2/remote_notification/@app/@all HTTP/1.1 Content-Type: application/json; charset=utf-8 { "payload": { "extras": { "bar": false, "foo": 1 }, "message": "hello notification" } } |
HTTP 响应
HTTP/1.0 202 Accepted Content-Type: application/json; charset=utf-8 Content-Length: 0 Connection: close Date: Thu, 10 Oct 2013 02:54:21 GMT Server: Unknown |
向限定的多个用户发送广播通知(Client Credentials Grant)
HTTP 请求
POST /social/api/restful/v2/remote_notification/@app/@all HTTP/1.1 Content-Type: application/json; charset=utf-8 { "payload": { "extras": { "bar": false, "foo": 1 }, "message": "hello notification" }, "recipientId": [ "134889", "134890" ] } |
HTTP 响应
HTTP/1.0 202 Accepted Content-Type: application/json; charset=utf-8 Content-Length: 182 Connection: close Date: Wed, 30 Oct 2013 07:40:06 GMT Server: Unknown { "groupId": "@all", "payload": { "extras": { "bar": false, "foo": 1 }, "message": "hello notification" }, "published": "2013-10-30T07:40:06", "recipientId": [ "sb.mbga.jp:134889", "sb.mbga.jp:134890" ] } |
向单人用户发送Game-to-User 远程通知(Client Credentials Grant)
HTTP 请求
POST /social/api/restful/v2/remote_notification/@app/@all/132835 HTTP/1.1 Content-Type: application/json; charset=utf-8 { "payload": { "extras": { "bar": false, "foo": 1 }, "message": "hello notification" } } |
HTTP 响应
HTTP/1.0 201 Created Content-Type: application/json; charset=utf-8 Content-Length: 201 Connection: close Date: Thu, 10 Oct 2013 03:22:05 GMT Server: Unknown { "id": "zeI83iJikTWEkPE6/7ZzyQ==", "payload": { "extras": { "bar": false, "foo": 1 }, "message": "hello notification" }, "published": "2013-10-10T03:22:05", "recipientId": "sb.mbga.jp:132835", "senderId": "sb.mbga.jp:0" } |
向单人用户发送User-to-User 远程通知(Authorization Code Grant)
HTTP 请求
POST /social/api/restful/v2/remote_notification/@app/@all/132835 HTTP/1.1 Content-Type: application/json; charset=utf-8 { "payload": { "extras": { "bar": false, "foo": 1 }, "message": "hello notification" } } |
HTTP 响应
HTTP/1.0 201 Created Content-Type: application/json; charset=utf-8 Content-Length: 205 Connection: close Date: Thu, 10 Oct 2013 03:38:16 GMT Server: Unknown { "id": "Bxdeu223Fj+TCKpjzCiAUw==", "payload": { "extras": { "bar": false, "foo": 1 }, "message": "hello notification" }, "published": "2013-10-10T03:38:16", "recipientId": "sb.mbga.jp:132835", "senderId": "sb.mbga.jp:38215" } |
更新履历
- 2015/01/12
- 请求方法为非 Client Credentials Grant 、Authorization Code Grant ,故修改。