OPPO开放平台 服务端单点推送

单点推送主要用于向一个特定的用户推送同一条消息的场景。一条单点推送消息对应一个推送目标,对应一个消息ID。

OPPO开放平台 服务端单点推送

单点推送

单点推送

单点推送主要用于向一个特定的用户推送同一条消息的场景。一条单点推送消息对应一个推送目标,对应一个消息ID。针对批量的单点推送任务,OPPO PUSH提供批量的单点推送接口可供开发者一次性发起多条单点推送服务。
和广播推送相比,单点推送无需预先保存消息体,而是在调用推送消息接口的同时传入消息内容。
为方便表述,以下部分内容介绍会将单点推送简称为单推。

单点推送接口

接口详情

描述内容
接口功能发送通知栏消息
请求方法POST
Content-Typeapplication/x-www-form-urlencoded
请求编码UTF-8
请求路径/server/v1/message/notification/unicast

请求参数

参数定义:

名称类型必须默认描述
auth_tokenstring鉴权令牌,详见鉴权一章。
messageString消息体参数,接受一个嵌套的JSON结构,推送目标和具体消息内容均在这个字段中配置。

message字段是一个JSON结构参数,接受的字段及含义如下:

名称类型必须默认描述
target_typeShort推送的目标类型 2: registration_id 5: 别名
target_valueString推送目标,按taget_type对应填入,仅接受一个值。
notificationJSON通知栏消息内容,参考消息体内容定义,按照JSON格式填入
verify_registration_idBooleanFALSE消息到达客户端后是否校验registration_id。 true表示推送目标与客户端registration_id进行比较,如果一致则继续展示,不一致则就丢弃;false表示不校验

message示范:

{
		"target_type": 2,
		"target_value": "CN_078ad8b8a137cadb14ae5b70cf846312",
		"verify_registration_id": true,
        // notification是一个嵌套在message的json,配置通知栏消息内容和参数
		"notification": {
				"appMessageId": null,
				"style": 1,
				"bigPictureId": null,
				"smallPictureId": null,
				"title": "您的订单已取消",
				"subTitle": null,
				"content": "您的订单(realme X7…) 已取消",
				"clickActionType": 4,
				"clickActionActivity": "com.realme.store.home.view.MainActivity",
				"clickActionUrl": null,
				"actionParameters": "{\"messageNo\":null,\"title\":\"您的订单已取消\",\"desc\":\"您的订单(realme X7…) 				已取消\",\"type\":null,\"redirectType\":2,\"resource\":\"1\",\"version\":1}",
				"showTimeType": 0,
				"showStartTime": null,
				"showEndTime": null,
				"offLine": true,
				"offLineTtl": 86400,
				"pushTimeType": 0,
				"pushStartTime": null,
				"timeZone": null,
				"fixSpeed": null,
				"fixSpeedRate": null,
				"networkType": null,
				"callBackUrl": null,
				"callBackParameter": null,
				"channelId": "message",
				"showTtl": 0,
				"notifyId": 1
				}
}

响应参数(JSON)

名称类型必须描述
codeInt返回码,请参考公共返回码与接口返回码
messageString请求响应信息
dataString响应返回值,正确响应后包含消息ID

推送请求调用成功响应示例:

{
    code:0,
    message: "",
    data : {
       // 消息ID 格式为 AppID-1-1-全局唯一性ID
       messageId : ZngnvJIM7wQusNtbqYnpH6XX-1-1-622ff7cfae27668d2ed3afec,
       } 
}

推送目标存在问题响应示例:
推送请求调用失败,但推送目标存在问题

{
    code:1000,
    message: "registration_id格式不正确
}

返回码(code)

Code英文描述中文描述
10000Invalid Registration_idregistration_id格式不正确

批量单推接口

接口

描述内容
接口功能批量发送单推通知栏消息
请求方法POST
Content-Typeapplication/x-www-form-urlencoded
请求编码UTF-8
请求路径/server/v1/message/notification/unicast_batch

请求参数

和推送单条消息的单推接口相比,批量单推接口使用messages字段容纳不少于一条的消息推送参数。messages字段是一个JSON数组,里面的一个元素和单推接口参数中的message相同。
以下是参数定义:

名称类型必须默认描述
auth_tokenstring鉴权令牌,详见鉴权一章。
messagesString通知栏消息JSON数组字符串,示例:[{message},{message}]【最多1000个】

message:

名称类型必须默认描述
target_typeShort目标类型 2: registration_id , 5:别名
target_valueString推送目标用户: registration_id或alias
notificationJSON通知栏消息内容,参考消息体内容定义,按照JSON格式填入
verify_registration_idBooleanFALSE消息到达客户端后是否校验registration_id。 true表示推送目标与客户端registration_id进行比较,如果一致则继续展示,不一致则就丢弃;false表示不校验

一个批量单推接口的messages参数范例

[
	// 传入两个推送目标和推送内容,将会产生两条单推推送消息
	{
		"target_type":2,
		"target_value":"CN_906bf7b0d76a5c0001668ddc410ab903",
		"notification":{
			"title":"Hello World-1",
			"content":"Hello World message-1"
		}
	},
	{
		"target_type":2,
		"target_value":"CN_b457331fd7874d0200c595ebb8d39de8",
		"notification":{
			"title":"Hello World-2",
            "content":"Hello World message-2"
        }
]

响应参数(JSON)

名称类型必须描述
codeInt返回码,请参考公共返回码与接口返回码
messageString请求响应信息
dataString返回值,JSON类型

推送请求调用成功响应示例:

{
     code: 0,
     message: "",
     data: [
         {
               messageId: xxxxxxxxx, // 消息Id
               registrationId: xxxxxxxxx
        }, {
               messageId: xxxxxxxxx, // 消息Id
               registrationId: xxxxxxxxx
       }, {
               messageId: xxxxxxxxx, // 消息Id
               registrationId: xxxxxxxxx, // 消息Id
               errorCode: 10000, // 失败码
               errorMessage: xxxx // 失败说明
       }
    ]
}

返回码(code)

Code英文描述中文描述
10000Invalid Registration_idregistration_id格式不正确

编辑:yimen,如若转载,请注明出处:https://www.yimenapp.com/kb-yimen/11093/

部分内容来自网络投稿,如有侵权联系立删

(0)
上一篇 2022年11月18日 下午2:57
下一篇 2022年11月18日 下午2:59

相关推荐