推送ios以及android信息,简单的基于jpush v2带IMEI的推送实现。
maven:
<dependency>
<groupId>cn.jpush.api</groupId>
<artifactId>jpush-client</artifactId>
<version>2.3.1</version>
</dependency>
实现:
JPushClient jpush = null;
NotificationParams params = new NotificationParams();
params.setReceiverType(ReceiverTypeEnum.ALIAS);
params.setReceiverValue(token);
Map<String, Object> pushType = new HashMap<String, Object>();//存放待推送的数据键值对,例pushType.put("id", id);
if("ios".equals(platform)){
jpush = new JPushClient(masterSecret, appKey,0, DeviceEnum.IOS, false);
IosExtras extras = new IosExtras(num); //ios推送几条未读
pushType.put("ios", extras);
}else{
jpush = new JPushClient(masterSecret,appKey,0, DeviceEnum.Android,false);
}
long startTime = System.currentTimeMillis();
MessageResult ret = jpush.sendNotification("测试推送!", params, pushType);
log.info("返回状态码:" + ret.getErrorCode());
if(!ret.isResultOK()){
log.info("错误信息:"+ret.getErrorMessage());
throw new RuntimeException("jpush 推送失败, token :" + token);
}
其他推送待ing......
具体jpush官方文档地址:http://docs.jpush.io/server/rest_api_v2_push/