コード例 #1
0
  /** 发送jpush到客户端 */
  @Override
  public boolean sendByRegisitrationID(
      String msg, Map<String, String> extras, Integer imsi, String... regisitrationIDs) {

    String extrasJson = new Gson().toJson(extras);
    // extrasJson = extrasJson.replaceAll("\"", "'");
    PushPayload payload = null;
    if (imsi == IMSI_ANDROID) {
      payload =
          PushPayload.newBuilder()
              .setPlatform(Platform.all())
              .setAudience(Audience.registrationId(regisitrationIDs))
              .setMessage(
                  Message.newBuilder().setMsgContent(msg).addExtra("data", extrasJson).build())
              .build();
    }
    //		else if(imsi==IMSI_IOS){
    //			 payload = PushPayload.newBuilder()
    //					.setPlatform(Platform.all())
    //					.setAudience(Audience.registrationId(regisitrationIDs))
    //					.setNotification(Notification.ios(msg, extras)) //alert(msg)
    //					.build();
    //		}
    else { // 默认按iphone处理
      payload =
          PushPayload.newBuilder()
              .setPlatform(Platform.all())
              .setAudience(Audience.registrationId(regisitrationIDs))
              .setNotification(Notification.ios(msg, extras)) // alert(msg)
              .build();
    }

    //		PushPayload payload = PushPayload
    //				.newBuilder()
    //				.setPlatform(Platform.all())
    //				.setAudience(Audience.registrationId(regisitrationIDs))
    //				.setMessage(
    //						Message.newBuilder().setMsgContent(msg)
    //								.addExtra("data",  extrasJson).build()).build();

    //
    //		PushPayload payload = PushPayload.newBuilder()
    //				.setPlatform(Platform.all())
    //				.setAudience(Audience.registrationId(regisitrationIDs))
    //				.setNotification(Notification.ios(msg, extras)) //alert(msg)
    //				.setMessage(
    //						Message.newBuilder().setMsgContent(msg)
    //								.addExtra("data",  extrasJson).build())
    //				.build();
    try {
      PushResult result = jpushClient.sendPush(payload);
      return result.isResultOK();
    } catch (Exception e1) {
      errorLogger.writeErrorLog(e1.getMessage());
      appLogger.error(e1.getMessage(), e1);
      debugLogger.error(e1.getMessage(), e1);
      return false;
    }
  }
コード例 #2
0
  /** 发送jpush到工作端口 */
  @Override
  public boolean sendByRegisitrationIDToWorker(
      String msg, Map<String, String> extras, String... regisitrationIDs) {

    // PushPayload payload = PushPayload.newBuilder()
    // .setPlatform(Platform.all())
    // .setAudience(Audience.registrationId(regisitrationIDs))
    // .setNotification(Notification.newBuilder()
    // .addPlatformNotification(AndroidNotification.newBuilder()
    // .addExtra("orderID", orderID)
    // .build())
    // .build())
    // .setMessage(Message.content(msg))
    // .build();

    String extrasJson = new Gson().toJson(extras);
    // extrasJson = extrasJson.replaceAll("\"", "'");

    PushPayload payload =
        PushPayload.newBuilder()
            .setPlatform(Platform.all())
            .setAudience(Audience.registrationId(regisitrationIDs))
            // .setNotification(Notification.ios(msg, extras)) //alert(msg)
            .setMessage(
                Message.newBuilder().setMsgContent(msg).addExtra("data", extrasJson).build())
            .build();

    // PushPayload payload = PushPayload.newBuilder()
    // .setPlatform(Platform.all())
    // .setAudience(Audience.registrationId(regisitrationIDs))
    // .setNotification( Notification.android(msg, msg, extras)
    // //.ios(msg, extras)
    // Notification.alert("")
    // ).build();

    try {
      PushResult result = jpushClientForService.sendPush(payload);
      return result.isResultOK();
    } catch (Exception e1) {
      errorLogger.writeErrorLog(e1.getMessage());
      appLogger.error(e1.getMessage(), e1);
      debugLogger.error(e1.getMessage(), e1);
      return false;
    }
  }
コード例 #3
0
 @Override
 public boolean sendAll(String msg) {
   PushPayload payload =
       PushPayload.newBuilder()
           .setPlatform(Platform.all())
           .setAudience(Audience.all())
           .setNotification(Notification.alert(msg))
           .build();
   try {
     PushResult result = jpushClient.sendPush(payload);
     return result.isResultOK();
   } catch (Exception e1) {
     errorLogger.writeErrorLog(e1.getMessage());
     appLogger.error(e1.getMessage(), e1);
     debugLogger.error(e1.getMessage(), e1);
     return false;
   }
 }