cn.jpush.api.push.model.PushPayload Java Examples

The following examples show how to use cn.jpush.api.push.model.PushPayload. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: anyline   Author: anylineorg   File: JPushUtil.java    License: Apache License 2.0 6 votes vote down vote up
private boolean sendByAlias(String type, String title, String msg, Map<String,String> extras, String[] alias){ 
		boolean result = false; 
		try { 
			PushPayload pl = buildPushObject_Alias(type, title, msg, extras, alias); 
			PushResult pr = client.sendPush(pl); 
			result = pr.isResultOK(); 
			 
//			extras.put("MESSAGE", msg); 
//			pl = buildPushObject_Alias_IOS(type, title, extras, alias); 
//			pr = client.sendPush(pl); 
//			result = pr.isResultOK() && result; 
		} catch (Exception e) { 
			e.printStackTrace(); 
			result = false; 
		} 
		return result; 
	}
 
Example #2
Source Project: anyline   Author: anylineorg   File: JPushUtil.java    License: Apache License 2.0 6 votes vote down vote up
private boolean sendByTag(String type, String title, String msg, Map<String,String> extras, String[] tags){ 
		boolean result = false; 
		try { 
			extras.put("MESSAGE", msg); 
			extras.put("TITLE", title); 
//			 
			PushPayload pl = buildPushObjec_Tag_Android(type, title, msg, extras, tags); 
			PushResult pr = client.sendPush(pl); 
			result = pr.isResultOK(); 
////			 
//			pl = buildPushObjec_Tag_IOS(type, title, extras, tags);
//			pr = client.sendPush(pl); 
//			result = pr.isResultOK() && result; 
		} catch (Exception e) { 
			e.printStackTrace(); 
			result = false; 
		} 
		return result; 
	}
 
Example #3
Source Project: anyline   Author: anylineorg   File: JPushUtil.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unused", "static-access" })
private PushPayload buildPushObjectByTag(String type, String title, String msg, Map<String, String> extras,String[] tags) { 
	if(null == extras){ 
		extras = new HashMap<String,String>(); 
	} 
	return PushPayload.newBuilder() 
			.setPlatform(Platform.all()) 
			.setAudience(Audience.newBuilder() 
					.addAudienceTarget(AudienceTarget.tag_and(tags)) 
					.build()) 
					.setMessage(Message.newBuilder() 
							.setMsgContent(type) 
							.addExtras(extras) 
							.build()).setOptions(Options.newBuilder() 
			                         .setApnsProduction(true) 
			                         .build()) 
							.setNotification(Notification.android(msg, title, extras).ios(title, extras)) 
							.build(); 
}
 
Example #4
Source Project: anyline   Author: anylineorg   File: JPushUtil.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("static-access")
private PushPayload buildPushObject_Alias(String type, String title, String msg, Map<String, String> extras,String[] alias) { 
	if(null == extras){ 
		extras = new HashMap<String,String>(); 
	} 
	return PushPayload.newBuilder() 
			.setPlatform(Platform.all()) 
			.setAudience(Audience.newBuilder() 
					.addAudienceTarget(AudienceTarget.alias(alias)) 
					.build()) 
					.setMessage(Message.newBuilder() 
							.setMsgContent(type) 
							.addExtras(extras) 
							.build()).setOptions(Options.newBuilder() 
			                         .setApnsProduction(true) 
			                         .build()) 
							.setNotification(Notification.android(msg, title, extras).ios(title, extras)) 
							.build(); 
}
 
Example #5
Source Project: anyline   Author: anylineorg   File: JPushUtil.java    License: Apache License 2.0 6 votes vote down vote up
private PushPayload buildPushObjec_Tag_Android(String type, String title, String msg, Map<String, String> extras,String[] tags) { 
	if(null == extras){ 
		extras = new HashMap<String,String>(); 
	} 
	return PushPayload.newBuilder() 
			.setPlatform(Platform.all()) 
			.setAudience(Audience.newBuilder() 
					.addAudienceTarget(AudienceTarget.tag_and(tags)) 
					.build()) 
					.setMessage(Message.newBuilder() 
							.setMsgContent(type) 
							.addExtras(extras) 
							.build()).setOptions(Options.newBuilder() 
			                         .setApnsProduction(true) 
			                         .build()) 
							.setNotification(Notification.android(msg, title, extras)) 
							.build(); 
}
 
Example #6
Source Project: anyline   Author: anylineorg   File: JPushUtil.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private PushPayload buildPushObject_Alias_Android(String type, String title, String msg, Map<String, String> extras,String[] alias) { 
	if(null == extras){ 
		extras = new HashMap<String,String>(); 
	} 
	return PushPayload.newBuilder() 
			.setPlatform(Platform.all()) 
			.setAudience(Audience.newBuilder() 
					.addAudienceTarget(AudienceTarget.alias(alias)) 
					.build()) 
					.setMessage(Message.newBuilder() 
							.setMsgContent(type) 
							.addExtras(extras) 
							.build()).setOptions(Options.newBuilder() 
			                         .setApnsProduction(true) 
			                         .build()) 
							.setNotification(Notification.android(msg, title, extras)) 
							.build(); 
}
 
Example #7
Source Project: anyline   Author: anylineorg   File: JPushUtil.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private PushPayload buildPushObjec_Tag_IOS(String type, String title,Map<String, String> extras,String[] tags) { 
	if(null == extras){ 
		extras = new HashMap<String,String>(); 
	} 
	return PushPayload.newBuilder() 
			.setPlatform(Platform.all()) 
			.setAudience(Audience.newBuilder() 
					.addAudienceTarget(AudienceTarget.tag_and(tags)) 
					.build()) 
					.setMessage(Message.newBuilder() 
							.setMsgContent(type) 
							.addExtras(extras) 
							.build()).setOptions(Options.newBuilder() 
			                         .setApnsProduction(true) 
			                         .build()) 
							.setNotification(Notification.ios(title, extras)) 
							.build(); 
}
 
Example #8
Source Project: anyline   Author: anylineorg   File: JPushUtil.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private PushPayload buildPushObject_Alias_IOS(String type, String title,Map<String, String> extras,String[] alias) { 
	if(null == extras){ 
		extras = new HashMap<String,String>(); 
	} 
	return PushPayload.newBuilder() 
			.setPlatform(Platform.all()) 
			.setAudience(Audience.newBuilder() 
					.addAudienceTarget(AudienceTarget.alias(alias)) 
					.build()) 
					.setMessage(Message.newBuilder() 
							.setMsgContent(type) 
							.addExtras(extras) 
							.build()).setOptions(Options.newBuilder() 
			                         .setApnsProduction(true) 
			                         .build()) 
							.setNotification(Notification.ios(title, extras)) 
							.build(); 
}
 
Example #9
Source Project: api-boot   Author: minbox-projects   File: ApiBootMessagePushJiGuangServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * setting platform
 *
 * @param messagePushBody ApiBoot Message Push request body
 * @param builder         push payload builder
 */
private void addPlatformMeta(MessagePushBody messagePushBody, PushPayload.Builder builder) {
    switch (messagePushBody.getPlatform()) {
        case ALL:
            builder.setPlatform(Platform.all());
            break;
        case IOS:
            builder.setPlatform(Platform.ios());
            // set is production
            builder.setOptions(Options.newBuilder().setApnsProduction(isProduction()).build());
            break;
        case ANDROID:
            builder.setPlatform(Platform.android());
            break;
        default:
            builder.setPlatform(Platform.all());
            break;
    }
}
 
Example #10
Source Project: api-boot   Author: minbox-projects   File: ApiBootMessagePushJiGuangServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * add notification
 *
 * @param builder         push payload builder
 * @param messagePushBody message push body
 */
private void addNotificationMeta(PushPayload.Builder builder, MessagePushBody messagePushBody) {
    Notification notification = null;
    switch (messagePushBody.getPlatform()) {
        case ALL:
            notification = Notification.newBuilder()
                .addPlatformNotification(getIosNotificationMeta(messagePushBody))
                .addPlatformNotification(getAndroidNotificationMeta(messagePushBody))
                .build();
            break;
        case IOS:
            notification = Notification.newBuilder()
                .addPlatformNotification(getIosNotificationMeta(messagePushBody)).build();
            break;
        case ANDROID:
            notification = Notification.newBuilder()
                .addPlatformNotification(getAndroidNotificationMeta(messagePushBody)).build();
            break;

    }
    builder.setNotification(notification);
}
 
Example #11
Source Project: classchecks   Author: IaHehe   File: JPushUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static PushPayload buildPushObject_android_regId_alert(String pushAlert, String pushTitle, List<String> regIds) {
	
	Map<String, String> extras = new HashMap<String, String>();
    extras.put("extra_1", "val1");
    extras.put("extra_2", "val2");
	
	return PushPayload.newBuilder()
			.setPlatform(Platform.android())
			.setAudience(Audience.registrationId(regIds))
			.setNotification(Notification
					.newBuilder()
					.setAlert(pushAlert)
					.addPlatformNotification(AndroidNotification.newBuilder()
							.setTitle(pushTitle)
							.addExtras(extras)
							.build())
					.build())
			.build();
}
 
Example #12
Source Project: java_server   Author: xiaowei1118   File: JpushInterface.java    License: MIT License 6 votes vote down vote up
public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage(String message, String msg_content) {
    return PushPayload.newBuilder()
            .setPlatform(Platform.ios())
            .setAudience(Audience.tag_and("tag1", "tag_all"))
            .setNotification(Notification.newBuilder()
                    .addPlatformNotification(IosNotification.newBuilder()
                            .setAlert(message)
                            .setBadge(5)
                            .setSound("happy")
                            .addExtra("from", "JPush")
                            .build())
                    .build())
            .setMessage(Message.content(msg_content))
            .setOptions(Options.newBuilder()
                    .setApnsProduction(true)
                    .build())
            .build();
}
 
Example #13
Source Project: api-boot   Author: minbox-projects   File: ApiBootMessagePushJiGuangServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * execute push message
 *
 * @param messagePushBody request body
 * @throws ApiBootException ApiBoot Exception
 */
@Override
public void executePush(MessagePushBody messagePushBody) throws ApiBootException {
    try {
        // push client config
        PushClientConfig pushClientConfig = getCurrentPushClient();
        // jpush client
        JPushClient pushClient = new JPushClient(pushClientConfig.getMasterSecret(), pushClientConfig.getAppKey(), null, ClientConfig.getInstance());

        PushPayload.Builder builder = PushPayload.newBuilder();

        // setting platform
        addPlatformMeta(messagePushBody, builder);

        // setting tag
        addTagMeta(messagePushBody, builder);
        // setting alias
        // Priority is higher than tag
        addAliasMeta(messagePushBody.getAlias(), builder);

        // setting notification
        addNotificationMeta(builder, messagePushBody);

        // execute push message
        pushClient.sendPush(builder.build());
    } catch (Exception e) {
        logger.error("Execute push message fail.", e);
    }

}
 
Example #14
Source Project: classchecks   Author: IaHehe   File: JPushUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
    * 
   * @Title: buildPushObject_all_tags_teacher_alert 
   * @Description: TODO(学生端) 
   * @return
   * PushPayload 
    */
private static PushPayload buildPushObject_android_tags_alert(String tag, String pushAlert, String pushTitle) {
       return PushPayload.newBuilder()
               .setPlatform(Platform.android())//设置接受的平台
               .setAudience(Audience.tag(tag))//Audience设置为all,说明采用广播方式推送,所有用户都可以接收到
               .setNotification(Notification.newBuilder()
               		.setAlert(pushAlert)
               		.addPlatformNotification(AndroidNotification.newBuilder()
               				.setTitle(pushTitle).build())
               		.build())
               .build();
   }
 
Example #15
Source Project: java_server   Author: xiaowei1118   File: JpushInterface.java    License: MIT License 5 votes vote down vote up
public static PushPayload buildPushObject_all_all_alert(String message) {
    return PushPayload.newBuilder()
            .setPlatform(Platform.android_ios())
            .setAudience(Audience.all())
            .setNotification(Notification.alert(message))
            .setOptions(Options.newBuilder().setApnsProduction(false).build())
            .setMessage(Message.newBuilder()
                    .setMsgContent(message)
                    .addExtra("from", "foryou")
                    .build())
            .build();
}
 
Example #16
Source Project: java_server   Author: xiaowei1118   File: JpushInterface.java    License: MIT License 5 votes vote down vote up
public static PushPayload buildPushObject_android_and_ios_alias_alert(String alertString, String phone) {

        return PushPayload.newBuilder()
                .setPlatform(Platform.android_ios())
                .setAudience(Audience.alias(phone))
                .setNotification(Notification.alert(alertString))
                .setOptions(Options.newBuilder().setApnsProduction(false
                ).build())
                .setMessage(Message.newBuilder()
                        .setMsgContent(alertString)
                        .addExtra("from", "foryou")
                        .build())
                .build();
    }
 
Example #17
Source Project: java_server   Author: xiaowei1118   File: JpushInterface.java    License: MIT License 5 votes vote down vote up
public static PushPayload buildPushObject_android_and_ios_tag_alert(
        String message, String tag) {
    return PushPayload.newBuilder()
            .setPlatform(Platform.android_ios())
            .setAudience(Audience.tag(tag))
            .setNotification(Notification.alert(message))
            .setOptions(Options.newBuilder().setApnsProduction(false).build())
            .setMessage(Message.newBuilder()
                    .setMsgContent(message)
                    .addExtra("from", "foryou")
                    .build())
            .build();
}
 
Example #18
Source Project: java_server   Author: xiaowei1118   File: JpushInterface.java    License: MIT License 5 votes vote down vote up
public static PushPayload buildPushObject_android__alertWithTitle(String message, String title) {
    return PushPayload.newBuilder()
            .setPlatform(Platform.android())
            .setAudience(Audience.tag("tag1"))
            .setNotification(Notification.android(message, title, null))
            .build();
}
 
Example #19
Source Project: java_server   Author: xiaowei1118   File: JpushInterface.java    License: MIT License 5 votes vote down vote up
public static PushPayload buildPushObject_android_and_ios() {
    return PushPayload.newBuilder()
            .setPlatform(Platform.android_ios())
            .setAudience(Audience.tag("tag1"))
            .setNotification(Notification.newBuilder()
                    .setAlert("alert content")
                    .addPlatformNotification(AndroidNotification.newBuilder()
                            .setTitle("Android Title").build())
                    .addPlatformNotification(IosNotification.newBuilder()
                            .incrBadge(1)
                            .addExtra("extra_key", "extra_value").build())
                    .build())
            .build();
}
 
Example #20
Source Project: java_server   Author: xiaowei1118   File: JpushInterface.java    License: MIT License 5 votes vote down vote up
public static PushPayload buildPushObject_ios_audienceMore_messageWithExtras(String msg_content) {
    return PushPayload.newBuilder()
            .setPlatform(Platform.android_ios())
            .setAudience(Audience.newBuilder()
                    .addAudienceTarget(AudienceTarget.tag("tag1", "tag2"))
                    .addAudienceTarget(AudienceTarget.alias("alias1", "alias2"))
                    .build())
            .setMessage(Message.newBuilder()
                    .setMsgContent(msg_content)
                    .addExtra("from", "JPush")
                    .build())
            .build();
}
 
Example #21
Source Project: java_server   Author: xiaowei1118   File: JpushInterface.java    License: MIT License 5 votes vote down vote up
public static PushPayload bulidPushObject_ios_alert(String message) {
    return PushPayload.newBuilder()
            .setPlatform(Platform.ios())
            .setAudience(Audience.all())
            .setNotification(Notification.alert(message))
            .setMessage(Message.newBuilder()
                    .setMsgContent(message)
                    .addExtra("from", "mickey")
                    .build())
            .build();
}
 
Example #22
Source Project: java_server   Author: xiaowei1118   File: JpushInterface.java    License: MIT License 5 votes vote down vote up
public static PushPayload bulidPushObject_android_alert(String message) {
    return PushPayload.newBuilder()
            .setPlatform(Platform.android())
            .setAudience(Audience.all())
            .setNotification(Notification.alert(message))
            .setMessage(Message.newBuilder()
                    .setMsgContent(message)
                    .addExtra("from", "mickey")
                    .build())
            .build();
}
 
Example #23
Source Project: api-boot   Author: minbox-projects   File: ApiBootMessagePushJiGuangServiceImpl.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * add alias to push payload
 *
 * @param alias   alias list
 * @param builder push payload builder
 */
private void addAliasMeta(List<String> alias, PushPayload.Builder builder) {
    if (!ObjectUtils.isEmpty(alias)) {
        builder.setAudience(Audience.alias(alias));
    }
}
 
Example #24
Source Project: api-boot   Author: minbox-projects   File: ApiBootMessagePushJiGuangServiceImpl.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * add tag
 *
 * @param messagePushBody push message body
 * @param builder         push payload builder
 */
private void addTagMeta(MessagePushBody messagePushBody, PushPayload.Builder builder) {
    if (!ObjectUtils.isEmpty(messagePushBody.getTags())) {
        builder.setAudience(Audience.tag(messagePushBody.getTags()));
    }
}