コード例 #1
0
 /**
  * 构建推送对象:所有平台,推送目标是别名为 "alias1",通知内容为 ALERT。
  *
  * @return
  */
 private static PushPayload buildPushObject_all_alias_alert(String title, String message) {
   return PushPayload.newBuilder()
       .setPlatform(Platform.all())
       .setAudience(Audience.alias(title))
       .setNotification(Notification.alert(message))
       .build();
 }
コード例 #2
0
 /**
  * The shortcut of building a simple alert notification object to all platforms and all audiences
  */
 public static PushPayload alertAll(String alert) {
   return new Builder()
       .setPlatform(Platform.all())
       .setAudience(Audience.all())
       .setNotification(Notification.alert(alert))
       .build();
 }
コード例 #3
0
  @Test
  public void lackOfParams_audience() {
    JsonObject payload = new JsonObject();
    payload.add("platform", Platform.all().toJSON());
    payload.add("notification", Notification.alert(ALERT).toJSON());
    System.out.println("json string: " + payload.toString());

    try {
      _client.sendPush(payload.toString());
    } catch (APIConnectionException e) {
      e.printStackTrace();
    } catch (APIRequestException e) {
      assertEquals(LACK_OF_PARAMS, e.getErrorCode());
    }
  }
コード例 #4
0
  @Test
  public void invalidParams_platform() {
    JsonObject payload = new JsonObject();
    payload.add("platform", new JsonPrimitive("all_platform"));
    payload.add("audience", Audience.all().toJSON());
    payload.add("notification", Notification.alert(ALERT).toJSON());
    System.out.println("json string: " + payload.toString());

    try {
      _client.sendPush(payload.toString());
    } catch (APIConnectionException e) {
      e.printStackTrace();
    } catch (APIRequestException e) {
      assertEquals(INVALID_PARAMS, e.getErrorCode());
    }
  }
コード例 #5
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;
   }
 }