leancloud 查询两个用户的信息记录

1.官网可查“查询历史信息”接口 链接
leancloud 查询两个用户的信息记录_第1张图片
参数:
leancloud 查询两个用户的信息记录_第2张图片
测试代码:

public static void main(String[] args) throws Exception {
  String appId = "NiDeAPPid-BaLaBaLa";
  String s = "https://" + StringUtils.substring(appId, 0, 8) + ".api.lncld.net";
  String path = String.format("/1.2/rtm/conversations/%s/messages", "5a0025c15b90c830ff7a6f14");

  Map<String, String> header1;
  header1 = new HashMap<>(5);
  header1.put("X-LC-Id", appId);
  header1.put("X-LC-Key", "NiDeAppKey-BaLaBaLa" + ",master");
  header1.put("Content-Type", "application/json");
[添加链接描述](https://leancloud.cn/docs/realtime_v2.html#hash24460545)
  Map<String, String> params = new HashMap(1);
  params.put("reversed", "true"); 

  try {
    HttpResponse response = HttpUtils.doGet(s, path, header1, params);
    String str = HttpClientUtil.fmt2String(response, "utf-8");
    System.out.print(str);
  } catch (ServiceException e) {
    throw e;
  }
}

这个接口需要一个对话ID,对话的概念见官网 服务总览
两个人对话产生一个对话ID。

2.根据两用户ID查到对话ID
“查询对话”接口接口链接

leancloud 查询两个用户的信息记录_第3张图片

public static void main(String[] args) throws Exception {
  String appId = "NiDeAPPid-BaLaBaLa";
  String s = "https://" + StringUtils.substring(appId, 0, 8) + ".api.lncld.net";
  String path1 = "/1.2/rtm/conversations";

  Map<String, String> header1;
  header1 = new HashMap<>(5);
  header1.put("X-LC-Id", appId);
  header1.put("X-LC-Key", "NiDeAppKey-BaLaBaLa" + ",master");
  header1.put("Content-Type", "application/json");

  Map<String, String> params = new HashMap(1);
  JSONObject jsonObject = JSONObject.parseObject("{" +
    "\"m\":[\"1237809\",\"1543889\"]}");
  params.put("where", jsonObject.toJSONString());

  try {
    HttpResponse response = HttpUtils.doGet(s, path, header1, params);
    String str = HttpClientUtil.fmt2String(response, "utf-8");
    System.out.print(str);
  } catch (ServiceException e) {
    throw e;
  }
}

要查已知用户间对话ID,需要where条件,参数是什么这里写的比较简单没有明确指出,可以从总览中找到
leancloud 查询两个用户的信息记录_第4张图片
“M”用来存用户字段,即查固定用户的信息where条件加上

JSONObject jsonObject = JSONObject.parseObject("{" +
    "\"m\":[\"1237809\",\"1543889\"]}");

json格式。
leancloud 查询两个用户的信息记录_第5张图片
结果如上,坐等前端兄弟展示。

你可能感兴趣的:(*【应用】)