1 private static final String MASTER_SECTET = ""; 2 //Portal上注册应用时生成的 appKey 3 private static final String APP_KEY = ""; 4 private static final long TIME_TO_LIVE_NOTICE = 1000; 5 public static String pushMsgWithAlias(int sendNo, String alias, String title,String msg, Map<String,Object> extra){ 6 // 指定某种设备发送,并且指定离线消息保存时间 7 JPushClient jpush = new JPushClient(MASTER_SECTET, APP_KEY, TIME_TO_LIVE_ORDER); 8 //是否启动ssl安全连接 9 jpush.setEnableSSL(true); 10 //发送带alias的通知 11 alias = splitVersionFlag(alias); 12 MessageResult msgResult = jpush.sendNotificationWithAlias(sendNo, alias, title, msg, 0, extra); 13 String message=""; 14 if (null != msgResult) { 15 if (msgResult.getErrcode() == ErrorCodeEnum.NOERROR.value() || msgResult.getErrcode() == ErrorCodeEnum.InvalidPush.value()) { 16 // System.out.println("发送成功, sendNo=" + msgResult.getSendno() + ";alias="+alias); 17 return msgResult.getErrmsg(); 18 } else { 19 System.out.println("发送失败, 错误代码=" + msgResult.getErrcode() + ", 错误消息=" + msgResult.getErrmsg() + ",sendNo=" + sendNo + ";alias="+alias); 20 message = "发送失败, 错误代码=" + msgResult.getErrcode() + ", 错误消息=" + msgResult.getErrmsg() + ",sendNo=" + sendNo + ";alias="+alias; 21 return message; 22 } 23 } else { 24 System.out.println("无法获取数据"); 25 message = "无法获取数据"; 26 return message; 27 } 28 } 29 public static void main(String[] args) { 30 Map<String,Object> extra = new LinkedHashMap<String,Object>(); 31 extra.put("aaa", 123); 32 extra.put("bbb", "N"); 33 pushMsg(1,"20_02","test","通知内容",extra); 34 }