跳到主要内容

notifications.subscribe

监听通知

  • 请求路由: notifications.subscribe
  • 交互模型: Request Stream
  • 访问限制: 无

发起通知监听请求,返回一个不会终止的消息流,当有新的通知时,会下发通知对象到消息流中。 客户端可以在onNext中接收并处理下发的通知对象。

调用示例:

RSocket.rs({
route: 'notifications.subscribe',
args: {
filter: {
businessKey: 'order:*', // 仅接收订单通知。可以使用通配符匹配
params: { // 可针对通知扩展参数进行过滤
notiTarget: 'driver',
templateName: '^.+订单.+$', // 使用正则表达式过滤
driverDisplay: true,
}
}
},
onNext: (notification) => {
// 收到通知时会触发onNext回调
console.log('收到通知: ', notification)
},
})

请求​

RSocket.rs({
"route" : "notifications.subscribe",
"args" : {
"filter" : {
"businessKey" : "order:*",
"params" : {
"notiTarget" : "driver",
"templateName" : "收到新订单提醒",
"driverDisplay" : true
}
}
}
});

请求参数​

名称类型必须说明
filterObject否过滤参数,匹配的字符串值可以以通配符*开始或结束,以匹配前缀或后缀
如果字符串值以^开头,且以$结尾,则字符串值被当做正则表达式用于过滤
filter.recipientString否接收者帐号
filter.subjectString否通知主题
filter.contentString否通知内容
filter.businessKeyString否关联的业务标识,例如订单通知相关的订单号等
filter.typeString否normal - 会持久化的普通通知
headline - 不会持久化的实时通知,仅在线用户可以收到这类通知
filter.paramsObject否通知参数,用于携带通知相关的一些上下文,不同sendType所需的基本params不同:
 email:
subject - 通知主题,可选,未指定时使用Notification.subject
content - 通知内容,可选,未指定时使用Notification.content
sms:
type - 短信类别,必须
wx:
appId - 用于发送微信通知的公众号或小程序appId,必须;
openId - 用于发送微信通知的用户标识,必须;
push:
bundleId - 用于发送App推送通知的App标识,必须;
除以上基本参数外,可以添加其他业务相关参数,以便客户端收到通知后执行特定业务逻辑

返回​

一个不会终止的流,流的元素是通知对象

[
{
"tenantId" : "mzd",
"id" : "6483c02eedb4f1131ba68047",
"scope" : "cbv",
"sender" : "admin",
"recipient" : "18900010001@mzd",
"subject" : "专线订单下单成功",
"content" : "",
"businessKey" : "order:SCO20230610081326748",
"type" : "normal",
"params" : {
"templateName" : "购票成功通知",
"appId" : "wx810cb7d88888888e",
"driverDisplay" : false
},
"status" : 0,
"sendTypes" : [
"app",
"sms",
"wx"
]
}
]

返回属性​

名称类型说明
idString通知标识
scopeString相关应用Scope
senderString发送者帐号
recipientString接收者帐号
subjectString通知主题
contentString通知内容
businessKeyString关联的业务标识,例如订单通知相关的订单号等
typeStringnormal - 会持久化的普通通知
headline - 不会持久化的实时通知,仅在线用户可以收到这类通知
paramsObject通知参数,用于携带通知相关的一些上下文,不同sendType所需的基本params不同:
 email:
subject - 通知主题,可选,未指定时使用Notification.subject
content - 通知内容,可选,未指定时使用Notification.content
sms:
type - 短信类别,必须
wx:
appId - 用于发送微信通知的公众号或小程序appId,必须;
openId - 用于发送微信通知的用户标识,必须;
push:
bundleId - 用于发送App推送通知的App标识,必须;
除以上基本参数外,可以添加其他业务相关参数,以便客户端收到通知后执行特定业务逻辑
statusNumber通知状态
0 - 未读; 1 - 已读
sendTypesString[]通知发送类别。
可同时指定多个发送类别
  • app - 应用内部通知
  • email - 邮件通知
  • sms - 短信通知
  • wx - 微信通知
  • push - 设备App推送通知
  • crDateString创建时间
    tenantIdString租户ID

    下载结果模型定义