集成推送平台 JAVA 版本 SDK JavaPushSdk 发布说明 ( 请使用最新版本 ) 中央仓库获取 MVN Repository 或者 Central Repository 直接下载获取 Java Server SDK 更新日志 [2017-12-06]V1.0.0.20171206 1.0.0 标准版 定义 推送服务 (IFlymeUpsPush) 调用该类实例的方法来推送消息, 构造函数说明如下 : 必填 appsecret String 是 null 注册应用 appsecret usessl Boolean 否 false 是否使用 https 接口调用 :true 使用 https 连接,false 使用 http 连接 通知栏消息体 (Message) 推送消息实体 ( 抽象类 ) 子类 VarnishedMessage UnVarnishedMessage 说明 通知栏消息体 透传消息体 通知栏消息 (VarnishedMessage) 必 填 appid Long 是 null 注册应用 appid title String 是 null 推送标题, 字数限制 1~32 content String 是 null 推送内容, 字数限制 1~100 clicktype int 否 0 点击动作 (0," 打开应用 "),(1," 打开应用页面 "),(2," 打开 URI 页面 "),(3, " 应用客户端自定义 "),(4, " 打开自定 Intent 1/12
URI"); 非必填, 值为 0 url String 否 null URI 页面地址, clicktype 为打开 URI 页面时, 必填, 长度 限制 1000byte parameters JSONObject 否 null 透传参数 JSON 格式, 非必填 activity String 否 null customattribute String 否 null customuri String 否 null isoffline Boolean 否 true validtime int 否 24 pushtimetype int 否 0 starttime Date 否 null 应用页面地址, clicktype 为打开应用页面时, 格式 pkg.activity eg: com.meizu.upspushdemo.testactivity 必填 应用客户端自定义内容, clicktype 为应用客户端自定义时, 必填, 长度限制 1000byte 打开自定 Intent URI clicktype=4, 必填, 长度限制 1000 字节 eg:upspushscheme://com.meizu.upspush/notify_detail? title=ups title&content=ups content 是否进离线消息, (false 否 true 是 ) 非必填, 值为 true 有效时长 (1~72 小时内的正整数 ), isoffline 值为 true 时, 必填, 值的范围 1~72 定时推送 (0, " 即时 "),(1, " 定时 "), 只对全部用户推送生效 任务定时开始时间, 非必填,pushTimeType 为 True 必填 只对全部用户推送生效 isfixspeed Boolean 否 false 是否定速推送, 非必填, 值为 False fixspeedrate Long 否 0 定速速率, isfixspeed 为 true 时, 必填 issuspend Boolean 否 true isclearnoticebar Boolean 否 true 是否通知栏悬浮窗显示 (true 显示,false 不显示 ) 非必填, True 是否可清除通知栏 (true 可以,false 不可以 ), 非必填, true isfixdisplay Boolean 否 false 是否定时展示 非必填, false fixdisplaytime (Date,Date) 否 (null,null) 定时展示开始, 结束时间 fixdisplay 为 true 时, 必填, 并且开始时间要晚于结束时间 vibrate Boolean 否 true 震动 (false 关闭 true 开启 ), 非必填, true lights Boolean 否 true 闪光 (false 关闭 true 开启 ), 非必填, true sound Boolean 否 true 声音 (false 关闭 true 开启 ), 非必填, true 透传消息 (UnVarnishedMessage) 2/12
必 填 默 认 appid Long 是 null 注册应用 appid title String 否 null 推送标题, 任务推送建议填写, 方便数据查询, 字数限制 1~32 content String 是 null 推送内容, 必填, 字数限制 3800byte 以内 isoffline Boolean 否 true 是否进离线消息, 非必填, 为 true validtime int 否 24 有效时长 (1~72 小时内的正整数 ), isoffline 值为 true 时, 必填, 值的范围 1--72 pushtimetype int 否 0 定时推送 (0, " 即时 "),(1, " 定时 "), 只对全部用户推送生效 starttime Date 否 null 任务定时开始时间, pushtimetype 为 1 必填 只对全部用户推 送生效 isfixspeed Boolean 否 false 是否定速推送, 非必填, 值为 false fixspeedrate Long 否 0 定速速率 isfixspeed 为 true 时, 必填 接口返回值 (ResultPack) 方法名称 code() String 接口响应码 Comment() String 接口响应 value() T 接口响应内容 errorcode() Enum 接口响应异常枚举详见 ErrorCode 消息推送结果 (PushResult) 方法名称 getmsgid() String 推送消息 ID, 用于推送流程明细排查 getresptarget() Map 推送目标结果状态 (KEY: 推送响应码 VALUE: 响应码对应的目标用户 ) logs Map app 渠道推送日志, 用于问题排查 (KEY: 渠道 value:log) 接口响应码定义 (ErrorCode) 名称 Code Commen UNKNOWN_ERROR -1 未知错误 SUCCESS 200 成功 SYSTEM_ERROR 1001 系统错误 3/12
SYSTEM_BUSY 1003 服务器忙 PARAMETER_ERROR 1005 参数错误, 请参考 API 文档 INVALID_SIGN 1006 签名认证失败 INVALID_APPLICATION_ID 110000 appid 不合法 INVALID_APPLICATION_KEY 110001 appkey 不合法 UNSUBSCRIBE_PUSHID 110002 pushid 未注册 INVALID_PUSHID 110003 pushid 非法 PARAM_BLANK 110004 参数不能为空 APP_REQUEST_EXCEED_LIMIT 110010 应用请求频率过快 APP_PUSH_TIME_EXCEED_LIMIT 110051 超过该应用的次数限制 APP_REQUEST_PUSH_LIMIT 110019 超过该应用每天推送次数限制 INVALID_APPLICATION_PACKAGENAME 110031 packagename 不合法 INVALID_TASK_ID 110032 非法的 taskid INVALID_APPLICATION_SECRET 110033 非法的 appsecret DIRECT_OUT_LIMIT 110053 透传超过限制 推送响应码定义 (PushResponseCode) 名称 Code Commen RSP_NO_AUT 201 没有权限, 服务器主动拒绝 RSP_DB_ERROR 501 推送消息失败 (db_error) RSP_INTERNAL_ERROR 513 推送消息失败 RSP_SPEED_LIMIT 518 推送超过配置的速率 RSP_OVERFLOW 519 推送消息失败服务过载 RSP_UNSUBSCRIBE_PUSHID 110002 pushid 未订阅 ( 包括推送开关关闭的设备 ) RSP_INVALID_PUSHID 110003 pushid 非法 RSP_UNSUBSCRIBE_ALIAS 110005 别名未订阅 ( 包括推送开关关闭的设备 ) 推送 (PushType) 枚举 STATUSBAR Enum 通知栏消息 DIRECT Enum 透传消息 4/12
渠道 (CP) 枚举 MEIZU Enum 魅族 XIAOMI Enum 小米 HUAWEI Enum 华为 任务推送统计 ( 天 )(DailyPushStatics) 名称 date Date 日期 pushedno Long 推送数 acceptno Long 接收数 clickno Long 点击数 接口说明 非任务推送 向指定的 pushid 推送消息 注 : 推送平台使用 pushid 来标识每个独立的用户, 每一台终端上每一个 app 拥有一个独立的 pushid 应用场景 场景 1: 查找手机业务需要远程定位位置, 可发送消息指令到对应的设备 场景 2: 社区用户回帖消息提醒, 用户对发表的帖子有最新回复时, 消息提醒发帖者 pushid 通知栏消息推送 (pushmessage) 接口说明 接口 ResultPack<PushResult> pushmessage(varnishedmessage message, List<String> pushids) ResultPack<PushResult> pushmessage(varnishedmessage message, List<String> pushids, int retries) 说明 推送通知栏 消息 推送通知栏 消息 5/12
参数说明 必需 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 { // 推送对象 IFlymeUpsPush push = new IFlymeUpsPush(APP_SECRET_KEY); // 组装消息 VarnishedMessage message = new VarnishedMessage.Builder().appId(appId).title("Java SDK 推送标题 ").content(" 消息内容 ").clicktype(clicktype.custom_uri.getdesc()) //.activity("com.meizu.upspushdemo.testactivity").customuri("upspushscheme://com.meizu.upspush/notify_detail? title=ups title&content=ups content") //.parameters(param) //.url("https://www.baidu.com/") //.customattribute(" 客户端自定义参数 ").build(); // 目标用户 List<String> pushids = new ArrayList<String>(); pushids.add("pushid_1"); pushids.add("pushid_2"); // 1 调用推送服务 ResultPack<PushResult> result = push.pushmessage(message, pushids); 6/12
if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 Map<String, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push result:" + pushresult); if (targetresultmap!= null &&!targetresultmap.isempty()) { System.err.println("push fail token:" + targetresultmap); else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); 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 处理 7/12
示例 /** * 透传消息推送 (pushmessage) * @throws Exception */ @Test public void testunvarnishedmessagepush() throws Exception { // 推送对象 IFlymeUpsPush push = new IFlymeUpsPush(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<String, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push result:" + pushresult); if (targetresultmap!= null &&!targetresultmap.isempty()) { System.err.println("push fail token:" + targetresultmap); else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); 别名通知栏消息推送 (pushmessagebyalias) 8/12
接口说明 接口 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: 响应码对应的目标用户 ) 注 : 只返回不合法 超速以及推送失败的目标用户 示例 /** * 别名通知栏消息推送 (pushmessage) * * @throws Exception */ @Test public void testvarnishedmessagepushbyalias() throws Exception { // 推送对象 IFlymeUpsPush push = new IFlymeUpsPush(APP_SECRET_KEY); // 组装消息 VarnishedMessage message = new VarnishedMessage.Builder().appId(appId).title("Java SDK 推送标题 ").content("java SDK 推送内容 ").build(); // 目标用户 List<String> alias = new ArrayList<String>(); alias.add("alias1"); alias.add("alias2"); 9/12
// 1 调用推送服务 ResultPack<PushResult> result = push.pushmessagebyalias(message, alias); // 2 处理推送结果 if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 Map<String, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push result:" + pushresult); if (targetresultmap!= null &&!targetresultmap.isempty()) { System.err.println("push fail token:" + targetresultmap); else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); 别名透传消息推送 (pushmessagebyalias) 接口说明 接口 ResultPack<PushResult> pushmessagebyalias(unvarnishedmessage message, List<String> alias) ResultPack<PushResult> pushmessagebyalias(unvarnishedmessage message, List<String> alias, int retries) 说明 推送透传 消息 推送透传 消息 参数说明 必需 message UnVarnishedMessage 是 null 推送消息 alias List 是 null 推送目标, 一批最多不能超过 1000 个 retries int 否 0 超时 or 异常重试次数 返回值 10/12
PushResult msgid; 推送消息 ID, 用于推送流程明细排查 resptarget; 推送目标结果状态 (key: 推送响应码 value: 响应码对应的目标用户 ) 注 : 只返回不合法 超速以及推送失败的目标用户 示例 /** * 别名透传推送 * * @throws Exception */ @Test public void testunvarnishedmessagepushbyalias() throws Exception { // 推送对象 IFlymeUpsPush push = new IFlymeUpsPush(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"); // 1 调用推送服务 ResultPack<PushResult> result = push.pushmessagebyalias(message, alias); if (result.issucceed()) { // 2 调用推送服务成功 ( 其中 map 为设备的具体推送结果, 一般业务针对超速的 code 做处理 ) PushResult pushresult = result.value(); String msgid = pushresult.getmsgid();// 推送消息 ID, 用于推送流程明细排查 Map<String, List<String>> targetresultmap = pushresult.getresptarget();// 推送结果, 全部推送成功, 则 map 为 empty System.out.println("push result:" + pushresult); if (targetresultmap!= null &&!targetresultmap.isempty()) { System.err.println("push fail token:" + targetresultmap); else { // 调用推送接口服务异常 eg: appid appkey 非法 推送消息非法... // result.code(); // 服务异常码 // result.comment();// 服务异常 System.out.println(String.format("pushMessage error code:%s comment:%s", result.code(), result.comment())); 11/12
获取应用推送统计 (dailypushstatics) 接口说明 接口 public ResultPack<List<DailyPushStatics>> dailypushstatics(long appid, Date starttime, Date endtime) 说明 获取应用推 送统计 参数说明 必需 appid Long 是 null 应用 ID starttime Date 是 null 开始日期 endtime Date 是 null 结束日期 返回值 List<DailyPushStatics> 示例 /** * 获取任务统计结果 * * @throws IOException */ @Test public void testdailypushstatics() throws IOException { // 推送对象 IFlymePush push = new IFlymePush(APP_SECRET_KEY); Date starttime = DateUtils.str2Date("2017-06-03", "yyyy-mm-dd"); Date endtime = DateUtils.str2Date("2017-06-10", "yyyy-mm-dd"); ResultPack<List<DailyPushStatics>> resultpack = push.dailypushstatics(appid, starttime, endtime); System.out.println(resultPack); 12/12