123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- package com.yihu.wlyy.util;
- import org.json.JSONArray;
- import org.json.JSONObject;
- /**
- * Created by 卓 on 2017/1/13.
- */
- public class ImUtill {
- /**
- * 发送消息给IM
- *
- * @param from 来自
- * @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";
- 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;
- }
- /**
- * 发送消息给IM
- *
- * @param from 来自
- * @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");
- 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);;
- String response = HttpClientUtil.postBody(url, params);
- return response;
- }
- /**
- * 结束议题
- *
- * @param topicId 议题ID
- * @param endUser 结束人
- * @param endUserName 结束人名字
- * @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";
- 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 static void updateTopicUser(String sessionId,String user) {
- String imAddr = SystemConf.getInstance().getImListGet() + "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 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";
- 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;
- }
- /**
- * 创建会话(system)
- *
- */
- public static JSONObject createSession(JSONObject participants,String sessionType,String sessionName,String sessionId) {
- String imAddr = SystemConf.getInstance().getImListGet() + "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
- * @return
- */
- 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);
- 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{
- 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;
- }
- }
- }
|