|  | @ -0,0 +1,574 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.util;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import org.json.JSONArray;
 | 
	
		
			
				|  |  | import org.json.JSONObject;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Component;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created by 卓 on 2017/1/13.
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @Component
 | 
	
		
			
				|  |  | public class ImUtill {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private HttpClientUtil HttpClientUtil;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Value("${im.im_list_get}")
 | 
	
		
			
				|  |  |     private String im_host;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public enum ContentType {
 | 
	
		
			
				|  |  |         plainText("信息", "1"),
 | 
	
		
			
				|  |  |         image("图片信息", "2"),
 | 
	
		
			
				|  |  |         audio("创建处方", "3"),
 | 
	
		
			
				|  |  |         article("文章信息", "4"),
 | 
	
		
			
				|  |  |         goTo("跳转信息,求组其他医生或者邀请其他医生发送的推送消息", "5"),
 | 
	
		
			
				|  |  |         topicBegin("议题开始", "6"),
 | 
	
		
			
				|  |  |         topicEnd("议题结束", "7"),
 | 
	
		
			
				|  |  |         personalCard("个人名片", "18"),
 | 
	
		
			
				|  |  |         messageForward("消息转发", "19"),
 | 
	
		
			
				|  |  |         topicInto("进入议题", "14"),
 | 
	
		
			
				|  |  |         video("视频", "12"),
 | 
	
		
			
				|  |  |         system("系统消息", "13"),
 | 
	
		
			
				|  |  |         prescriptionCheck("续方审核消息消息", "15"),
 | 
	
		
			
				|  |  |         prescriptionBloodStatus("续方咨询血糖血压咨询消息", "16"),
 | 
	
		
			
				|  |  |         prescriptionFollowupContent("续方咨询随访问卷消息", "17"),
 | 
	
		
			
				|  |  |         Rehabilitation("康复计划发送","20");
 | 
	
		
			
				|  |  |         private String name;
 | 
	
		
			
				|  |  |         private String value;
 | 
	
		
			
				|  |  |         ContentType(String name, String value) {
 | 
	
		
			
				|  |  |             this.name = name;
 | 
	
		
			
				|  |  |             this.value = value;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         public String getName() {
 | 
	
		
			
				|  |  |             return name;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         public void setName(String name) {
 | 
	
		
			
				|  |  |             this.name = name;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         public String getValue() {
 | 
	
		
			
				|  |  |             return value;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         public void setValue(String value) {
 | 
	
		
			
				|  |  |             this.value = value;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 发送消息
 | 
	
		
			
				|  |  |      * @param senderId 发送者的code
 | 
	
		
			
				|  |  |      * @param receiverId 接受者code
 | 
	
		
			
				|  |  |      * @param contentType 消息类型 1二维码内容
 | 
	
		
			
				|  |  |      * @param content 消息内容
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String sendMessage(String senderId,String receiverId,String contentType,String content){
 | 
	
		
			
				|  |  |         String imAddr = im_host + "api/v2/message/send";
 | 
	
		
			
				|  |  |         JSONObject params = new JSONObject();
 | 
	
		
			
				|  |  |         params.put("sender_id", senderId);
 | 
	
		
			
				|  |  |         params.put("sender_name", receiverId);
 | 
	
		
			
				|  |  |         params.put("content_type", contentType);
 | 
	
		
			
				|  |  |         params.put("content", content);
 | 
	
		
			
				|  |  |         String response = HttpClientUtil.postBody(imAddr, params);
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取医生统计数据
 | 
	
		
			
				|  |  |      * status reply 为空值是是该医生总咨询量
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param user          团队就把团队的医生合并起来用,隔开(医生编码)
 | 
	
		
			
				|  |  |      * @param adminTeamCode
 | 
	
		
			
				|  |  |      * @param status
 | 
	
		
			
				|  |  |      * @param reply
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String getConsultData(String user, Integer adminTeamCode, Integer status, Integer reply) {
 | 
	
		
			
				|  |  |         String imAddr = im_host + "api/v2/sessions/topics/count/reply";
 | 
	
		
			
				|  |  |         imAddr = imAddr + "?user=" + user;
 | 
	
		
			
				|  |  |         if (status != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&status=" + status);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (adminTeamCode != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&adminTeamCode=" + adminTeamCode);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (reply != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&reply=" + reply);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String response = HttpClientUtil.get(imAddr, "UTF-8");
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void updateTopics(String topicId, String jsonValue) {
 | 
	
		
			
				|  |  |         String imAddr = im_host + "api/v2/sessions/" + topicId + "/topics";
 | 
	
		
			
				|  |  |         JSONObject params = new JSONObject();
 | 
	
		
			
				|  |  |         params.put("topic_id", topicId);
 | 
	
		
			
				|  |  |         params.put("data", jsonValue);
 | 
	
		
			
				|  |  |         HttpClientUtil.putBody(imAddr, params);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 当前医生下当前团队列表接口
 | 
	
		
			
				|  |  |      * 获取团队内医生的健康咨询状况
 | 
	
		
			
				|  |  |      * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param user          团队就把团队的医生合并起来用,隔开(医生编码)
 | 
	
		
			
				|  |  |      * @param adminTeamCode 行政团队code
 | 
	
		
			
				|  |  |      * @param page
 | 
	
		
			
				|  |  |      * @param pagesize
 | 
	
		
			
				|  |  |      * @param status
 | 
	
		
			
				|  |  |      * @param reply
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String getTeamConsultByStatus(String user, Integer adminTeamCode, Integer status, Integer reply, int page, int pagesize) {
 | 
	
		
			
				|  |  |         String imAddr = im_host + "api/v2/sessions/healthTeamTopics";
 | 
	
		
			
				|  |  |         imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
 | 
	
		
			
				|  |  |         if (adminTeamCode != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&adminTeamCode=" + adminTeamCode);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (status != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&status=" + status);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (reply != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&reply=" + reply);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String response = HttpClientUtil.get(imAddr, "UTF-8");
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 列表接口
 | 
	
		
			
				|  |  |      * 获取团队内医生的健康咨询状况
 | 
	
		
			
				|  |  |      * status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param user     团队就把团队的医生合并起来用,隔开(医生编码)
 | 
	
		
			
				|  |  |      * @param page
 | 
	
		
			
				|  |  |      * @param pagesize
 | 
	
		
			
				|  |  |      * @param status
 | 
	
		
			
				|  |  |      * @param reply
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String getConsultByStatus(String user, Integer status, Integer reply, int page, int pagesize) {
 | 
	
		
			
				|  |  |         String imAddr = im_host + "api/v2/sessions/healthTopics";
 | 
	
		
			
				|  |  |         imAddr = imAddr + "?user=" + user + "&page=" + page + "&pagesize=" + pagesize;
 | 
	
		
			
				|  |  |         if (status != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&status=" + status);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (reply != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&reply=" + reply);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String response = HttpClientUtil.get(imAddr, "UTF-8");
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 咨询列表
 | 
	
		
			
				|  |  |      * @param user
 | 
	
		
			
				|  |  |      * @param status status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
 | 
	
		
			
				|  |  |      * @param reply
 | 
	
		
			
				|  |  |      * @param type 1、三师咨询,2、家庭医生咨询,6、患者名医咨询 7医生名医咨询 8续方咨询 10医生发起的求助
 | 
	
		
			
				|  |  |      * @param page
 | 
	
		
			
				|  |  |      * @param pagesize
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String getConsultByStatusAndType(String user,Integer status,Integer reply,Integer type,String patientName,String startTime,String endTime,int page,int pagesize){
 | 
	
		
			
				|  |  |         String imAddr = im_host + "api/v2/sessions/topicListByType";
 | 
	
		
			
				|  |  |         imAddr = imAddr + "?user="+user + "&page=" + page + "&pagesize=" + pagesize;
 | 
	
		
			
				|  |  |         if (status != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&status=" + status);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (reply != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&reply=" + reply);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (type != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&type=" + type);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (patientName != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&patientName=" + patientName);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (startTime != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&startTime=" + startTime);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (endTime != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&endTime=" + endTime);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String response = HttpClientUtil.get(imAddr, "UTF-8");
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 咨询列表总数
 | 
	
		
			
				|  |  |      * @param user
 | 
	
		
			
				|  |  |      * @param status status = 10 已结束的咨询,status=0,reply = 1 已回复 ,status=0,reply=0未回复
 | 
	
		
			
				|  |  |      * @param reply
 | 
	
		
			
				|  |  |      * @param type 1、三师咨询,2、家庭医生咨询,6、患者名医咨询 7医生名医咨询 8续方咨询 10医生发起的求助
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String getConsultCountByStatusAndType(String user,Integer status,Integer reply,Integer type,String patientName,String startTime,String endTime){
 | 
	
		
			
				|  |  |         String imAddr = im_host + "api/v2/sessions/topicListCountByType";
 | 
	
		
			
				|  |  |         imAddr = imAddr + "?user="+user;
 | 
	
		
			
				|  |  |         if (status != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&status=" + status);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (reply != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&reply=" + reply);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (type != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&type=" + type);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (patientName != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&patientName=" + patientName);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (startTime != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&startTime=" + startTime);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         if (endTime != null) {
 | 
	
		
			
				|  |  |             imAddr += ("&endTime=" + endTime);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         String response = HttpClientUtil.get(imAddr, "UTF-8");
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 发送消息给IM
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param from        来自
 | 
	
		
			
				|  |  |      * @param contentType 1文字 2图片消息
 | 
	
		
			
				|  |  |      * @param content     内容
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public 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);
 | 
	
		
			
				|  |  |         params.put("content_type", contentType);
 | 
	
		
			
				|  |  |         params.put("content", content);
 | 
	
		
			
				|  |  |         params.put("session_id", sessionId);
 | 
	
		
			
				|  |  |         params.put("business_type", businessType);
 | 
	
		
			
				|  |  |         String response = HttpClientUtil.postBody(imAddr, params);
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 更新会话状态
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param sessionId 会话ID
 | 
	
		
			
				|  |  |      * @param status    状态
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public 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;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 更新会话状态
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param sessionId 会话ID
 | 
	
		
			
				|  |  |      * @param status    状态
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String updateTopicEvaluate(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;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 发送消息给IM
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param from        来自
 | 
	
		
			
				|  |  |      * @param contentType 1文字 2图片消息
 | 
	
		
			
				|  |  |      * @param content     内容
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String sendTopicIM(String from, String fromName, String topicId, String contentType, String content, String agent) {
 | 
	
		
			
				|  |  |         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("agent", agent);
 | 
	
		
			
				|  |  |         String response = HttpClientUtil.postBody(url, params);
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 发送进入im消息
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param from
 | 
	
		
			
				|  |  |      * @param sessionId
 | 
	
		
			
				|  |  |      * @param topicId
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String sendIntoTopicIM(String from, String sessionId, String topicId, String content, String intoUser, String intoUserName) {
 | 
	
		
			
				|  |  |         String url = im_host + "api/v2/sessions/" + sessionId + "/topics/" + topicId + "/into";
 | 
	
		
			
				|  |  |         JSONObject params = new JSONObject();
 | 
	
		
			
				|  |  |         params.put("sender_id", from);
 | 
	
		
			
				|  |  |         params.put("topic_id", topicId);
 | 
	
		
			
				|  |  |         params.put("into_user", intoUser);
 | 
	
		
			
				|  |  |         params.put("into_user_name", intoUserName);
 | 
	
		
			
				|  |  |         params.put("content", content);
 | 
	
		
			
				|  |  |         String response = HttpClientUtil.postBody(url, params);
 | 
	
		
			
				|  |  |         return response;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 结束议题
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param topicId     议题ID
 | 
	
		
			
				|  |  |      * @param endUser     结束人
 | 
	
		
			
				|  |  |      * @param endUserName 结束人名字
 | 
	
		
			
				|  |  |      * @param sessionId   会话ID
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public 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("topic_id", topicId);
 | 
	
		
			
				|  |  |         String ret = HttpClientUtil.postBody(imAddr, params);
 | 
	
		
			
				|  |  |         JSONObject obj = null;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             obj = new JSONObject(ret);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return obj;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 议题邀请人员
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param user      结束人名字
 | 
	
		
			
				|  |  |      * @param sessionId 会话ID
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public 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);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 创建议题
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param topicId      议题ID
 | 
	
		
			
				|  |  |      * @param topicName    议题名称
 | 
	
		
			
				|  |  |      * @param participants 成员
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject createTopics(String sessionId, String topicId, String topicName, JSONObject participants, JSONObject messages, String sessionType) {
 | 
	
		
			
				|  |  |         String imAddr = im_host + "api/v2/sessions/" + topicId + "/topics";
 | 
	
		
			
				|  |  |         JSONObject params = new JSONObject();
 | 
	
		
			
				|  |  |         params.put("topic_id", topicId);
 | 
	
		
			
				|  |  |         params.put("topic_name", topicName);
 | 
	
		
			
				|  |  |         params.put("participants", participants.toString());
 | 
	
		
			
				|  |  |         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 {
 | 
	
		
			
				|  |  |             obj = new JSONObject(ret);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return obj;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 判断会话是否存在
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Boolean sessionIsExist(String sessionId) {
 | 
	
		
			
				|  |  |         Boolean re = false;
 | 
	
		
			
				|  |  |         String url = im_host + "api/v2/sessions/isExist?session_id="+sessionId;
 | 
	
		
			
				|  |  |         JSONObject params = new JSONObject();
 | 
	
		
			
				|  |  |         String ret = HttpClientUtil.get(url, "UTF-8");
 | 
	
		
			
				|  |  |         JSONObject obj = null;
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             obj = new JSONObject(ret);
 | 
	
		
			
				|  |  |             if(obj.getInt("status")==200&&sessionId.equals(obj.getString("sessionId"))){
 | 
	
		
			
				|  |  |                 re = true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return re;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 创建会话(system)
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public 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 {
 | 
	
		
			
				|  |  |             obj = new JSONObject(ret);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return obj;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取会话实例的消息对象
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param senderId
 | 
	
		
			
				|  |  |      * @param senderName
 | 
	
		
			
				|  |  |      * @param title
 | 
	
		
			
				|  |  |      * @param description
 | 
	
		
			
				|  |  |      * @param images
 | 
	
		
			
				|  |  |      * @param agent
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject getCreateTopicMessage(String senderId, String senderName, String title, String description, String images, String agent) {
 | 
	
		
			
				|  |  |         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("agent", agent);
 | 
	
		
			
				|  |  |         return messages;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public 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) {
 | 
	
		
			
				|  |  |                 throw new RuntimeException(obj.getString("message"));
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 return obj.getJSONObject("data");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public 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) {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 删除对应的成员信息在MUC模式中
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param userId
 | 
	
		
			
				|  |  |      * @param oldUserId
 | 
	
		
			
				|  |  |      * @param sessionId
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public 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);
 | 
	
		
			
				|  |  |             JSONObject obj = new JSONObject(ret);
 | 
	
		
			
				|  |  |             if (obj.getInt("status") == -1) {
 | 
	
		
			
				|  |  |                 throw new RuntimeException("人员更换失败!");
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 return obj;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             throw new RuntimeException("人员更换失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取议题
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param topicId
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public 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) {
 | 
	
		
			
				|  |  |                 throw new RuntimeException("获取议题失败!");
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 return obj;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             throw new RuntimeException("获取议题失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取会话成员
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param sessionId
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public 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) {
 | 
	
		
			
				|  |  |             throw new RuntimeException("获取议题失败!");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取会话成员
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param sessionId
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public 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) {
 | 
	
		
			
				|  |  |             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_TYPE_PRESCRIPTION = "8";//续方
 | 
	
		
			
				|  |  |     public static final String SESSION_STATUS_PROCEEDINGS = "0";
 | 
	
		
			
				|  |  |     public static final String SESSION_STATUS_END = "1";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public static final String CONTENT_TYPE_TEXT = "1";
 | 
	
		
			
				|  |  | }
 |