魅族推送平台接入文档 (JAVA-SDK) 2017.02
文档变更记录 日期作者版本变更描述下载链接 2016-12-18 王新国 1.0.0.20161218_release 1.0.0 标准版 Download 2017-02-16 王新国 1.1.0.20170216_release 1.1.0 标准版 Download 2
目录 魅族推送平台接入文档 (JAVA-SDK)... 1 1. 类型定义... 5 1.1 推送服务 (IFlymePush)... 5 1.2 通知栏消息体 (Message)... 5 1.2.1 通知栏消息 (VarnishedMessage)... 5 1.2.2 透传消息 (UnVarnishedMessage)... 9 1.3 接口返回值 (ResultPack)... 10 1.4 消息推送结果 (PushResult)... 11 1.5 接口响应码定义 (ErrorCode)... 11 1.6 推送响应码定义 (PushResponseCode)... 12 1.7 推送类型 (PushType)... 13 1.8 推送标签集合类型 (ScopeType)... 13 1.9 任务推送统计 (TaskStatistics)... 14 2. 接口说明... 14 2.1 非任务推送... 14 2.1.1 描述... 14 2.1.2 应用场景... 14 2.1.2.1 pushid 通知栏消息推送 (pushmessage)... 15 2.1.2.2 pushid 透传消息推送 (pushmessage)... 17 2.1.2.3 别名通知栏消息推送 (pushmessagebyalias)... 19 2.1.2.4 别名透传消息推送 (pushmessagebyalias)... 21 3
2.2 任务推送... 23 2.2.1 描述... 23 2.2.2 应用场景... 23 2.2.3 获取推送 taskid(gettaskid)... 24 2.2.4 pushid 消息推送 (pushmessagebytaskid)... 25 2.2.5 别名消息推送 (pushaliasmessagebytaskid)... 28 2.2.6 应用全部推送 (pushtoapp)... 31 2.2.7 应用标签推送 (pushtotag)... 33 2.2.8 取消推送任务 (canceltaskpush)... 34 2.3 推送统计... 35 获取任务推送统计 (gettaskstatistics)... 35 4
1. 类型定义 1.1 推送服务 (IFlymePush) 调用该类实例的方法来推送消息, 构造函数说明如下 : 参数名称类型必填默认描述 appsecret String 是 null 注册应用 appsecret usessl Boolean 否 false 是否使用 https 接口调用 :true 使 用 https 连接,false 使用 http 连接 1.2 通知栏消息体 (Message) 推送消息实体 ( 抽象类 ): 子类 说明 VarnishedMessage 通知栏消息体 UnVarnishedMessage 透传消息体 1.2.1 通知栏消息 (VarnishedMessage) 参数名称类型必填默认描述 appid Long 是 null 注册应用 appid title String 是 null 推送标题, ( 字数限制 1~32) content String 是 null 推送内容, ( 字数限制 1~100) 5
参数名称类型必填默认描述 通知栏样式 (0, " 标准 "),(2, " noticebartype int 否 0 安卓原生 ")( 非必填, 默认 值为 0) 展开方式 (0, " 标准 "),(1, " noticeexpandtype int 否 0 文本 ")( 非必填, 默认值为 0) noticeexpandcont ent String 否 null 展开内容, (noticeexpandtype 为文 本时, 必填 ) 点击动作 (0," 打开应用 "),(1," 打开应用页面 "),(2," 打 clicktype int 否 0 开 URI 页面 "),(3, " 应用客户 端自定义 ")( 非必填, 默认 值为 0) URI 页面地址, (clicktype url String 否 null 为打开 URI 页面时, 必填, 长度限制 1000byte) parameters JSONOb ject 否 null 透传参数 (JSON 格式, 非必填 ) 6
参数名称类型必填默认描述 应用页面地址, (clicktype activity String 否 null 为打开应用页面时, 必填, 长度限制 1000byte) 应用客户端自定义内容, customattribute String 否 null (clicktype 为应用客户端 自定义时, 必填, 长度限制 1000byte) 是否进离线消息, (false 否 isoffline Boolean 否 true true 是 ) ( 非必填, 默认 值为 true) 有效时长 (1~72 小时内的 validtime int 否 24 正整数 ), (isoffline 值为 true 时, 必填, 值的范围 1~72) 定时推送 (0, " 即时 "),(1, " pushtimetype int 否 0 定时 "), ( 只对全部用户推 送生效 ) starttime Date 否 null 任务定时开始时间,( 非必 填,pushTimeType 为 7
参数名称类型必填默认描述 True 必填 ) 只对全部用户 推送生效 isfixspeed Boolean 否 false 是否定速推送, ( 非必填, 默认值为 False) fixspeedrate Long 否 0 定速速率,(isFixSpeed 为 true 时, 必填 ) 是否通知栏悬浮窗显示 issuspend Boolean 否 true (true 显示,false 不显示 ) ( 非必填, 默认 True) 是否可清除通知栏 (true 可 isclearnoticebar Boolean 否 true 以,false 不可以 ),( 非 必填, 默认 true) isfixdisplay Boolean 否 false 是否定时展示 ( 非必填, 默 认 false) fixdisplaytime (Date,D ate) 否 (null,null ) 定时展示开始, 结束时间 (fixdisplay 为 true 时, 必填, 并且开始时间要晚于结束时间 ) 8
参数名称类型必填默认描述 震动 (false 关闭 true 开 vibrate Boolean 否 true 启 ), ( 非必填, 默认 true) 闪光 (false 关闭 true 开 lights Boolean 否 true 启 ), ( 非必填, 默认 true) 声音 (false 关闭 true 开 sound Boolean 否 true 启 ), ( 非必填, 默认 true) 1.2.2 透传消息 (UnVarnishedMessage) 参数名称类型必填默认描述 appid Long 是 null 注册应用 appid title String 否 null 推送标题, 任务推送建议填写, 方便 数据查询,( 字数限制 1~32) content String 是 null 推送内容,( 必填, 字数限制 3800byte 以内 ) isoffline Boolean 否 true 是否进离线消息,( 非必填, 默认为 true) 9
参数名称类型必填默认描述 有效时长 (1~72 小时内的正整数 ), validtime int 否 24 (isoffline 值为 true 时, 必填, 值的范围 1--72) pushtimet ype int 否 0 定时推送 (0, " 即时 "),(1, " 定时 "), ( 只对全部用户推送生效 ) 任务定时开始时间, starttime Date 否 null (pushtimetype 为 1 必填 ) 只对 全部用户推送生效 isfixspeed Boolean 否 false 是否定速推送,( 非必填, 默认值为 false) fixspeedra te Long 否 0 定速速率 (isfixspeed 为 true 时, 必填 ) 1.3 接口返回值 (ResultPack) 方法名称类型描述 code() String 接口响应码 Comment() String 接口响应描述 value() T 接口响应内容 10
方法名称类型描述 errorcode() Enum 接口响应异常枚举详见 ErrorCode 1.4 消息推送结果 (PushResult) 方法名称类型描述 getmsgid() String 推送消息 ID, 用于推送流程明细排查 getresptarget() Map 推送目标结果状态 (KEY: 推送响应码 VALUE: 响应码对应的目标用户 ) 1.5 接口响应码定义 (ErrorCode) 名称 Code Commen UNKNOWN_ERROR -1 未知错误 SUCCESS 200 成功 SYSTEM_ERROR 1001 系统错误 SYSTEM_BUSY 1003 服务器忙 PARAMETER_ERROR 1005 参数错误, 请参考 API 文档 INVALID_SIGN 1006 签名认证失败 INVALID_APPLICATION_ID 110000 appid 不合法 11
名称 Code Commen INVALID_APPLICATION_KEY 110001 appkey 不合法 UNSUBSCRIBE_PUSHID 110002 pushid 未注册 INVALID_PUSHID 110003 pushid 非法 PARAM_BLANK 110004 参数不能为空 APP_IN_BLACK_LIST 110009 应用被加入黑名单 APP_REQUEST_EXCEED_LIMIT 110010 应用请求频率过快 APP_PUSH_TIME_EXCEED_LIMIT 110051 超过该应用的次数限制 APP_REQUEST_PUSH_LIMIT 110019 超过该应用每天推送次 数限制 INVALID_APPLICATION_PACKAGE NAME 110031 packagename 不合法 INVALID_TASK_ID 110032 非法的 taskid INVALID_APPLICATION_SECRET 110033 非法的 appsecret 1.6 推送响应码定义 (PushResponseCode) 名称 Code Commen RSP_NO_AUT 201 没有权限, 服务器主动拒绝 12
名称 Code Commen RSP_DB_ERROR 501 推送消息失败 (db_error) RSP_INTERNAL_ERROR 513 推送消息失败 RSP_SPEED_LIMIT 518 推送超过配置的速率 RSP_OVERFLOW 519 推送消息失败服务过载 RSP_REPEATED 520 消息折叠 (1 分钟内同一设备同一应用消 息收到多次, 默认 5 次 ) RSP_UNSUBSCRIBE_PU SHID 110002 pushid 未订阅 ( 包括推送开关关闭的设 备 ) RSP_INVALID_PUSHID 110003 pushid 非法 RSP_UNSUBSCRIBE_ALI AS 110005 别名未订阅 ( 包括推送开关关闭的设备 ) 1.7 推送类型 (PushType) 枚举类型描述 STATUSBAR Enum 通知栏消息类型 DIRECT Enum 透传消息类型 1.8 推送标签集合类型 (ScopeType) 13
枚举类型描述 UNION Enum 并集 INTERSECTION Enum 交集 1.9 任务推送统计 (TaskStatistics) 名称类型描述 targetno Long 目标数 validno Long 有效数 pushedno Long 推送数 acceptno Long 接受数 displayno Long 展示数 2. 接口说明 2.1 非任务推送 2.1.1 描述 向指定的 pushid 推送消息 : clickno Long 点击数 注 : 推送平台使用 pushid 来标识每个独立的用户, 每一台终端上每一个 app 拥有一个独立的 pushid 2.1.2 应用场景 场景 1: 查找手机业务需要远程定位位置, 可发送消息指令到对应的设备 14
场景 2: 社区用户回帖消息提醒, 用户对发表的帖子有最新回复时, 消息提醒发帖者 2.1.2.1 pushid 通知栏消息推送 (pushmessage) 接口说明 : 接口 说明 ResultPack< PushResult> pushmessage(varnishedmessage message, List<String> pushids) ResultPack< PushResult > pushmessage(varnishedmessage message, List<String> pushids, int retries) 推送通知栏消息 推送通知栏消息 参数说明 : 参数名称类型必需默认描述 message VarnishedMessage 是 null 推送消息 pushids List 是 null 推送目标, 一批最多不 能超过 1000 个 retries int 否 0 超时 or 异常重试次数 返回值 : PushResult msgid; 推送消息 ID, 用于推送流程明细排查 resptarget; 推送目标结果状态 (key: 推送响应码 value: 响应码对应的目标用户注 : 只返回不合法 超速以及推送失败的目标用户, 业务一般对超速的 pushid 处理 示例 : /** * 通知栏消息推送 (pushmessage) * @throws Exception */ @Test public void testvarnishedmessagepush() throws Exception { 15
// 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); // 组装消息 VarnishedMessage message = new VarnishedMessage.Builder().appId(appId).title("Java SDK 推送标题 ").content("java SDK 推送内容 ").noticeexpandtype(1).noticeexpandcontent(" 展开文本内容 ").clicktype(2).url("http://www.baidu.com").parameters(json.pa rseobject("{\"k1\":\"value1\",\"k2\":0,\"k3\":\"value3\"")).offline(true).validtime(12).suspend(true).clearnoticebar(true).vibrate(true).lights(tru e).sound(true).build(); // 目标用户 List<String> pushids = new ArrayList<String>(); pushids.add("pushid_1"); pushids.add("pushid_2"); // 1 调用推送服务 ResultPack< PushResult> result = push.pushmessage(message, pushids); if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 类型做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 Map<Integer, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push msgid:" + msgid); System.out.println("push targetresultmap:" + targetresultmap); if (targetresultmap!= null &&!targetresultmap.isempty()) { // 3 判断是否有获取超速的 target if (targetresultmap.containskey(pushresponsecode.rsp_speed_limit.getvalue())) { // 4 获取超速的 target List<String> ratelimittarget = targetresultmap.get(pushresponsecode.rsp_speed_limit.getvalue()); System.out.println("rateLimitTarget is :" + ratelimittarget); //TODO 5 业务处理, 重推... 16
else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常描述 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); 2.1.2.2 pushid 透传消息推送 (pushmessage) 接口说明 : 接口 说明 ResultPack<PushResult> pushmessage(unvarnishedmessage message, List<String> pushids) ResultPack<PushResult> pushmessage(unvarnishedmessage message, List<String> pushids, int retries) 推送透传消息 推送透传消息 参数说明 : 参数名称类型必需默认描述 message UnVarnishedMessage 是 null 推送消息 pushids List 是 null 推送目标, 一批最多不能 超过 1000 个 retries int 否 0 超时 or 异常重试次数 返回值 : PushResult msgid; 推送消息 ID, 用于推送流程明细排查 resptarget; 推送目标结果状态 (key: 推送响应码 value: 响应码对应的目标用户注 : 只返回不合法 超速以及推送失败的目标用户, 业务一般对超速的 pushid 处理 示例 : /** 17
* 透传消息推送 (pushmessage) * @throws Exception */ @Test public void testunvarnishedmessagepush() throws Exception { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); // 组装透传消息 UnVarnishedMessage message = new UnVarnishedMessage.Builder().appId(appId).title("Java SDK 透传推送标题 ").content("java Sdk 透传推送内容 ").isoffline(true).validtime(10).build(); // 目标用户 List<String> pushids = new ArrayList<String>(); pushids.add("pushid_1"); pushids.add("pushid_2"); // 1 调用推送服务 ResultPack<PushResult> result = push.pushmessage(message, pushids); if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 类型做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 Map<Integer, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push msgid:" + msgid); System.out.println("push targetresultmap:" + targetresultmap); if (targetresultmap!= null &&!targetresultmap.isempty()) { // 3 判断是否有获取超速的 target if (targetresultmap.containskey(pushresponsecode.rsp_speed_limit.getvalue())) { // 4 获取超速的 target List<String> ratelimittarget = targetresultmap.get(pushresponsecode.rsp_speed_limit.getvalue()); System.out.println("rateLimitTarget is :" + ratelimittarget); //TODO 5 业务处理, 重推... 18
else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常描述 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); 2.1.2.3 别名通知栏消息推送 (pushmessagebyalias) 接口说明 : 接口 说明 ResultPack<PushResult> pushmessagebyalias(varnishedmessage message, List<String> alias) ResultPack<PushResult> pushmessagebyalias(varnishedmessage message, List<String> alias, int retries) 推送通知栏消息 推送通知栏消息 参数说明 : 参数名称类型必需默认描述 message VarnishedMessage 是 null 推送消息 alias List 是 null 推送目标, 一批最多不 能超过 1000 个 retries int 否 0 超时 or 异常重试次数 返回值 : PushResult msgid; 推送消息 ID, 用于推送流程明细排查 resptarget; 推送目标结果状态 (key: 推送响应码 value: 响应码对应的目标用户注 : 只返回不合法 超速以及推送失败的目标用户, 业务一般对超速的 pushid 处理 示例 : 19
/** * 别名通知栏消息推送 (pushmessage) * * @throws Exception */ @Test public void testvarnishedmessagepushbyalias() throws Exception { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); // 组装消息 VarnishedMessage message = new VarnishedMessage.Builder().appId(appId).title("Java SDK 推送标题 ").content("java SDK 推送内容 ").noticeexpandtype(1).noticeexpandcontent(" 展开文本内容 ").clicktype(2).url("http://push.meizu.com").parameters(json.parse Object("{\"k1\":\"value1\",\"k2\":0,\"k3\":\"value3\"")).offLine(true).validTime(12).isFixDisplay(true).fixDisplayTime(str2Date("2017-10-01 12:00:00"), str2date("2017-10-01 12:30:00")).suspend(true).clearNoticeBar(true).vibrate(true).lights(true).s ound(true).build(); // 目标用户 List<String> alias = new ArrayList<String>(); alias.add("android"); alias.add("alias2"); // 1 调用推送服务 ResultPack<PushResult> result = push.pushmessagebyalias(message, alias); if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 类型做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 Map<Integer, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push msgid:" + msgid); System.out.println("push targetresultmap:" + targetresultmap); if (targetresultmap!= null &&!targetresultmap.isempty()) { // 3 判断是否有获取超速的 target 20
if (targetresultmap.containskey(pushresponsecode.rsp_speed_limit.getvalue())) { // 4 获取超速的 target List<String> ratelimittarget = targetresultmap.get(pushresponsecode.rsp_speed_limit.getvalue()); System.out.println("rateLimitTarget is :" + ratelimittarget); //TODO 5 业务处理, 重推... else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常描述 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); 2.1.2.4 别名透传消息推送 (pushmessagebyalias) 接口说明 : 接口 说明 ResultPack<PushResult> pushmessagebyalias(unvarnishedmessage message, List<String> alias) ResultPack<PushResult> pushmessagebyalias(unvarnishedmessage message, List<String> alias, int retries) 推送透传消息 推送透传消息 参数说明 : 参数名称 类型 必 需 默 认 描述 message UnVarnishedMessage 是 null 推送消息 21
参数名称 类型 必 需 默 认 描述 alias List 是 null 推送目标, 一批最多不能 超过 1000 个 retries int 否 0 超时 or 异常重试次数 返回值 : PushResult msgid; 推送消息 ID, 用于推送流程明细排查 resptarget; 推送目标结果状态 (key: 推送响应码 value: 响应码对应的目标用户注 : 只返回不合法 超速以及推送失败的目标用户, 业务一般对超速的 pushid 处理 示例 : /** * 别名透传推送 * * @throws Exception */ @Test public void testunvarnishedmessagepushbyalias() throws Exception { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); // 组装透传消息 UnVarnishedMessage message = new UnVarnishedMessage.Builder().appId(appId).title("Java SDK 透传推送标题 ").content("java Sdk 透传推送内容 ").build(); // 目标用户 List<String> alias = new ArrayList<String>(); alias.add("alias"); alias.add("alias2"); alias); // 1 调用推送服务 ResultPack<PushResult> result = push.pushmessagebyalias(message, 22
if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 类型做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 Map<Integer, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push msgid:" + msgid); System.out.println("push targetresultmap:" + targetresultmap); if (targetresultmap!= null &&!targetresultmap.isempty()) { // 3 判断是否有获取超速的 target if (targetresultmap.containskey(pushresponsecode.rsp_speed_limit.getvalue())) { // 4 获取超速的 target List<String> ratelimittarget = targetresultmap.get(pushresponsecode.rsp_speed_limit.getvalue()); System.out.println("rateLimitTarget is :" + ratelimittarget); //TODO 5 业务处理, 重推... else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常描述 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); 2.2 任务推送 2.2.1 描述 首先获取推送的 taskid, 然后通过 taskid 向指定的 pushid 推送消息 2.2.2 应用场景 浏览器对指定的某一大批量 pushid 用户推送活动或者新闻消息, 通过先获取 taskid, 然后通过 taskid 批量推送, 推送过程中可以根据 taskid 时时获取推送 统计结果 23
2.2.3 获取推送 taskid(gettaskid) 接口说明 : 接口 说明 ResultPack gettaskid(pushtype pushtype, Message message) 获取推送 taskid 参数说明 : 参数名称类型必需默认描述 pushtype PushType 是 null 消息类型 message Message 是 null 消息体 返回值 : Long 任务 ID 示例 : /** * 获取通知栏推送 taskid(gettaskid) * @throws Exception */ @Test public void testgetvarnishedmessagetaskid() throws Exception { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); // 组装消息 VarnishedMessage message = new VarnishedMessage.Builder().appId(appId).title("java Sdk 推送标题 ").content("java Sdk 推送内容 ").noticeexpandtype(1).noticeexpandcontent(" 展开文本内容 ").clicktype(2).url("http://www.baidu.com").parameters(json.pa rseobject("{\"k1\":\"value1\",\"k2\":0,\"k3\":\"value3\"")).offline(true).validtime(12) 24
.suspend(true).clearnoticebar(true).vibrate(false).lights(fa lse).sound(false).fixspeed(true).fixspeedrate(20).build(); ResultPack<Long> result = push.gettaskid(pushtype.statusbar, message); System.out.println(result); /** * 获取透传推送 taskid(gettaskid) * @throws Exception */ @Test public void testgetunvarnishedmessagetaskid() throws Exception { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); // 组装消息 UnVarnishedMessage message = new UnVarnishedMessage.Builder().appId(appId).title("java sdk 推送标题 ").content("java sdk 推送内容 ").build(); ResultPack<Long> result = push.gettaskid(pushtype.direct, message); System.out.println(result); 2.2.4 pushid 消息推送 (pushmessagebytaskid) 接口说明 接口 说明 ResultPack<PushResult> pushmessagebytaskid(pushtype pushtype, long appid, long taskid, List<String> pushids) 任务消息推 送 ResultPack<PushResult> pushmessagebytaskid(pushtype pushtype, long appid, long taskid, List<String> pushids, int retries) 任务消息推 送 25
参数说明 : 参数名称类型必需默认描述 pushtype PushType 是 null 消息类型 appid Long 是 null 推送应用 ID taskid Long 是 null 推送任务 ID pushids List 是 null 推送目标, 一批最多不能超过 1000 个 retries int 否 0 超时 or 异常重试次数 返回值 : PushResult msgid; 推送消息 ID, 用于推送流程明细排查 resptarget; 推送目标结果状态 (key: 推送响应码 value: 响应码对应的目标用户注 : 只返回不合法 超速以及推送失败的目标用户, 业务一般对超速的 pushid 处理 示例 : /** * 任务消息推送 (pushmessagebytaskid) * @throws IOException */ @Test public void testpushpytaskid() throws IOException { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); // 目标用户 List<String> pushids = new ArrayList<String>(); pushids.add("pushid_1"); pushids.add("pushid_2"); // 通知栏任务消息推送 Long taskid = 123l; // 1 调用推送服务 26
ResultPack<PushResult> result = push.pushmessagebytaskid(pushtype.statusbar, appid, taskid, pushids, 0); if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 类型做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 Map<Integer, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push msgid:" + msgid); System.out.println("push targetresultmap:" + targetresultmap); if (targetresultmap!= null &&!targetresultmap.isempty()) { // 3 判断是否有获取超速的 target if (targetresultmap.containskey(pushresponsecode.rsp_speed_limit.getvalue())) { // 4 获取超速的 target List<String> ratelimittarget = targetresultmap.get(pushresponsecode.rsp_speed_limit.getvalue()); System.out.println("rateLimitTarget is :" + ratelimittarget); //TODO 5 业务处理, 重推... else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常描述 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); // 透传消息任务推送 taskid = 123l; // 1 调用推送服务 result = push.pushmessagebytaskid(pushtype.direct, appid, taskid, pushids, 0); if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 类型做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 27
Map<Integer, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push msgid:" + msgid); System.out.println("push targetresultmap:" + targetresultmap); if (targetresultmap!= null &&!targetresultmap.isempty()) { // 3 判断是否有获取超速的 target if (targetresultmap.containskey(pushresponsecode.rsp_speed_limit.getvalue())) { // 4 获取超速的 target List<String> ratelimittarget = targetresultmap.get(pushresponsecode.rsp_speed_limit.getvalue()); System.out.println("rateLimitTarget is :" + ratelimittarget); //TODO 5 业务处理, 重推... else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常描述 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); 2.2.5 别名消息推送 (pushaliasmessagebytaskid) 接口说明 : 接口 说明 ResultPack<PushResult> pushaliasmessagebytaskid(pushtype pushtype, long appid, long taskid, List<String> alias) ResultPack<PushResult> pushaliasmessagebytaskid(pushtype pushtype, long appid, long taskid, List<String> alias, int retries) 任务消息推送 任务消息推送 参数说明 : 28
参数名称类型必需默认描述 pushtype PushType 是 null 消息类型 appid Long 是 null 推送应用 ID taskid Long 是 null 推送任务 ID alias List 是 null 推送目标别名, 一批最多 不能超过 1000 个 retries int 否 0 超时 or 异常重试次数 返回值 : PushResult msgid; 推送消息 ID, 用于推送流程明细排查 resptarget; 推送目标结果状态 (key: 推送响应码 value: 响应码对应的目标用户注 : 只返回不合法 超速以及推送失败的目标用户, 业务一般对超速的 pushid 处理 示例 : ** * 别名任务消息推送 * * @throws IOException */ @Test public void testpushaliaspytaskid() throws IOException { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); // 目标用户 List<String> alias = new ArrayList<String>(); alias.add("alias123"); alias.add("android654"); // 通知栏任务消息推送 Long taskid = 45361L; // 1 调用推送服务 29
ResultPack<PushResult> result = push.pushaliasmessagebytaskid(pushtype.statusbar, appid, taskid, alias); if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 类型做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 Map<Integer, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push msgid:" + msgid); System.out.println("push targetresultmap:" + targetresultmap); if (targetresultmap!= null &&!targetresultmap.isempty()) { // 3 判断是否有获取超速的 target if (targetresultmap.containskey(pushresponsecode.rsp_speed_limit.getvalue())) { // 4 获取超速的 target List<String> ratelimittarget = targetresultmap.get(pushresponsecode.rsp_speed_limit.getvalue()); System.out.println("rateLimitTarget is :" + ratelimittarget); //TODO 5 业务处理, 重推... else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常描述 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); // 透传消息任务推送 taskid = 45407L; // 1 调用推送服务 result = push.pushaliasmessagebytaskid(pushtype.direct, appid, taskid, alias); if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 类型做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 30
Map<Integer, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push msgid:" + msgid); System.out.println("push targetresultmap:" + targetresultmap); if (targetresultmap!= null &&!targetresultmap.isempty()) { // 3 判断是否有获取超速的 target if (targetresultmap.containskey(pushresponsecode.rsp_speed_limit.getvalue())) { // 4 获取超速的 target List<String> ratelimittarget = targetresultmap.get(pushresponsecode.rsp_speed_limit.getvalue()); System.out.println("rateLimitTarget is :" + ratelimittarget); //TODO 5 业务处理, 重推... else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常描述 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); 2.2.6 应用全部推送 (pushtoapp) 接口说明 : 接口 ResultPack<Long> pushtoapp(pushtype pushtype, Message message) 说明 应用全部推送 参数说明 : 参数名称类型必需默认描述 pushtype PushType 是 null 消息类型 message Message 是 null 消息体 31
返回值 : Long 任务 ID 示例 : /** * 应用全部推送 (pushtoapp) * @throws IOException */ @Test public void testpushtoapp() throws IOException { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); // 通知栏全部消息推送 VarnishedMessage message = new VarnishedMessage.Builder().appId(appId).title("java Sdk 全部推送标题 ").content("java Sdk 全部推送内容 ").noticeexpandtype(1).noticeexpandcontent(" 展开文本内容 ").clicktype(2).url("http://www.baidu.com").parameters(json.pa rseobject("{\"k1\":\"value1\",\"k2\":0,\"k3\":\"value3\"")).offline(true).validtime(12).suspend(true).clearnoticebar(true).vibrate(false).lights(fa lse).sound(false).fixspeed(true).fixspeedrate(30).pushtimetype(1).starttime(new Date()).build(); ResultPack<Long> result = push.pushtoapp(pushtype.statusbar, message); System.out.println(result); // 透传全部推送 UnVarnishedMessage message2 = new UnVarnishedMessage.Builder().appId(appId).title("Java SDK 全部推送标题 ").content("java Sdk 全部推送内容 ").isoffline(true).validtime(10).pushtimetype(1).starttime(new Date()).build(); 32
result = push.pushtoapp(pushtype.direct, message2); System.out.println(result); 2.2.7 应用标签推送 (pushtotag) 接口说明 : 接口 说明 ResultPack<Long> pushtotag(pushtype pushtype, Message message, List<String> tagname, ScopeType scopetype) 应用标签推送 参数说明 : 参数名称类型必需默认描述 pushtype PushType 是 null 消息类型 message Message 是 null 消息体 tagname List 是 null 推送标签 scopetype ScopeType 是 null 标签集合类型 返回值 : Long 任务 ID 示例 : /** * 标签推送 (pushtotag) * * @throws IOException */ @Test public void testpushtotag() throws IOException { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); // 推送标签 List<String> tagname = new ArrayList<String>(); 33
tagname.add("news"); tagname.add("tech"); // 通知栏标签推送 VarnishedMessage varnishedmessage = new VarnishedMessage.Builder().appId(appId).title("java Sdk 标签推送标题 ").content("java Sdk 标签推送内容 ").noticeexpandtype(1).noticeexpandcontent(" 展开文本内容 ").offline(true).validtime(12).suspend(true).clearnoticebar(true).vibrate(false).lights(false).sound(false).fixspeed(true).fixspeedrate(30).pushtimetype(1).starttime(new Date()).build(); ResultPack<Long> result = push.pushtotag(pushtype.statusbar, varnishedmessage, tagname, ScopeType.INTERSECTION); System.out.println(result); // 透传标签推送 UnVarnishedMessage unvarnishedmessage = new UnVarnishedMessage.Builder().appId(appId).title("Java SDK 标签推送标题 ").content("java Sdk 标签推送内容 ").isoffline(true).validtime(10).pushtimetype(1).starttime(new Date()).build(); result = push.pushtotag(pushtype.direct, unvarnishedmessage, tagname, ScopeType.UNION); System.out.println(result); 2.2.8 取消推送任务 (canceltaskpush) 接口说明 : 接口 ResultPack<Boolean> canceltaskpush(pushtype pushtype, long appid, long taskid) 说明 只针对全部用户推送以及标签推送且推送状态为待推送或者推送中的任务取消 34
参数说明 : 参数名称 类型 必需 默认 描述 pushtype PushType 是 null 消息类型 appid Long 是 null 应用 ID taskid Long 是 null 任务 ID 返回值 : Boolean true: 成功 false: 失败 示例 : /** * 取消推送任务 (canceltaskpush) 只针对全网推送生效 * @throws IOException */ @Test public void testcanceltaskpush() throws IOException { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); long taskid = 123l; ResultPack resultpack = push.canceltaskpush(pushtype.statusbar, appid, taskid); System.out.println(resultPack); 2.3 推送统计 获取任务推送统计 (gettaskstatistics) 接口说明 : 接口 说明 public ResultPack<TaskStatistics> gettaskstatistics(long appid, long taskid) 获取推送统计 参数说明 : 35
参数名称类型必需默认描述 appid Long 是 null 应用 ID taskid Long 是 null 任务 ID 返回值 : TaskStatistics 示例 : /** * 获取任务统计结果 * * @throws IOException */ @Test public void testgettaskstatistics() throws IOException { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); long taskid = 44760L; ResultPack<TaskStatistics> resultpack = push.gettaskstatistics(appid, taskid); System.out.println(resultPack); 36