极光推送 java util

publicclassJPushUtil {

/**

* 安卓iOS标签推送

*@paramtagValues 标签集合

*@paramtitle标题

*@paramsubTitle副标题仅iOS有效,没有传空字符串

*@paramcontent内容

*@paramextras自定义信息

*@return

*/

publicstaticbooleanPush_android_iOS_tag_Message(CollectiontagValues,

Stringtitle, StringsubTitle, Stringcontent,

Mapextras) {

JPushClientjpushClient= getJPushClient();

// For push, all you need do is to build PushPayload object.

PushPayloadpayload= buildPushObject_android_iOS_tag(tagValues,title,subTitle,content,extras);

try{

PushResultresult=jpushClient.sendPush(payload);

System.out.println(result);

if(result.getResponseCode() == 200)

returntrue;

else

returnfalse;

}catch(Exceptione) {

// Connection error, should retry later

e.printStackTrace();

}

returnfalse;

}

/**

* 安卓iOS别名推送

*@paramaliases别名集合

*@paramtitle标题

*@paramsubTitle副标题仅iOS有效,没有传空字符串

*@paramcontent内容

*@paramextras自定义信息

*@return

*/

publicstaticbooleanPush_android_iOS_alias_Message(Collectionaliases,

Stringtitle, StringsubTitle, Stringcontent,

Mapextras) {

JPushClientjpushClient= getJPushClient();

// For push, all you need do is to build PushPayload object.

PushPayloadpayload= buildPushObject_android_iOS_alias(aliases,title,subTitle,content,extras);

try{

PushResultresult=jpushClient.sendPush(payload);

System.out.println(result);

if(result.getResponseCode() == 200)

returntrue;

else

returnfalse;

}catch(Exceptione) {

// Connection error, should retry later

e.printStackTrace();

}

returnfalse;

}

/**

* 推送所有安卓

*@paramtitle标题

*@paramcontent内容

*@paramextras自定义信息

*@return

*/

publicstaticbooleanPush_all_android(

Stringtitle, Stringcontent,

Mapextras) {

JPushClientjpushClient= getJPushClient();

// For push, all you need do is to build PushPayload object.

PushPayloadpayload= buildPushObject_all_android(title,content,extras);

try{

PushResultresult=jpushClient.sendPush(payload);

System.out.println(result);

if(result.getResponseCode() == 200)

returntrue;

else

returnfalse;

}catch(Exceptione) {

// Connection error, should retry later

e.printStackTrace();

}

returnfalse;

}

/**

* 推送所有iOS

*@paramtitle标题

*@paramsubTitle副标题仅iOS有效,没有传空字符串

*@paramcontent内容

*@paramextras自定义信息

*@return

*/

publicstaticbooleanPush_all_iOS(

Stringtitle, StringsubTitle, Stringcontent,

Mapextras) {

JPushClientjpushClient= getJPushClient();

// For push, all you need do is to build PushPayload object.

PushPayloadpayload= buildPushObject_all_iOS(title,subTitle,content,extras);

try{

PushResultresult=jpushClient.sendPush(payload);

System.out.println(result);

if(result.getResponseCode() == 200)

returntrue;

else

returnfalse;

}catch(Exceptione) {

// Connection error, should retry later

e.printStackTrace();

}

returnfalse;

}

/**

* android——iOS——tag

*@paramtagValues标签tag 集合

*@paramtitle标题

*@paramsubTitle副标题仅iOS有效,没有传空字符串

*@paramcontent内容

*@paramextras自定义信息

*@return

*/

privatestaticPushPayload buildPushObject_android_iOS_tag(CollectiontagValues,

Stringtitle, StringsubTitle, Stringcontent,

Mapextras) {

returnPushPayload.newBuilder()

.setPlatform(Platform.android_ios())

.setAudience(Audience.tag(tagValues))

.setNotification(Notification.newBuilder()

.addPlatformNotification(AndroidNotification.newBuilder()

.setAlert(title)

.setTitle(title)

.addExtras(extras)

.build())

.addPlatformNotification(IosNotification.newBuilder()

.setAlert(IosAlert.newBuilder()

.setTitleAndBody(title,subTitle,content)

.build())

.setBadge(1)

.addExtras(extras)

.build())

.build())

.setMessage(Message.newBuilder()

.setTitle(title)

.setMsgContent(content)

.addExtras(extras)

.build())

.setOptions(Options.newBuilder()

.setApnsProduction(Constants.JPUSH_DEPLOY_STATUS)

.build())

.build();

}

/**

* android_iOS_alias

*@paramaliases 别名集合

*@paramtitle标题

*@paramsubTitle副标题仅iOS有效,没有传空字符串

*@paramcontent内容

*@paramextras自定义信息

*@return

*/

privatestaticPushPayload buildPushObject_android_iOS_alias(Collectionaliases,

Stringtitle, StringsubTitle, Stringcontent,

Mapextras) {

returnPushPayload.newBuilder()

.setPlatform(Platform.android_ios())

.setAudience(Audience.alias(aliases))

.setNotification(Notification.newBuilder()

.addPlatformNotification(AndroidNotification.newBuilder()

.setAlert(title)

.setTitle(title)

.addExtras(extras)

.build())

.addPlatformNotification(IosNotification.newBuilder()

.setAlert(IosAlert.newBuilder()

.setTitleAndBody(title,subTitle,content)

.build())

.setBadge(1)

.addExtras(extras)

.build())

.build())

.setMessage(Message.newBuilder()

.setTitle(title)

.setMsgContent(content)

.addExtras(extras)

.build())

.setOptions(Options.newBuilder()

.setApnsProduction(Constants.JPUSH_DEPLOY_STATUS)

.build())

.build();

}

/**

* 推送所有安卓设备

*@paramtitle标题

*@paramcontent内容

*@paramextras自定义信息

*@return

*/

privatestaticPushPayload buildPushObject_all_android(

Stringtitle, Stringcontent,

Mapextras) {

returnPushPayload.newBuilder()

.setPlatform(Platform.android())

.setAudience(Audience.all())

.setNotification(Notification.newBuilder()

.addPlatformNotification(AndroidNotification.newBuilder()

.setAlert(title)

.setTitle(title)

.addExtras(extras)

.build())

.build())

.setMessage(Message.newBuilder()

.setTitle(title)

.setMsgContent(content)

.addExtras(extras)

.build())

.build();

}

/**

* 推送所有iOS

*@paramtitle

*@paramsubTitle

*@paramcontent

*@paramextras

*@return

*/

privatestaticPushPayload buildPushObject_all_iOS(Stringtitle,

StringsubTitle, Stringcontent,

Mapextras) {

returnPushPayload.newBuilder()

.setPlatform(Platform.ios())

.setAudience(Audience.all())

.setNotification(Notification.newBuilder()

.addPlatformNotification(IosNotification.newBuilder()

.setAlert(IosAlert.newBuilder()

.setTitleAndBody(title,subTitle,content)

.build())

.setBadge(1)

.addExtras(extras)

.build())

.build())

.setMessage(Message.newBuilder()

.setTitle(title)

.setMsgContent(content)

.addExtras(extras)

.build())

.setOptions(Options.newBuilder()

.setApnsProduction(Constants.JPUSH_DEPLOY_STATUS)

.build())

.build();

}

privatestaticJPushClient getJPushClient() {

returnnewJPushClient(Constants.JPUSH_MASTER_SECRET,

Constants.JPUSH_APP_KEY,null, ClientConfig.getInstance());

}

}

你可能感兴趣的:(极光推送 java util)