/** The shortcut of building a simple message object to all platforms and all audiences */ public static PushPayload messageAll(String msgContent) { return new Builder() .setPlatform(Platform.all()) .setAudience(Audience.all()) .setMessage(Message.content(msgContent)) .build(); }
@Test public void testMsgContent() { Message message = Message.content("msg content"); JsonObject json = new JsonObject(); json.add("msg_content", new JsonPrimitive("msg content")); Assert.assertEquals("", json, message.toJSON()); }
/** * 构建推送对象:平台是 iOS,推送目标是 "tag1", "tag_all" 的交集, 推送内容同时包括通知与消息 - 通知信息是 ALERT,角标数字为 5,通知声音为 "happy", * 并且附加字段 from = "JPush";消息内容是 MSG_CONTENT。通知是 APNs 推送通道的, 消息是 JPush 应用内消息通道的。APNs * 的推送环境是“生产”(如果不显式设置的话,Library 会默认指定为开发) * * @return */ private static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage( String target, String targetAll, String messageTitle, String message, String otherTitle, String otherMessage) { return PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.tag_and(target, targetAll)) .setNotification( Notification.newBuilder() .addPlatformNotification( IosNotification.newBuilder() .setAlert(messageTitle) .setBadge(5) .setSound("happy.caf") .addExtra(otherTitle, otherMessage) .build()) .build()) .setMessage(Message.content(message)) .setOptions(Options.newBuilder().setApnsProduction(PRODUCT_MODE).build()) .build(); }