|
@ -2,11 +2,18 @@ package com.yihu.hos.device.common.util;
|
|
|
|
|
|
import com.yihu.hos.device.common.http.HttpClientUtil;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
/**
|
|
|
* Created by 卓 on 2017/1/13.
|
|
|
*/
|
|
|
@Component
|
|
|
public class ImUtill {
|
|
|
|
|
|
@Autowired
|
|
|
private HttpClientUtil HttpClientUtil;
|
|
|
|
|
|
/**
|
|
|
* 发送消息给IM
|
|
|
*
|
|
@ -14,7 +21,7 @@ public class ImUtill {
|
|
|
* @param contentType 1文字 2图片消息
|
|
|
* @param content 内容
|
|
|
*/
|
|
|
public static String sendImMsg(String baseUrl,String from,String fromName, String sessionId, String contentType, String content,String businessType) {
|
|
|
public String sendImMsg(String baseUrl,String from,String fromName, String sessionId, String contentType, String content,String businessType) {
|
|
|
String imAddr = baseUrl + "/api/v2/sessions/"+sessionId+"/messages";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("sender_id", from);
|
|
@ -35,7 +42,7 @@ public class ImUtill {
|
|
|
* @param contentType 1文字 2图片消息
|
|
|
* @param content 内容
|
|
|
*/
|
|
|
public static String sendTopicIM(String baseUrl,String from,String fromName, String topicId, String contentType, String content) {
|
|
|
public String sendTopicIM(String baseUrl,String from,String fromName, String topicId, String contentType, String content) {
|
|
|
String url = baseUrl+ ("api/v2/sessions/topic/"+topicId+"/messages");
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("sender_id", from);
|
|
@ -55,7 +62,7 @@ public class ImUtill {
|
|
|
* @param endUserName 结束人名字
|
|
|
* @param sessionId 会话ID
|
|
|
*/
|
|
|
public static JSONObject endTopics(String baseUrl,String sessionId,String endUser, String endUserName,String topicId) {
|
|
|
public JSONObject endTopics(String baseUrl,String sessionId,String endUser, String endUserName,String topicId) {
|
|
|
String imAddr = baseUrl + "api/v2/sessions/"+sessionId+"/topics/"+topicId+"/ended";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("session_id", sessionId);
|
|
@ -78,7 +85,7 @@ public class ImUtill {
|
|
|
* @param user 结束人名字
|
|
|
* @param sessionId 会话ID
|
|
|
*/
|
|
|
public static void updateTopicUser(String baseUrl,String sessionId,String user) {
|
|
|
public void updateTopicUser(String baseUrl,String sessionId,String user) {
|
|
|
String imAddr = baseUrl + "api/v2/sessions/"+sessionId+"/participants/"+user;
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("user", user+":"+0);
|
|
@ -92,7 +99,7 @@ public class ImUtill {
|
|
|
* @param topicName 议题名称
|
|
|
* @param participants 成员
|
|
|
*/
|
|
|
public static JSONObject createTopics(String baseUrl,String sessionId, String topicId, String topicName, JSONObject participants, JSONObject messages, String sessionType) {
|
|
|
public JSONObject createTopics(String baseUrl,String sessionId, String topicId, String topicName, JSONObject participants, JSONObject messages, String sessionType) {
|
|
|
String imAddr = baseUrl + "api/v2/sessions/"+topicId+"/topics";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("topic_id", topicId);
|
|
@ -115,7 +122,7 @@ public class ImUtill {
|
|
|
* 创建会话(system)
|
|
|
*
|
|
|
*/
|
|
|
public static JSONObject createSession(String baseUrl,JSONObject participants,String sessionType,String sessionName,String sessionId) {
|
|
|
public JSONObject createSession(String baseUrl,JSONObject participants,String sessionType,String sessionName,String sessionId) {
|
|
|
String imAddr = baseUrl + "api/v2/sessions";
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("participants", participants.toString());
|
|
@ -141,7 +148,7 @@ public class ImUtill {
|
|
|
* @param images
|
|
|
* @return
|
|
|
*/
|
|
|
public static JSONObject getCreateTopicMessage(String senderId,String senderName,String title,String description,String images){
|
|
|
public JSONObject getCreateTopicMessage(String senderId,String senderName,String title,String description,String images){
|
|
|
JSONObject messages = new JSONObject();
|
|
|
messages.put("description",description);
|
|
|
messages.put("title",title);
|
|
@ -151,7 +158,7 @@ public class ImUtill {
|
|
|
return messages;
|
|
|
}
|
|
|
|
|
|
public static JSONObject getTopicMessage(String baseUrl,String topicId,String startMsgId,String endMsgId,int page,int pagesize,String uid){
|
|
|
public JSONObject getTopicMessage(String baseUrl,String topicId,String startMsgId,String endMsgId,int page,int pagesize,String uid){
|
|
|
String url = baseUrl
|
|
|
+ "api/v2/sessions/topic/"+topicId+"/messages?topic_id="+topicId+"&end="+startMsgId
|
|
|
+"&start="+(endMsgId==null?"":endMsgId)+"&page="+page+"&pagesize="+pagesize+"&user="+uid;
|
|
@ -176,7 +183,7 @@ public class ImUtill {
|
|
|
* @param sessionId
|
|
|
* @return
|
|
|
*/
|
|
|
public static JSONObject deleteMucUser(String baseUrl,String userId,String oldUserId,String sessionId) throws Exception{
|
|
|
public JSONObject deleteMucUser(String baseUrl,String userId,String oldUserId,String sessionId) throws Exception{
|
|
|
String url = baseUrl
|
|
|
+ "api/v2/sessions/"+sessionId+"/participant/update";
|
|
|
try{
|
|
@ -202,7 +209,7 @@ public class ImUtill {
|
|
|
* @param topicId
|
|
|
* @return
|
|
|
*/
|
|
|
public static JSONObject getTopic(String baseUrl,String topicId) throws Exception{
|
|
|
public JSONObject getTopic(String baseUrl,String topicId) throws Exception{
|
|
|
String url =baseUrl
|
|
|
+ "api/v2/sessions/topics/"+topicId+"?topic_id="+topicId;
|
|
|
try{
|