java后台推送,只调用了一次,但是极光出现两次推送 You_are_my_angel 2017-11-06 08:31 1k 0
```
public static int sendToAll(String title, String content, String url, String urlType, String extrasparam, String extrasparam2) {
log.info("sendToAll执行!");
PushPayload pushPayload = PushPayload.newBuilder()
.setPlatform(Platform.android_ios())
.setAudience(Audience.all())
.setNotification(Notification.newBuilder()
.setAlert(content)
.addPlatformNotification(AndroidNotification.newBuilder()
.setTitle(title)
.addExtra("url", url)
.addExtra("urlType", urlType)
.addExtra("type", extrasparam)
.addExtra("pushinfoId", extrasparam2)
.build())
.addPlatformNotification(IosNotification.newBuilder()
.incrBadge(1)
.setAlert(title)
.addExtra("url", url)
.addExtra("urlType", urlType)
.addExtra("type", extrasparam)
.addExtra("pushinfoId", extrasparam2)
.build())
.build())
.setOptions(Options.newBuilder()
// 此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义
.setApnsProduction(true)
// 此字段是给开发者自己给推送编号,方便推送者分辨推送记录
//.setSendno(1)
// 此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天,单位为秒
//.setTimeToLive(259200) //3天
.build())
.setMessage(Message.newBuilder()
.setMsgContent(content)
.setTitle(title)
.addExtra("type", extrasparam)
.addExtra("pushinfoId", extrasparam2)
.addExtra("from", "JPush")
.addExtra("url", url)
.addExtra("urlType", urlType)
.build())
.build();
PushResult pushResult;
try {
pushResult = jPushClient.sendPush(pushPayload);
log.info("pushResult:"+pushResult);
if (pushResult.getResponseCode() == 200) {
return 1;
}
} catch (APIConnectionException e) {
// TODO Auto-generated catch block
log.info("sendToAll执行异常:"+e.getMessage());
e.printStackTrace();
} catch (APIRequestException e) {
// TODO Auto-generated catch block
log.info("sendToAll执行异常:"+e.getMessage());
e.printStackTrace();
}
return 0;
}
``` 回答 关注