|
@ -7,8 +7,9 @@ import org.json.JSONObject;
|
|
|
* Created by 卓 on 2017/1/13.
|
|
|
*/
|
|
|
public class ImUtill {
|
|
|
|
|
|
private static final String im_host = SystemConf.getInstance().getImListGet();
|
|
|
|
|
|
// private static String host = "http://192.168.131.107:3008";
|
|
|
/**
|
|
|
* 获取医生统计数据
|
|
|
* status reply 为空值是是该医生总咨询量
|
|
@ -17,18 +18,20 @@ public class ImUtill {
|
|
|
* @param status
|
|
|
* @param reply
|
|
|
* @return
|
|
|
*
|
|
|
*/
|
|
|
public static String getConsultData(String user, Integer status, Integer reply) {
|
|
|
String imAddr = SystemConf.getInstance().getImListGet() + "/api/v2/sessions/topics/count/reply";
|
|
|
// String imAddr = host + "/api/v2/sessions/topics/count/reply";
|
|
|
imAddr = imAddr + "?user=" + user;
|
|
|
if (status != null) {
|
|
|
imAddr += ("&status=" + status);
|
|
|
String imAddr = im_host + "api/v2/sessions/topics/count/reply";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("user", user);
|
|
|
if (status!=null) {
|
|
|
params.put("status", status);
|
|
|
|
|
|
}
|
|
|
if (reply != null) {
|
|
|
imAddr += ("&reply=" + reply);
|
|
|
if (reply!=null) {
|
|
|
params.put("reply", reply);
|
|
|
}
|
|
|
String response = HttpClientUtil.get(imAddr, "UTF-8");
|
|
|
String response = HttpClientUtil.postBody(imAddr, params);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
@ -45,19 +48,21 @@ public class ImUtill {
|
|
|
* @return
|
|
|
*/
|
|
|
public static String getConsultByStatus(String user, Integer status, Integer reply, int page, int pagesize) {
|
|
|
String imAddr = SystemConf.getInstance().getImListGet() + "/api/v2/sessions/topics";
|
|
|
// String imAddr = host + "/api/v2/sessions/topics";
|
|
|
imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
|
|
|
if (status != null) {
|
|
|
imAddr += ("&status=" + status);
|
|
|
String imAddr = im_host + "api/v2/sessions/topics";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("user", user);
|
|
|
params.put("page", page);
|
|
|
params.put("pagesize", pagesize);
|
|
|
if (status!=null) {
|
|
|
params.put("status", status);
|
|
|
}
|
|
|
if (reply != null) {
|
|
|
imAddr += ("&reply=" + reply);
|
|
|
if (reply!=null) {
|
|
|
params.put("reply", reply);
|
|
|
}
|
|
|
String response = HttpClientUtil.get(imAddr, "UTF-8");
|
|
|
String response = HttpClientUtil.postBody(imAddr, params);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
// ===============================
|
|
|
/**
|
|
|
* 发送消息给IM
|
|
|
*
|
|
@ -65,8 +70,8 @@ public class ImUtill {
|
|
|
* @param contentType 1文字 2图片消息
|
|
|
* @param content 内容
|
|
|
*/
|
|
|
public static String sendImMsg(String from, String fromName, String sessionId, String contentType, String content, String businessType) {
|
|
|
String imAddr = SystemConf.getInstance().getImListGet() + "/api/v2/sessions/" + sessionId + "/messages";
|
|
|
public static String sendImMsg(String from,String fromName, String sessionId, String contentType, String content,String businessType) {
|
|
|
String imAddr = im_host + "api/v2/sessions/"+sessionId+"/messages";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("sender_id", from);
|
|
|
params.put("sender_name", fromName);
|
|
@ -81,11 +86,11 @@ public class ImUtill {
|
|
|
/**
|
|
|
* 更新会话状态
|
|
|
*
|
|
|
* @param sessionId 会话ID
|
|
|
* @param status 状态
|
|
|
* @param sessionId 会话ID
|
|
|
* @param status 状态
|
|
|
*/
|
|
|
public static String updateSessionStatus(String sessionId, String status) {
|
|
|
String imAddr = SystemConf.getInstance().getImListGet() + "/api/v2/sessions/" + sessionId + "/status?status=" + status + "&sessionId=" + sessionId;
|
|
|
public static String updateSessionStatus(String sessionId,String status) {
|
|
|
String imAddr = im_host + "api/v2/sessions/"+sessionId+"/status?status="+status+"&sessionId="+sessionId;
|
|
|
JSONObject params = new JSONObject();
|
|
|
String response = HttpClientUtil.postBody(imAddr, params);
|
|
|
return response;
|
|
@ -99,16 +104,14 @@ public class ImUtill {
|
|
|
* @param contentType 1文字 2图片消息
|
|
|
* @param content 内容
|
|
|
*/
|
|
|
public static String sendTopicIM(String from, String fromName, String topicId, String contentType, String content) {
|
|
|
String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ ("api/v2/sessions/topic/" + topicId + "/messages");
|
|
|
public static String sendTopicIM(String from,String fromName, String topicId, String contentType, String content) {
|
|
|
String url = im_host + "api/v2/sessions/topic/"+topicId+"/messages";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("sender_id", from);
|
|
|
params.put("sender_name", fromName);
|
|
|
params.put("content_type", contentType);
|
|
|
params.put("content", content);
|
|
|
params.put("topic_id", topicId);
|
|
|
;
|
|
|
params.put("topic_id", topicId);;
|
|
|
String response = HttpClientUtil.postBody(url, params);
|
|
|
return response;
|
|
|
}
|
|
@ -116,23 +119,23 @@ public class ImUtill {
|
|
|
/**
|
|
|
* 结束议题
|
|
|
*
|
|
|
* @param topicId 议题ID
|
|
|
* @param endUser 结束人
|
|
|
* @param topicId 议题ID
|
|
|
* @param endUser 结束人
|
|
|
* @param endUserName 结束人名字
|
|
|
* @param sessionId 会话ID
|
|
|
* @param sessionId 会话ID
|
|
|
*/
|
|
|
public static JSONObject endTopics(String sessionId, String endUser, String endUserName, String topicId) {
|
|
|
String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions/" + sessionId + "/topics/" + topicId + "/ended";
|
|
|
public static JSONObject endTopics(String sessionId,String endUser, String endUserName,String topicId) {
|
|
|
String imAddr = im_host + "api/v2/sessions/"+sessionId+"/topics/"+topicId+"/ended";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("session_id", sessionId);
|
|
|
params.put("end_user", endUser);
|
|
|
params.put("end_user_name", endUserName);
|
|
|
params.put("end_user_name",endUserName);
|
|
|
params.put("topic_id", topicId);
|
|
|
String ret = HttpClientUtil.postBody(imAddr, params);
|
|
|
JSONObject obj = null;
|
|
|
try {
|
|
|
String ret = HttpClientUtil.postBody(imAddr,params);
|
|
|
JSONObject obj = null;
|
|
|
try{
|
|
|
obj = new JSONObject(ret);
|
|
|
} catch (Exception e) {
|
|
|
}catch (Exception e){
|
|
|
return null;
|
|
|
}
|
|
|
return obj;
|
|
@ -141,26 +144,25 @@ public class ImUtill {
|
|
|
|
|
|
/**
|
|
|
* 议题邀请人员
|
|
|
*
|
|
|
* @param user 结束人名字
|
|
|
* @param user 结束人名字
|
|
|
* @param sessionId 会话ID
|
|
|
*/
|
|
|
public static void updateTopicUser(String sessionId, String user) {
|
|
|
String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions/" + sessionId + "/participants/" + user;
|
|
|
public static void updateTopicUser(String sessionId,String user) {
|
|
|
String imAddr = im_host + "api/v2/sessions/"+sessionId+"/participants/"+user;
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("user", user + ":" + 0);
|
|
|
HttpClientUtil.putBody(imAddr, params);
|
|
|
params.put("user", user+":"+0);
|
|
|
HttpClientUtil.putBody(imAddr,params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 创建议题
|
|
|
*
|
|
|
* @param topicId 议题ID
|
|
|
* @param topicName 议题名称
|
|
|
* @param topicId 议题ID
|
|
|
* @param topicName 议题名称
|
|
|
* @param participants 成员
|
|
|
*/
|
|
|
public static JSONObject createTopics(String sessionId, String topicId, String topicName, JSONObject participants, JSONObject messages, String sessionType) {
|
|
|
String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions/" + topicId + "/topics";
|
|
|
String imAddr = im_host + "api/v2/sessions/"+topicId+"/topics";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("topic_id", topicId);
|
|
|
params.put("topic_name", topicName);
|
|
@ -168,11 +170,11 @@ public class ImUtill {
|
|
|
params.put("messages", messages.toString());
|
|
|
params.put("session_id", sessionId);
|
|
|
params.put("session_type", sessionType);
|
|
|
String ret = HttpClientUtil.postBody(imAddr, params);
|
|
|
JSONObject obj = null;
|
|
|
try {
|
|
|
String ret = HttpClientUtil.postBody(imAddr,params);
|
|
|
JSONObject obj = null;
|
|
|
try{
|
|
|
obj = new JSONObject(ret);
|
|
|
} catch (Exception e) {
|
|
|
}catch (Exception e){
|
|
|
return null;
|
|
|
}
|
|
|
return obj;
|
|
@ -180,19 +182,20 @@ public class ImUtill {
|
|
|
|
|
|
/**
|
|
|
* 创建会话(system)
|
|
|
*
|
|
|
*/
|
|
|
public static JSONObject createSession(JSONObject participants, String sessionType, String sessionName, String sessionId) {
|
|
|
String imAddr = SystemConf.getInstance().getImListGet() + "api/v2/sessions";
|
|
|
public static JSONObject createSession(JSONObject participants,String sessionType,String sessionName,String sessionId) {
|
|
|
String imAddr = im_host + "api/v2/sessions";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("participants", participants.toString());
|
|
|
params.put("session_name", sessionName);
|
|
|
params.put("session_type", sessionType);
|
|
|
params.put("session_id", sessionId);
|
|
|
String ret = HttpClientUtil.postBody(imAddr, params);
|
|
|
JSONObject obj = null;
|
|
|
try {
|
|
|
String ret = HttpClientUtil.postBody(imAddr,params);
|
|
|
JSONObject obj = null;
|
|
|
try{
|
|
|
obj = new JSONObject(ret);
|
|
|
} catch (Exception e) {
|
|
|
}catch (Exception e){
|
|
|
return null;
|
|
|
}
|
|
|
return obj;
|
|
@ -200,7 +203,6 @@ public class ImUtill {
|
|
|
|
|
|
/**
|
|
|
* 获取会话实例的消息对象
|
|
|
*
|
|
|
* @param senderId
|
|
|
* @param senderName
|
|
|
* @param title
|
|
@ -208,138 +210,128 @@ public class ImUtill {
|
|
|
* @param images
|
|
|
* @return
|
|
|
*/
|
|
|
public static JSONObject getCreateTopicMessage(String senderId, String senderName, String title, String description, String images) {
|
|
|
public static JSONObject getCreateTopicMessage(String senderId,String senderName,String title,String description,String images){
|
|
|
JSONObject messages = new JSONObject();
|
|
|
messages.put("description", description);
|
|
|
messages.put("title", title);
|
|
|
messages.put("img", images);
|
|
|
messages.put("sender_id", senderId);
|
|
|
messages.put("sender_name", senderName);
|
|
|
messages.put("description",description);
|
|
|
messages.put("title",title);
|
|
|
messages.put("img",images);
|
|
|
messages.put("sender_id",senderId);
|
|
|
messages.put("sender_name",senderName);
|
|
|
return messages;
|
|
|
}
|
|
|
|
|
|
public static JSONObject getTopicMessage(String topicId, String startMsgId, String endMsgId, int page, int pagesize, String uid) {
|
|
|
String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ "api/v2/sessions/topic/" + topicId + "/messages?topic_id=" + topicId + "&end=" + startMsgId
|
|
|
+ "&start=" + (endMsgId == null ? "" : endMsgId) + "&page=" + page + "&pagesize=" + pagesize + "&user=" + uid;
|
|
|
try {
|
|
|
public static JSONObject getTopicMessage(String topicId,String startMsgId,String endMsgId,int page,int pagesize,String uid){
|
|
|
String url = im_host
|
|
|
+ "api/v2/sessions/topic/"+topicId+"/messages?topic_id="+topicId+"&end="+startMsgId
|
|
|
+"&start="+(endMsgId==null?"":endMsgId)+"&page="+page+"&pagesize="+pagesize+"&user="+uid;
|
|
|
try{
|
|
|
String ret = HttpClientUtil.get(url, "UTF-8");
|
|
|
JSONObject obj = new JSONObject(ret);
|
|
|
if (obj.getInt("status") == -1) {
|
|
|
if(obj.getInt("status")==-1){
|
|
|
throw new RuntimeException(obj.getString("message"));
|
|
|
} else {
|
|
|
return obj.getJSONObject("data");
|
|
|
}else{
|
|
|
return obj.getJSONObject("data");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
}catch (Exception e){
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static JSONArray getSessionMessage(String sessionId, String startMsgId, String endMsgId, int page, int pagesize, String uid) {
|
|
|
String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ "api/v2/sessions/" + sessionId + "/messages?session_id=" + sessionId + "&user=" + uid + "&start_message_id=" + startMsgId + "&end_message_id=" + endMsgId + "&page=" + page + "&pagesize=" + pagesize;
|
|
|
try {
|
|
|
public static JSONArray getSessionMessage(String sessionId,String startMsgId,String endMsgId,int page,int pagesize,String uid){
|
|
|
String url = im_host+ "api/v2/sessions/"+sessionId+"/messages?session_id="+sessionId+"&user="+uid+"&start_message_id="+startMsgId+"&end_message_id="+endMsgId+"&page="+page+"&pagesize="+pagesize;
|
|
|
try{
|
|
|
String ret = HttpClientUtil.get(url, "UTF-8");
|
|
|
JSONArray obj = new JSONArray(ret);
|
|
|
return obj;
|
|
|
} catch (Exception e) {
|
|
|
}catch (Exception e){
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除对应的成员信息在MUC模式中
|
|
|
*
|
|
|
* @param userId
|
|
|
* @param oldUserId
|
|
|
* @param sessionId
|
|
|
* @return
|
|
|
*/
|
|
|
public static JSONObject deleteMucUser(String userId, String oldUserId, String sessionId) throws Exception {
|
|
|
String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ "api/v2/sessions/" + sessionId + "/participant/update";
|
|
|
try {
|
|
|
public static JSONObject deleteMucUser(String userId,String oldUserId,String sessionId) throws Exception{
|
|
|
String url = im_host+ "api/v2/sessions/"+sessionId+"/participant/update";
|
|
|
try{
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("user_id", userId);
|
|
|
params.put("old_user_id", oldUserId);
|
|
|
params.put("session_id", sessionId);
|
|
|
String ret = HttpClientUtil.postBody(url, params);
|
|
|
String ret = HttpClientUtil.postBody(url,params);
|
|
|
JSONObject obj = new JSONObject(ret);
|
|
|
if (obj.getInt("status") == -1) {
|
|
|
if(obj.getInt("status")==-1){
|
|
|
throw new RuntimeException("人员更换失败!");
|
|
|
} else {
|
|
|
}else{
|
|
|
return obj;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException("人员更换失败!");
|
|
|
}catch (Exception e){
|
|
|
throw new RuntimeException("人员更换失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取议题
|
|
|
*
|
|
|
* @param topicId
|
|
|
* @return
|
|
|
*/
|
|
|
public static JSONObject getTopic(String topicId) throws Exception {
|
|
|
String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ "api/v2/sessions/topics/" + topicId + "?topic_id=" + topicId;
|
|
|
try {
|
|
|
String ret = HttpClientUtil.get(url, "utf-8");
|
|
|
public static JSONObject getTopic(String topicId) throws Exception{
|
|
|
String url = im_host + "api/v2/sessions/topics/"+topicId+"?topic_id="+topicId;
|
|
|
try{
|
|
|
String ret = HttpClientUtil.get(url,"utf-8");
|
|
|
JSONObject obj = new JSONObject(ret);
|
|
|
if (obj.getInt("status") == -1) {
|
|
|
if(obj.getInt("status")==-1){
|
|
|
throw new RuntimeException("获取议题失败!");
|
|
|
} else {
|
|
|
}else{
|
|
|
return obj;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
}catch (Exception e){
|
|
|
throw new RuntimeException("获取议题失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取会话成员
|
|
|
*
|
|
|
* @param sessionId
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public static JSONArray getParticipants(String sessionId) {
|
|
|
String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ "api/v2/sessions/" + sessionId + "/participants?session_id=" + sessionId;
|
|
|
try {
|
|
|
String ret = HttpClientUtil.get(url, "utf-8");
|
|
|
public static JSONArray getParticipants(String sessionId){
|
|
|
String url = im_host + "api/v2/sessions/"+sessionId+"/participants?session_id="+sessionId;
|
|
|
try{
|
|
|
String ret = HttpClientUtil.get(url,"utf-8");
|
|
|
return new JSONArray(ret);
|
|
|
} catch (Exception e) {
|
|
|
}catch (Exception e){
|
|
|
throw new RuntimeException("获取议题失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取会话成员
|
|
|
*
|
|
|
* @param sessionId
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public static JSONArray getSessions(String sessionId) {
|
|
|
String url = SystemConf.getInstance().getSystemProperties().getProperty("im_list_get")
|
|
|
+ "api/v2/sessions/" + sessionId + "/participants?session_id=" + sessionId;
|
|
|
try {
|
|
|
String ret = HttpClientUtil.get(url, "utf-8");
|
|
|
public static JSONArray getSessions(String sessionId){
|
|
|
String url = im_host+ "api/v2/sessions/"+sessionId+"/participants?session_id="+sessionId;
|
|
|
try{
|
|
|
String ret = HttpClientUtil.get(url,"utf-8");
|
|
|
return new JSONArray(ret);
|
|
|
} catch (Exception e) {
|
|
|
}catch (Exception e){
|
|
|
throw new RuntimeException("获取议题失败!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static final String SESSION_TYPE_MUC = "1";
|
|
|
public static final String SESSION_TYPE_P2P = "2";
|
|
|
public static final String SESSION_TYPE_GROUP = "3";
|
|
|
public static final String SESSION_TYPE_SYSTEM = "0";
|
|
|
public static final String SESSION_STATUS_PROCEEDINGS = "0";
|
|
|
public static final String SESSION_STATUS_END = "1";
|
|
|
public static final String SESSION_TYPE_MUC = "1";
|
|
|
public static final String SESSION_TYPE_P2P = "2";
|
|
|
public static final String SESSION_TYPE_GROUP = "3";
|
|
|
public static final String SESSION_TYPE_SYSTEM = "0";
|
|
|
public static final String SESSION_STATUS_PROCEEDINGS= "0";
|
|
|
public static final String SESSION_STATUS_END= "1";
|
|
|
}
|