跳到主要内容

通过 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 中的任意一项。

在请求正文内的 JSON 中,无 recipientId 指定时:
@all: 向全部应用用户发送远程通知。
@android: 只向 Android 应用用户发送远程通知。
@ios: 只向 iOS 应用用户发送远程通知。

在请求正文内的 JSON 中,有 recipientId 指定时:
@all: 向recipientId 指定的用户发送。
@android: 只针对Android 终端,向recipientId 指定的用户发送。
@ios: 只针对iOS 终端,向recipientId 指定的用户发送。

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 。
向Android终端发送远程通知后,当对象终端离线时,只发送最后信息所需的任意字符串。
在Android终端上,会替换显示任意的字符串。
但是,远程通知不保证通知顺序,不能保证是否真的是最后信息。另外,collapseKey 未指定时,会指定全部相同的字符串。对iOS终端,即使指定collapseKey 仍会被忽略。

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 状态信息说明
201Created数据创建成功时
202Accepted数据更新成功时
400Bad Request客户端请求数据不当
401Unauthorized认证错误
403Forbidden资源存在,但由于认证错误以外的原因导致不能访问的情况
404Not Found资源不存在
429Too Many Requests请求数量超出限制 Game to All User 通知只能每小时发送 1 次
500Internal Server ErrorAPI 服务器端错误
503Service 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 ,故修改。