1、Tag推送——————按照分类推送
public static PushPayload buildPushObject_all_alias_alert(String gender, String title) {
return PushPayload.newBuilder()
.setPlatform(Platform.all())
.setAudience(Audience.tag(gender, "secret"))
.setNotification(
Notification
.newBuilder()
.setAlert(title)
.addPlatformNotification(
IosNotification.newBuilder().setSound("default").setBadge(1).addExtras(null)
.build())
.addPlatformNotification(AndroidNotification.newBuilder().build()).build()).build();
}
2、Alias推送(定点推送 不带参数)
public static PushPayload buildPushObject_memberId_alias_alert(String memberId, String title) {
return PushPayload
.newBuilder()
.setPlatform(Platform.all())
.setAudience(Audience.alias(memberId))
.setNotification(
Notification
.newBuilder()
.setAlert(title)
.addPlatformNotification(
IosNotification.newBuilder().setSound("default").setBadge(1).addExtras(null)
.build())
.addPlatformNotification(AndroidNotification.newBuilder().build()).build()).build();
}
3、Alias推送(定点推送 带参数)
public static PushPayload buildPushObject_memberId_alias_alert(String memberId, String title, String id, int type) {
// 补充要传递的参数
Map<String, String> ex = new HashMap<String, String>();
ex.put("id", id);
ex.put("type", type + "");
return PushPayload
.newBuilder()
.setPlatform(Platform.all())
.setAudience(Audience.alias(memberId))
.setNotification(
Notification
.newBuilder()
.setAlert(title)
.addPlatformNotification(
IosNotification.newBuilder().setSound("default").setBadge(1).addExtras(ex)
.build())
.addPlatformNotification(AndroidNotification.newBuilder().addExtras(ex).build())
.build()).build();
}
4、静默推送
public static PushPayload buildPushObject_memberId_alias_silenceAlert(String memberId, String title,int id,int classfyID,int type) {
return PushPayload
.newBuilder()
.setPlatform(Platform.android_ios())
.setAudience(Audience.alias(memberId))
.setNotification(
Notification
.newBuilder()
.setAlert("")
.addPlatformNotification(
IosNotification.newBuilder().setContentAvailable(true).addExtra("classfyID",classfyID)
.build())
.build())
.setMessage(
Message
.newBuilder()
.setMsgContent("")
.addExtra("classfyID",classfyID).build()
)
.setOptions(Options.newBuilder().setApnsProduction(true).build())
.build();
}
5、广播
public static PushPayload buildPushObject_all_all_alert(String title) {
// return PushPayload.alertAll(title);
return PushPayload
.newBuilder()
.setPlatform(Platform.all())
.setAudience(Audience.all())
.setNotification(
Notification
.newBuilder()
.setAlert(title)
.addPlatformNotification(
IosNotification.newBuilder().setSound("default").setBadge(1).addExtras(null)
.build())
.addPlatformNotification(AndroidNotification.newBuilder().build()).build()).build();
}
/**
补充 苹果开发者模式设置,否则前端iphone无法接收到推送数据
public static PushPayload enterpriseNotPassAlert(String id, int type, String reason) {
// 补充要传递的参数
Map<String, String> ex = new HashMap<String, String>();
id = "enterprise_" + id;
ex.put("type", type + "");
ex.put("parttimeId", "");
reason = "您的企业资料审核未通过,原因如下:" + reason;
ex.put("reason", "您的企业资料审核未通过,原因如下:" + reason);
return PushPayload
.newBuilder()
.setPlatform(Platform.all())
.setAudience(Audience.alias(id))
.setOptions(Options.newBuilder().setApnsProduction(true).build())
.setNotification(
Notification
.newBuilder()
.setAlert(reason)
.addPlatformNotification(
IosNotification.newBuilder().setSound("default").setBadge(1).addExtras(ex)
.build())
.addPlatformNotification(AndroidNotification.newBuilder().addExtras(ex).build())
.build()).build();
}