package com.zteits.pay.util; import cn.jiguang.common.ClientConfig; import cn.jiguang.common.resp.APIConnectionException; 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.Platform; import cn.jpush.api.push.model.PushPayload; import cn.jpush.api.push.model.audience.Audience; import cn.jpush.api.push.model.notification.Notification; import com.zteits.pay.configuration.JPushInspectConfigure; import com.zteits.pay.configuration.JPushPDAConfigure; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class JPushForInspectUtil { private static final Logger log = LoggerFactory.getLogger(JPushForInspectUtil.class); private static JPushClient pdaJpushClient = new JPushClient(JPushInspectConfigure.getMASTER_SECRET(), JPushInspectConfigure.getAPP_KEY(), null,ClientConfig.getInstance()); /** * 巡查单个android用户推送消息 * @param title * @param msgContent * @param alias * @return * 2017年11月28日 zhaowg */ public static PushResult inspectSendPush(String title, String msgContent,String... alias) { PushResult result = new PushResult(); try { PushPayload payload = sendAndroidMessageWithAlias(title,msgContent,null,alias); result = pdaJpushClient.sendPush(payload); } catch (Exception e) { e.printStackTrace(); log.debug(" 单个用户推送消息 失败:"+e); } return result; } public static PushPayload buildPushObject_all_alias_alert(String msgContent,String alias) { return PushPayload.newBuilder() .setPlatform(Platform.all()) .setAudience(Audience.alias(alias)) .setNotification(Notification.alert(msgContent)) .build(); } public static PushPayload sendAndroidMessageWithAlias(String title, String msgContent, String contentType,String... alias) throws APIConnectionException, APIRequestException { return PushPayload.newBuilder() .setPlatform(Platform.android()) .setAudience(Audience.alias(alias)) .setMessage(Message.newBuilder() .setTitle(title) .setMsgContent(msgContent) .setContentType(contentType) .build()) .build(); } public static PushPayload sendIosMessageWithAlias(String title, String msgContent, String contentType,String... alias) throws APIConnectionException, APIRequestException { return PushPayload.newBuilder() .setPlatform(Platform.ios()) .setAudience(Audience.alias(alias)) .setMessage(Message.newBuilder() .setTitle(title) .setMsgContent(msgContent) .setContentType(contentType) .build()) .build(); } /*public static void main(String[] args) { PDAMsgPushDTO msgPushDTO = new PDAMsgPushDTO<>(); InspectMsgPushDTO inOutParkMsgPushDTO = new InspectMsgPushDTO(); inOutParkMsgPushDTO.setMsg("到点了,签退吧"); msgPushDTO.setContent(inOutParkMsgPushDTO); msgPushDTO.setMsgType(PDAMsgTypeEnum.SIGN_OUT_ALERT.name()); PushResult result = new PushResult(); try { PushPayload payload = sendAndroidMessageWithAlias("", JSON.toJSONString(msgPushDTO),null,"18261520692"); JPushClient pdaJpushClient = new JPushClient("11350a6a38cfaf518c1beafe", "b7aabe15e95547f3fb1815ca", null, ClientConfig.getInstance()); result = pdaJpushClient.sendPush(payload); System.out.println(result); } catch (Exception e) { e.printStackTrace(); log.debug(" 单个用户推送消息 失败:"+e); } }*/ }