MobPush REST API的推送 API之创建推送

 

向某单个设备或者某设备列表推送一条通知、消息。
推送的内容只能是 JSON 表示的一个推送对象。

调用验证

详情参见 REST API 概述的 鉴权方式 说明。

频率控制

详情参见推送限制策略的 接口限制 说明。

调用地址

推送对象

  • 以 JSON 格式表达,表示一条推送相关的所有信息
参数类型必须说明
worknostring自定义任务id,默认由MobTech自动生成,无需传递(需保证唯一性)
sourcestring固定值webapi
appkeystringMobTech提供的AppKey
pushTargetobject推送目标
pushTarget.targetnumber推送目标类型
- 1:广播
- 2:别名(alias)
- 3:标签(tags)
- 4:rid
- 5:地理位置(city)
- 6:用户分群
- 9:复杂地理位置推送(pushAreas)
- 14:fileid推送
pushTarget.aliasstring []target等于2时必填推送别名集合,集合元素限制1000个以内。
例:["alias1","alias2"]
pushTarget.tagsstring []target等于3时必填推送标签集合,集合元素限制1000个以内。
例:["tag1","tag2"]
pushTarget.tagsTypenumber标签组合方式,target等于3时可用
- 1:并集
- 2:交集
- 3:补集(暂未实现)
不填默认值为
- 1:并集
pushTarget.ridsstring[]target等于4时必填推送rid集合,集合元素限制1000个以内。
例:["id1","id2"]
pushTarget.citystringtarget等于5时可选,且city、province、country 必选一个不为空推送地理位置的城市
例:上海市
pushTarget.provincestringtarget等于5时可选,且city、province、country 必选一个不为空推送地理位置的省份
例:浙江省
pushTarget.countrystringtarget等于5时可选,且city、province、country 必选一个不为空推送地理位置的国家
例:中国
pushTarget.blockstringtarget等于6时必填用户分群ID
注:该功能暂未实现
pushTarget.pushAreasobjecttarget等于9时必填复杂地理位置
pushTarget.pushAreas.countriesobject []国家列表
pushTarget.pushAreas.countries.countrystring国家名称
pushTarget.pushAreas.countries.provincesobject []指定需要推送的省份列表
pushTarget.pushAreas.countries.provinces.provincestring省份名称
pushTarget.pushAreas.countries.provinces.citiesstring []需要推送的城市列表
pushTarget.pushAreas.countries.provinces.excludeCitiesstring []指定不需要推送的城市列表,当指定[cities]时,这个字段不起作用
pushTarget.pushAreas.countries.provinces.excludeProvincesstring []指定不需要推送的省份列表,当设置[provinces]时,这个不起作用
pushTarget.fileIdstringtarget等于14时必填fileid
pushTarget.appPackagesstring []指定推送的包名列表,如不填则使用默认包名进行推送
pushNotifyobject推送展示细节配置
pushNotify.platsnumber []推送生效渠道
- 1:android
- 2:iOS
- 8:harmony
例:[1, 2, 8]
pushNotify.iosProductionnumberplats数组值含有2时可选iOS环境
- 0:测试环境
- 1:生产环境(默认)
pushNotify.offlineSecondsnumber离线消息保存时间,单位:秒,默认值为86400,离线时间设置必须大于等于5分钟。
注:魅族厂商的离线保留时间范围是1~72小时,设置的离线保留时间如超出该范围将会导致消息无法使用魅族厂商通道,其他厂商不受影响
pushNotify.contentstring推送内容
注1:内容长度超过厂商限制会被截断。
注2:vivo不支持纯表情。
pushNotify.titlestring通知标题
注1:默认通知标题为应用名称
注2:标题长度超过厂商限制会被截断
注3:vivo不允许纯表情
pushNotify.typenumber推送类型
- 1:通知
- 2:自定义
pushNotify.customParamSwitchboolean是否开启个性化参数,默认为false
注:开启后,pushNotify.content参数支持${{}}个性化通知占位符
pushNotify.customParamDefaultContentstring个性化参数默认内容,${{}}个性化通知占位符无法替换时会使用。
注:开启个性化参数时必填
pushNotify.androidNotifyobjectAndroid通知消息对象
pushNotify.androidNotify.contentstring []推送内容,配合style参数使用,默认: 0
- style=0 不生效
- style=1 部分机型可以生效覆盖
- style=2 传入图片链接,部分低版本手机不支持
- style=3 对应传入文字内容
pushNotify.androidNotify.customStyleobject自定义样式
pushNotify.androidNotify.customStyle.styleNointeger样式序号
- 1:样式1
- 2:样式2
- 3:样式3
pushNotify.androidNotify.customStyle.backgroundUrlstring背景图Url
pushNotify.androidNotify.customStyle.smallIconsstring小图标
pushNotify.androidNotify.customStyle.buttonCopystring按钮文案
pushNotify.androidNotify.customStyle.buttonJumpUrlstring点击按钮跳转的链接
pushNotify.androidNotify.warnstring提醒类型,可多选组合
- 1:提示音
- 2:震动
- 3:指示灯
例:12(提示音+震动)
pushNotify.androidNotify.styleinteger显示样式标识
- 0:默认
- 1:长内容
- 2:大图
- 3:横幅
- 4:自定义样式
pushNotify.androidNotify.soundstring自定义声音
pushNotify.androidNotify.iconstring附带小图标的推送
注1:icon和image只能二选一,同时传输则取icon中的数据
注2:目前客户端版本暂不支持
pushNotify.androidNotify.imagestring推送大图标的url地址
注1:icon和image只能二选一,同时传输则取icon中的数据
注2:透传消息不支持
注3:小米厂商对图片尺寸有严格要求,不符合要求则不会按照大图样式进行推送,具体要求为:宽高固定为876*324px,格式需为PNG/JPG/JPEG,大小小于1M
注4:OPPO厂商大图需要申请权限,否则会报错导致客户端收不到推送消息
pushNotify.androidNotify.androidChannelIdstring安卓通知渠道ID
注:当输入该参数后,MobPush通道和厂商通道都会使用该channelId;当androidChannelId 和 pushFactoryExtra中的channelId同时使用填写时,那MobPush通道使用androidChannelId,厂商通道使用pushFactoryExtra中设置的channelId
pushNotify.androidNotify.androidBadgeTypenumber角标类型
- 1:角标数值取androidBadge值
- 2:角标数值为androidBadge当前值加1
注:透传消息不支持
pushNotify.androidNotify.androidBadgenumber角标数值
pushNotify.androidNotify.notifyRepeatobject消息重弹配置项
pushNotify.androidNotify.notifyRepeat.repeatSwitchinteger重弹开关可取值:
- 0:关闭
- 1:开启
pushNotify.androidNotify.notifyRepeat.repeatTimesinteger重弹次数,可取值:1 - 5
pushNotify.androidNotify.notifyRepeat.repeatIntervalinteger重弹时间间隔,单位:秒,可取值:5~86400
pushNotify.androidNotify.nativeCategorystringTCP消息类别,当前仅华为机型支持可选枚举值:
promo 营销推广
recommendation 内容推荐
social 社交动态
call 通话
email 邮件
msg 即时聊天
navigation 导航
reminder 事项提醒
service 财务
alarm 闹钟/计时器
stopwatch 秒表
progress 进度
location_sharing 位置共享
注:参数为空时,默认赋值为:promo
pushNotify.harmonyNotifyobjectharmony通知消息对象
pushNotify.harmonyNotify.titlestring如果不设置,则默认的通知标题为应用的名称
pushNotify.harmonyNotify.stylenumber类型
- 1: 默认通知
- 5: 多行文本样式
pushNotify.harmonyNotify.contentstring []content: style样式具体内容
pushNotify.harmonyNotify.imagestring推送大图标的url地址
pushNotify.harmonyNotify.groupstring组通知名称
pushNotify.harmonyNotify.labelstring通知标签
pushNotify.harmonyNotify.additionalTextstring通知附加内容,是对通知内容的补充
pushNotify.harmonyNotify.briefTextstring通知概要内容,是对通知内容的总结
pushNotify.harmonyNotify.expandedTitlestring通知展开时的标题
pushNotify.harmonyNotify.slotTypeinteger渠道类型
- 0:未知类型
- 1:社交类型
- 2:服务类型
- 3:内容类型
- 4:实况类型
- 5:客户服务类型
- 65535:其他类型
pushNotify.harmonyNotify.badgeinteger角标
pushNotify.iosNotifyobjectiOS通知消息对象
pushNotify.iosNotify.badgenumber角标
pushNotify.iosNotify.badgeTypenumberbadge类型
- 1:绝对值 不能为负数
- 2增减(正数增加,负数减少),减到0以下会设置为0
pushNotify.iosNotify.categorystringAPNs的category字段,只有IOS8及以上系统才支持此参数推送
pushNotify.iosNotify.soundstringAPNs通知,通过这个字段指定声音,默认为default(系统默认声音),如设置为空值则为静音。如设置为其他字符,则需要您的应用中配置了该声音才可以正常发声。
pushNotify.iosNotify.subtitlestring副标题
pushNotify.iosNotify.slientPushnumber如果只携带content-available: 1,不携带任何badge,sound 和消息内容等参数, 则可以不打扰用户的情况下进行内容更新等操作即为“Silent Remote Notifications”
pushNotify.iosNotify.contentAvailablenumber将该键设为 1 则表示有新的可用内容。带上这个键值,意味着你的 App 在后台启动了或恢复运行了,application:didReceiveRemoteNotification:fetchCompletionHandler:被调用了
pushNotify.iosNotify.mutableContentnumber- 1 使用富文本
- 0 不设置
注:默认为0,配合attachmentType 和attachment使用
pushNotify.iosNotify.attachmentTypenumber富文本类型
- 0:无
- 1:图片
- 2:视频
- 3:音频
pushNotify.iosNotify.attachmentstringios富文本内容
pushNotify.taskCronnumber是否是定时消息
- 0:否(默认)
- 1:是
pushNotify.taskTimenumbertaskCron=1时必填定时消息发送时间,单位:毫秒时间戳
例:1594277916000
pushNotify.speednumber每秒推送速率的趋势,默认为0(代表不开启)
pushNotify.skipOnlinenumber是否跳过在线设备
- 1:跳过
- 0:不跳过(默认)
pushNotify.skipFactorynumber是否跳过厂商通道
- 1:跳过
- 0:不跳过(默认)
pushNotify.policynumber推送策略
- 1:先走tcp,再走厂商
- 2:先走厂商,再走tcp
- 3:只走厂商
- 4:只走tcp
- 5:设备亮屏推送 注:厂商透传只支持策略3或4
pushNotify.extrasMapListobject []附加参数列表
例:{"key1":"value1","key2":"value2",…}
pushOperatorobject运营保障相关配置
pushOperator.dropTypenumber运营保障消息修改类型,推荐使用专用接口进行操作
- 1:取消
- 2:替换
- 3:撤回
pushOperator.dropIdstring推送任务的唯一ID
pushForwardobjectlink 相关打开配置
pushForward.urlstringlink跳转 moblink功能的的uri
pushForward.schemestringscheme moblink功能的的scheme
pushForward.schemeDataListobject []scheme参数
例:{"key1":"value1","key2":"value2",…}
pushForward.nextTypeinteger后续动作
- 0:打开首页
- 1:link跳转
- 2:scheme 跳转
- 3:Intent
pushForward.intentUrlstringIntent页面地址
harmonyForwardobject备注: 鸿蒙跳转相关
harmonyForward.nextTypeinteger后续操作类型
- 0:  打开首页
- 4:  打开应用自定义页面
harmonyForward.uristring打开应用自定义页面的uri
harmonyForward.actionstringnextType=4,uri与action至少填1个
harmonyForward.abilityNamestring页面名称
harmonyForward.entitiesstring[]标识能够接收的Entity值的集合。
harmonyForward.bundleNamestring包名
pushCallbackobject推送回调配置
pushCallback.urlstring回调地址点击查看详情
pushCallback.paramsobjectJSON对象自定义参数
例: { "key": "value" }
reportCallbackobject厂商回调配置
reportCallback.urlstring回调地址点击查看详情
pushFactoryExtraobject厂商特殊配置
pushFactoryExtra.huaweiExtraobject华为厂商特殊配置
pushFactoryExtra.huaweiExtra.importancestring消息类型
- LOW:资讯营销类
- NORMAL:服务与通讯类
注:资讯营销类的消息提醒方式为静默通知,仅在下拉通知栏展示。 服务与通讯类的消息提醒方式为锁屏+铃声+震动
pushFactoryExtra.huaweiExtra.categorystring作用一:完成自分类权益申请后,用于标识消息类型,确定消息提醒方式,对特定类型消息加快发送,取值如下:
IM:即时聊天
VOIP:音视频通话
SUBSCRIPTION:订阅
TRAVEL:出行
HEALTH:健康
WORK:工作事项提醒
ACCOUNT:帐号动态
EXPRESS:订单&物流
FINANCE:财务
DEVICEREMINDER:设备提醒
SYSTEM
REMINDER:系统提示
MAIL:邮件
PLAYVOICE:语音播报(仅透传消息支持)
MARKETING:内容推荐、新闻、财经动态、生活资讯、社交动态、调研、产品促销、功能推荐、运营活动(仅对内容进行标识,不会加快消息发送)
作用二:申请特殊权限后,用于标识高优先级透传场景,取值如下:
VOIP:音视频通话
PLAY
VOICE:语音播报
pushFactoryExtra.xiaomiExtraobject小米厂商特殊配置
pushFactoryExtra.xiaomiExtra.channelIdstring小米渠道Id 适配定制化渠道
pushFactoryExtra.oppoExtraobjectOPPO厂商特殊配置
pushFactoryExtra.oppoExtra.channelIdstringOPPO渠道Id 适配定制化渠道
pushFactoryExtra.vivoExtraobjectVIVO厂商特殊配置
pushFactoryExtra.vivoExtra.classificationintVIVO消息类型
- 0:运营类型消息
- 1:系统类型消息
pushFactoryExtra.vivoExtra.categorystring二级分类,传值参见二级分类标准中category说明
1、填写category后,可以不填写classification、messageSort,但若填写classification、messageSort,请保证category与messageSort或classification是正确对应关系,否则返回错误码10097;
2、赋值请按照消息分类规则填写,且必须大写;若传入错误无效的值,否则返回错误码10096;
pushFactoryExtra.honorExtraobject荣耀厂商特殊配置
pushFactoryExtra.honorExtra.importancestring消息类型
- LOW:资讯营销类
- NORMAL:服务与通讯类
注:资讯营销类的消息默认展示方式为静默通知,仅在下拉通知栏展示。 服务与通讯类的消息默认展示方式为锁屏展示+下拉通知栏展示
userExtraobject用于解释推送任务的字段扩充
userExtra.pushWorkDescstring推送任务的解释说明,由用户设置
userExtra.activityTaskinteger活动任务
- 0:不是活动任务(默认)
- 1:是活动任务
userExtra.activityWorkIdstringactivityTask为1时必传活动ID,不能超过20个字符,且唯一不可重复
groupIdstringAB分组测试ID

请求示例

curl --location --request POST 'http://api.push.mob.com/v3/push/createPush' \
--header 'Content-Type: application/json' \
--header 'key: 2f2d7a68f8a40' \
--header 'sign: eb276f35cf6480169b2d3e2e509db680' \
--data-raw '{"source":"webapi","appkey":"2f2d7a68f8a40","pushTarget":{"target":1},"pushNotify":{"plats":[1],"content":"推送的内容","type":1}}'

响应示例

  • 请求成功
{
    "status": 200,
    "res": {
        "batchId": "4bp4tw9ttc06xgch6o",
        "fetched": null,
        "uninstalls": null,
        "closes": null,
        "notFounds": null
    },
    "error": null
}
  • 请求失败
{
    "status": 5801,
    "res": null,
    "error": "数据校验失败"
}
  • 响应参数
参数类型说明
statusint返回码
resobject消息体
res.batchIdstring本次推送的任务ID
errorstring返回码描述

调用示例

推送广播

{
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 1
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送的内容",
        "type": 1
    }
}

推送广播并附加参数

{
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 1
    },
    "pushNotify": {
        "plats": [
            1,
            2
        ],
        "content": "推送的内容",
        "type": 1,
        "iosProduction": 0,
        "extrasMapList": [
            {
                "key": "ContentTypeasd",
                "value": "personal_chat"
            }
        ]
    }
}

推送标签

{
    "source": "webapi",
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 3,
        "tags": [
            "男",
            "上海",
            "老师"
        ]
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送的内容",
        "type": 1
    }
}

推送别名

{
    "source": "webapi",
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 2,
        "alias": [
            "alias_1",
            "alias_2"
        ]
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送的内容",
        "type": 1
    }
}

推送RegisterID

{
    "source": "webapi",
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 4,
        "rids": [
            "c262bac10d05ec1c9b04126d"
        ]
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送的内容",
        "type": 1
    }
}

自定义消息(透传消息)

{
    "source": "webapi",
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 1
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送内容",
        "type": 2,
    }
}

Android通知大图模式

{
    "source": "webapi",
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 1
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送内容",
        "type": 1,
        "androidNotify": {
            "content": [
                "Android推送内容1",
                "Android推送内容2"
            ],
            "style": 2
        }
    }
}

Android通知横幅模式

{
    "source": "webapi",
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 1
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送内容",
        "type": 1,
        "androidNotify": {
            "content": [
                "Android推送内容1",
                "Android推送内容2"
            ],
            "style": 3
        }
    }
}

Android通知自定义声音

音频文件放到项目res/raw目录下,只需传音频文件的文件名

{
    "source": "webapi",
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 1
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送内容",
        "type": 1,
        "androidNotify": {
            "content": [
                "Android推送内容1",
                "Android推送内容2"
            ],
            "style": 2,
            "warn": "1",
            "sound": "warn",
            "androidChannelId": "channelId"
        }
    }
}

跳转首页并传递附加参数

{
    "source": "webapi",
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 1
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送内容",
        "type": 1,
        "androidNotify": {
            "content": [
                "Android推送内容1",
                "Android推送内容2"
            ],
            "style": 2,
            "warn": "1",
            "sound": "warn"
        },
        "extrasMapList": [
            {
                "key": "extrakey",
                "value": "extravalue"
            }
        ]
    },
    "pushForward": {
        "nextType": 0
    }
}

跳转到指定界面并且传递携带scheme数据

{
    "source": "webapi",
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 1
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送内容",
        "type": 1,
        "androidNotify": {
            "content": [
                "Android推送内容1",
                "Android推送内容2"
            ],
            "style": 2,
            "warn": "1",
            "sound": "warn"
        }
    },
    "pushForward": {
        "nextType": 2,
        "scheme": "mlink://com.mob.mobpush.linkone",
        "schemeDataList": [
            {
                "key": "schemekey",
                "value": "schemevalue"
            }
        ]
    }
}

打开网页

{
    "source": "webapi",
    "appkey": "moba6b6c6d6",
    "pushTarget": {
        "target": 1
    },
    "pushNotify": {
        "plats": [
            1
        ],
        "content": "推送内容",
        "type": 1,
        "androidNotify": {
            "content": [
                "Android推送内容1",
                "Android推送内容2"
            ],
            "style": 2,
            "warn": "1",
            "sound": "warn"
        }
    },
    "pushForward": {
        "nextType": 1,
        "url": "http://www.mob.com"
    }
}

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MobTech袤博科技

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值