Пример #1
0
  /** 在群组中减少一个人 */
  public static ObjectNode deleteUserFromGroup(String chatgroupid, String userName) {
    ObjectNode objectNode = factory.objectNode();
    // check appKey format
    if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", APPKEY)) {
      LOGGER.error("Bad format of Appkey: " + APPKEY);
      objectNode.put("message", "Bad format of Appkey");
      return objectNode;
    }

    try {
      URL allMemberssByGroupIdUrl =
          HTTPClientUtils.getURL(
              Constants.APPKEY.replace("#", "/")
                  + "/chatgroups/"
                  + chatgroupid
                  + "/users/"
                  + userName);
      objectNode =
          HTTPClientUtils.sendHTTPRequest(
              allMemberssByGroupIdUrl, credential, null, HTTPMethod.METHOD_DELETE);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return objectNode;
  }
Пример #2
0
  /**
   * 获取一个用户参与的所有群组
   *
   * @param username
   * @return
   */
  private static ObjectNode getJoinedChatgroupsForIMUser(String username) {
    ObjectNode objectNode = factory.objectNode();
    // check appKey format
    if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", APPKEY)) {
      LOGGER.error("Bad format of Appkey: " + APPKEY);
      objectNode.put("message", "Bad format of Appkey");
      return objectNode;
    }
    if (StringUtils.isBlank(username.trim())) {
      LOGGER.error("Property that named username must be provided .");
      objectNode.put("message", "Property that named username must be provided .");
      return objectNode;
    }

    try {
      URL getJoinedChatgroupsForIMUserUrl =
          HTTPClientUtils.getURL(
              Constants.APPKEY.replace("#", "/") + "/users/" + username + "/joined_chatgroups");
      objectNode =
          HTTPClientUtils.sendHTTPRequest(
              getJoinedChatgroupsForIMUserUrl, credential, null, HTTPMethod.METHOD_GET);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return objectNode;
  }
Пример #3
0
  /**
   * 获取一个或者多个群组的详情
   *
   * @return
   */
  public static ObjectNode getGroupDetailsByChatgroupid(String[] chatgroupIDs) {
    ObjectNode objectNode = factory.objectNode();
    // check appKey format
    if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", APPKEY)) {
      LOGGER.error("Bad format of Appkey: " + APPKEY);
      objectNode.put("message", "Bad format of Appkey");
      return objectNode;
    }

    try {
      URL groupDetailsByChatgroupidUrl =
          HTTPClientUtils.getURL(
              Constants.APPKEY.replace("#", "/") + "/chatgroups/" + chatgroupIDs.toString());
      objectNode =
          HTTPClientUtils.sendHTTPRequest(
              groupDetailsByChatgroupidUrl, credential, null, HTTPMethod.METHOD_GET);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return objectNode;
  }
Пример #4
0
  /**
   * 群组批量添加成员
   *
   * @param toAddBacthChatgroupid
   * @param usernames
   * @return
   */
  private static ObjectNode addUsersToGroupBatch(
      String toAddBacthChatgroupid, ObjectNode usernames) {
    ObjectNode objectNode = factory.objectNode();
    // check appKey format
    if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", APPKEY)) {
      LOGGER.error("Bad format of Appkey: " + APPKEY);
      objectNode.put("message", "Bad format of Appkey");
      return objectNode;
    }
    if (StringUtils.isBlank(toAddBacthChatgroupid.trim())) {
      LOGGER.error("Property that named toAddBacthChatgroupid must be provided .");
      objectNode.put("message", "Property that named toAddBacthChatgroupid must be provided .");
      return objectNode;
    }
    // check properties that must be provided
    if (null != usernames && !usernames.has("usernames")) {
      LOGGER.error("Property that named usernames must be provided .");
      objectNode.put("message", "Property that named usernames must be provided .");
      return objectNode;
    }

    try {
      URL getJoinedChatgroupsForIMUserUrl =
          HTTPClientUtils.getURL(
              Constants.APPKEY.replace("#", "/")
                  + "/chatgroups/"
                  + toAddBacthChatgroupid
                  + "/users");
      objectNode =
          HTTPClientUtils.sendHTTPRequest(
              getJoinedChatgroupsForIMUserUrl, credential, usernames, HTTPMethod.METHOD_POST);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return objectNode;
  }