@Test
  public void push() {
    JPushClient jpushClient = new JPushClient(MASTERT_SECRET, APPKEY, 3);

    // For push, all you need do is to build PushPayload object.
    PushPayload payload = buildPushObject_all_all_alert("Test"); // Android And Ios Push

    try {
      PushResult result = jpushClient.sendPush(payload);
      System.out.println("Got result - " + result);
      //			LOG.info("Got result - " + result);

    } catch (APIConnectionException e) {
      // Connection error, should retry later
      System.out.println("Connection error, should retry later" + e);
      //			LOG.error("Connection error, should retry later", e);

    } catch (APIRequestException e) {
      // Should review the error, and fix the request
      System.out.println("Should review the error, and fix the request" + e);
      System.out.println("HTTP Status: " + e.getStatus());
      System.out.println("Error Code: " + e.getErrorCode());
      System.out.println("Error Message: " + e.getErrorMessage());
      //			LOG.error("Should review the error, and fix the request", e);
      //			LOG.info("HTTP Status: " + e.getStatus());
      //			LOG.info("Error Code: " + e.getErrorCode());
      //			LOG.info("Error Message: " + e.getErrorMessage());
    }
  }
Exemplo n.º 2
0
  public static void push(String alert) {
    JPushClient jpushClient =
        new JPushClient(Constants.JPUSH_MASTER_SECRET, Constants.JPUSH_APP_KEY, 3);
    // For push, all you need do is to build PushPayload object.
    PushPayload payload = buildPushObject_android_tag_alertWithTitle(alert);

    try {
      PushResult result = jpushClient.sendPush(payload);
      LOG.info("Got result - " + result);

    } catch (APIConnectionException e) {
      // Connection error, should retry later
      LOG.error("Connection error, should retry later", e);

    } catch (APIRequestException e) {
      // Should review the error, and fix the request
      LOG.error("Should review the error, and fix the request", e);
      LOG.info("HTTP Status: " + e.getStatus());
      LOG.info("Error Code: " + e.getErrorCode());
      LOG.info("Error Message: " + e.getErrorMessage());
    }
  }
Exemplo n.º 3
0
  public boolean pushAndroid(String msg, String devId, Map<String, String> extra) {
    // HttpProxy proxy = new HttpProxy("localhost", 3128);
    // Can use this https proxy: https://github.com/Exa-Networks/exaproxy
    PushPayload payload = buildAndroidPayload(msg, devId, extra);
    //		PushPayload payload = buildPushObject_all_all_alert(msg);

    try {
      PushResult result = jpushClient.sendPush(payload);
      LOG.info("Got result - " + result);

    } catch (APIConnectionException e) {
      LOG.error("Connection error. Should retry later. ", e);
      return false;

    } catch (APIRequestException e) {
      LOG.error("Error response from JPush server. Should review and fix it. ", e);
      LOG.info("HTTP Status: " + e.getStatus());
      LOG.info("Error Code: " + e.getErrorCode());
      LOG.info("Error Message: " + e.getErrorMessage());
      LOG.info("Msg ID: " + e.getMsgId());
      return false;
    }
    return true;
  }