package org.jeecg.common.util; import java.util.ArrayList; import cn.jiguang.common.resp.APIConnectionException; /** private final static String MASTERSECRET = “********”; private static JPushClient jPushClient = new JPushClient(MASTERSECRET, APPKEY); } 注:以上内容仅提供参考和交流,请勿用于商业用途,如有侵权联系本人删除!
<dependency> <groupId>cn.jpush.api</groupId> <artifactId>jpush-client</artifactId> <version>3.3.10</version> </dependency> <dependency> <groupId>cn.jpush.api</groupId> <artifactId>jiguang-common</artifactId> <version>1.1.4</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.6.Final</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.3</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.7</version> </dependency> <!-- For log4j --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.7</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>
import java.util.List;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;
import cn.jpush.api.schedule.ScheduleResult;
import lombok.extern.slf4j.Slf4j;
*
* @ClassName: JpushUtil
* @Description: 极光推送工具类
* @author WangJing
* @date 2020年6月12日
*
*/
@Slf4j
public class JpushUtil {
private final static String APPKEY = “********”;
/**
* 发送给标识用户
* @param alias 设备标识
* @param notificationTitle 通知内容标题
* @param msgTitle 消息内容标题
* @param msgContent 消息内容
* @param extrasparam 扩展字段(传跳转的链接)
* @param uuid 日志记录标识
* @return false推送失败,true推送成功
*/
public static Boolean sendToAlias(List<String> alias, String notificationTitle, String msgTitle, String msgContent,
String extrasparam, String uuid) {
Boolean result = false;
try {
PushPayload pushPayload = buildPushObject(alias, notificationTitle, msgTitle, msgContent, extrasparam);
log.info(“uuid:{}, JpushUtil–sendToAlias–jpush–participation:{} “, uuid,
pushPayload.toJSON().toString());
PushResult sendPush = jPushClient.sendPush(pushPayload);
if (sendPush.getResponseCode() == 200) {
result = true;
}
log.info(“uuid:{}, JpushUtil–sendToAlias–jpush–outParameter:{} “, uuid, sendPush.toString());
} catch (APIConnectionException | APIRequestException e) {
log.error(“uuid:{}, JpushUtil–sendToAlias–error:{} “, uuid, e);
}
return result;
}
/**
* 定时发送给标识用户
* @param alias 设备标识
* @param notificationTitle 通知内容标题
* @param msgTitle 消息内容标题
* @param msgContent 消息内容
* @param extrasparam 扩展字段(传跳转的链接)
* @param scheduleName 日程名称
* @param scheduleTime 日程时间(格式:yyyy-MM-dd HH:mm:ss)
* @param uuid 日志记录标识
* @return false推送失败,true推送成功
*/
public static Boolean sendToAliasTiming(List<String> alias, String notificationTitle, String msgTitle,
String msgContent, String extrasparam, String scheduleName, String scheduleTime, String uuid) {
Boolean result = false;
try {
PushPayload pushPayload = buildPushObject(alias, notificationTitle, msgTitle, msgContent, extrasparam);
log.info(“uuid:{}, JpushUtil–sendToAliasTiming–jpush–participation:{} “, uuid,
pushPayload.toJSON().toString());
ScheduleResult createSingleSchedule = jPushClient.createSingleSchedule(scheduleName, scheduleTime,
pushPayload);
if (createSingleSchedule.getResponseCode() == 200) {
result = true;
}
log.info(“uuid:{}, JpushUtil–sendToAliasTiming–jpush–outParameter:{} “, uuid,
createSingleSchedule.toString());
} catch (APIConnectionException | APIRequestException e) {
log.error(“uuid:{}, JpushUtil–sendToAliasTiming–error:{} “, uuid, e);
}
return result;
}
/**
* 发送给所有安卓用户
* @param notificationTitle 通知内容标题
* @param msgTitle 消息内容标题
* @param msgContent 消息内容
* @param extrasparam 扩展字段(传跳转的链接)
* @param uuid 日志记录标识
* @return false推送失败,true推送成功
*/
public static Boolean sendToAndroid(String notificationTitle, String msgTitle, String msgContent,
String extrasparam, String uuid) {
Boolean result = false;
try {
PushPayload pushPayload = buildPushObjectByAndroid(notificationTitle, msgTitle, msgContent, extrasparam);
log.info(“uuid:{}, JpushUtil–sendToAndroid–jpush–participation:{} “, uuid,
pushPayload.toJSON().toString());
PushResult sendPush = jPushClient.sendPush(pushPayload);
if (sendPush.getResponseCode() == 200) {
result = true;
}
log.info(“uuid:{}, JpushUtil–sendToAndroid–jpush–outParameter:{} “, uuid, sendPush.toString());
} catch (APIConnectionException | APIRequestException e) {
log.error(“uuid:{}, JpushUtil–sendToAndroid–error:{} “, uuid, e);
}
return result;
}
/**
* 发送给所有IOS用户
* @param notificationTitle 通知内容标题
* @param msgTitle 消息内容标题
* @param msgContent 消息内容
* @param extrasparam 扩展字段(传跳转的链接)
* @param uuid 日志记录标识
* @return false推送失败,true推送成功
*/
public static Boolean sendToIos(String notificationTitle, String msgTitle, String msgContent, String extrasparam,
String uuid) {
Boolean result = false;
try {
PushPayload pushPayload = buildPushObjectByIos(notificationTitle, msgTitle, msgContent, extrasparam);
log.info(“uuid:{}, JpushUtil–sendToIos–jpush–participation:{} “, uuid, pushPayload.toJSON().toString());
PushResult sendPush = jPushClient.sendPush(pushPayload);
if (sendPush.getResponseCode() == 200) {
result = true;
}
log.info(“uuid:{}, JpushUtil–sendToIos–jpush–outParameter:{} “, uuid, sendPush.toString());
} catch (APIConnectionException | APIRequestException e) {
log.error(“uuid:{}, JpushUtil–sendToIos–error:{} “, uuid, e);
}
return result;
}
/**
* 发送给所有用户
* @param notificationTitle 通知内容标题
* @param msgTitle 消息内容标题
* @param msgContent 消息内容
* @param extrasparam 扩展字段(传跳转的链接)
* @param uuid 日志记录标识
* @return false推送失败,true推送成功
*/
public static int sendToAll(String notificationTitle, String msgTitle, String msgContent, String extrasparam,
String uuid) {
int result = 0;
try {
PushPayload pushPayload = buildPushObjectByAll(notificationTitle, msgTitle, msgContent, extrasparam);
log.info(“uuid:{}, JpushUtil–sendToAll–jpush–participation:{} “, uuid, pushPayload.toJSON().toString());
PushResult sendPush = jPushClient.sendPush(pushPayload);
if (sendPush.getResponseCode() == 200) {
result = 1;
}
log.info(“uuid:{}, JpushUtil–sendToAll–jpush–outParameter:{} “, uuid, sendPush.toString());
} catch (APIConnectionException | APIRequestException e) {
log.error(“uuid:{}, JpushUtil–sendToAll–error:{} “, uuid, e);
}
return result;
}
/**
* 定时发送给所有用户
* @param notificationTitle 通知内容标题
* @param msgTitle 消息内容标题
* @param msgContent 消息内容
* @param extrasparam 扩展字段(传跳转的链接)
* @param scheduleName 日程名称
* @param scheduleTime 日程时间(格式:yyyy-MM-dd HH:mm:ss)
* @param uuid 日志记录标识
* @return false推送失败,true推送成功
*/
public static Boolean sendToAllTiming(String notificationTitle, String msgTitle, String msgContent,
String extrasparam, String scheduleName, String scheduleTime, String uuid) {
Boolean result = false;
try {
PushPayload pushPayload = buildPushObjectByAll(notificationTitle, msgTitle, msgContent, extrasparam);
log.info(“uuid:{}, JpushUtil–sendToAllTiming–jpush–participation:{} “, uuid,
pushPayload.toJSON().toString());
ScheduleResult createSingleSchedule = jPushClient.createSingleSchedule(scheduleName, scheduleTime,
pushPayload);
if (createSingleSchedule.getResponseCode() == 200) {
result = true;
}
log.info(“uuid:{}, JpushUtil–sendToAllTiming–jpush–outParameter:{} “, uuid,
createSingleSchedule.toString());
} catch (APIConnectionException | APIRequestException e) {
log.error(“uuid:{}, JpushUtil–sendToAllTiming–error:{} “, uuid, e);
}
return result;
}
/**
* 组合发送对象(所有用户)
* @param notificationTitle 通知内容标题
* @param msgTitle 消息内容标题
* @param msgContent 消息内容
* @param extrasparam 扩展字段(传跳转的链接)
* @return
*/
public static PushPayload buildPushObjectByAll(String notificationTitle, String msgTitle, String msgContent,
String extrasparam) {
return PushPayload.newBuilder().setPlatform(Platform.android_ios()).setAudience(Audience.all())
.setNotification(Notification.newBuilder().setAlert(msgContent)
.addPlatformNotification(AndroidNotification.newBuilder().setAlert(msgContent)
.setTitle(notificationTitle).addExtra(“url”, extrasparam).build())
.addPlatformNotification(IosNotification.newBuilder().setAlert(msgContent).incrBadge(1)
.setSound(“sound.caf”).addExtra(“url”, extrasparam).build())
.build())
.setMessage(Message.newBuilder().setMsgContent(msgContent).setTitle(msgTitle)
.addExtra(“url”, extrasparam).build())
.setOptions(Options.newBuilder().setApnsProduction(true).setSendno(1).setTimeToLive(86400).build())
.build();
}
/**
* 组合发送对象(标识用户)
* @param alias 用户标识
* @param notificationTitle 通知内容标题
* @param msgTitle 消息内容标题
* @param msgContent 消息内容
* @param extrasparam 扩展字段(传跳转的链接)
* @return
*/
private static PushPayload buildPushObject(List<String> alias, String notificationTitle, String msgTitle,
String msgContent, String extrasparam) {
return PushPayload.newBuilder().setPlatform(Platform.all()).setAudience(Audience.alias(alias))
.setNotification(Notification.newBuilder()
.addPlatformNotification(AndroidNotification.newBuilder().setAlert(msgContent)
.setTitle(notificationTitle).addExtra(“url”, extrasparam).build())
.addPlatformNotification(IosNotification.newBuilder().setAlert(msgContent).incrBadge(1)
.setSound(“sound.caf”).addExtra(“url”, extrasparam).build())
.build())
.setMessage(Message.newBuilder().setMsgContent(msgContent).setTitle(msgTitle)
.addExtra(“url”, extrasparam).build())
.setOptions(Options.newBuilder().setApnsProduction(true).setSendno(1).setTimeToLive(86400).build())
.build();
/**
* 组合发送对象(Android用户)
* @param notificationTitle 通知内容标题
* @param msgTitle 消息内容标题
* @param msgContent 消息内容
* @param extrasparam 扩展字段(传跳转的链接)
* @return
*/
private static PushPayload buildPushObjectByAndroid(String notificationTitle, String msgTitle, String msgContent,
String extrasparam) {
return PushPayload.newBuilder().setPlatform(Platform.android()).setAudience(Audience.all())
.setNotification(Notification.newBuilder()
.addPlatformNotification(AndroidNotification.newBuilder().setAlert(msgContent)
.setTitle(notificationTitle).addExtra(“url”, extrasparam).build())
.build())
.setMessage(Message.newBuilder().setMsgContent(msgContent).setTitle(msgTitle)
.addExtra(“url”, extrasparam).build())
.setOptions(Options.newBuilder().setApnsProduction(true).setSendno(1).setTimeToLive(86400).build())
.build();
}
/**
* 组合发送对象(ios用户)
* @param notificationTitle 通知内容标题
* @param msgTitle 消息内容标题
* @param msgContent 消息内容
* @param extrasparam 扩展字段(传跳转的链接)
* @return
*/
private static PushPayload buildPushObjectByIos(String notificationTitle, String msgTitle, String msgContent,
String extrasparam) {
return PushPayload.newBuilder().setPlatform(Platform.ios()).setAudience(Audience.all())
.setNotification(Notification.newBuilder()
.addPlatformNotification(IosNotification.newBuilder().setAlert(msgContent).incrBadge(1)
.setSound(“sound.caf”).addExtra(“url”, extrasparam).build())
.build())
.setMessage(Message.newBuilder().setMsgContent(msgContent).setTitle(msgTitle)
.addExtra(“url”, extrasparam).build())
.setOptions(Options.newBuilder().setApnsProduction(true).setSendno(1).setTimeToLive(86400).build())
.build();
}
}
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算