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
“查询对话”接口接口链接
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条件,参数是什么这里写的比较简单没有明确指出,可以从总览中找到
“M”用来存用户字段,即查固定用户的信息where条件加上
JSONObject jsonObject = JSONObject.parseObject("{" +
"\"m\":[\"1237809\",\"1543889\"]}");