kk 2 månader sedan
förälder
incheckning
d0da980859

+ 19 - 0
game-business/pom.xml

@@ -27,6 +27,25 @@
             <groupId>com.game</groupId>
             <artifactId>game-common</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>com.wengying666</groupId>
+            <artifactId>IMSocket</artifactId>
+            <version>2.5.6</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.13</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpmime</artifactId>
+            <version>4.5.13</version>
+        </dependency>
+
         <dependency>
             <groupId>io.springfox</groupId>
             <artifactId>springfox-core</artifactId>

+ 461 - 0
game-business/src/main/java/com/game/business/util/im/ChatMsgUtil.java

@@ -0,0 +1,461 @@
+package com.game.business.util.im;
+
+import cn.hutool.core.date.BetweenFormatter;
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.imsocket.util.ApiResult;
+import org.springframework.imsocket.util.ImGroupInfo;
+import org.springframework.imsocket.util.ImGroupUser;
+import org.springframework.imsocket.util.SocketUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 发送消息的工具
+ *
+ * @author jiang
+ */
+public class ChatMsgUtil {
+    private static Logger logger = LoggerFactory.getLogger(ChatMsgUtil.class);
+
+    /**
+     * 使用腾讯im
+     */
+    public static boolean use_tencent_Im = false;
+
+    public static final int SYSTEM_MSG_USER_ID = 111;
+
+    /**
+     * 创建群组
+     *
+     * @param groupId      群组id
+     * @param ownerId      群组拥有者
+     * @param isQuietGroup 是否是静默群组
+     * @param familyName 家族名称
+     * @author jiang
+     * @description
+     * @date 2021/8/5 10:40
+     */
+    public static void createGroup(long groupId, long ownerId, boolean isQuietGroup, String familyName) {
+        ImGroupUser imGroupUser = new ImGroupUser();
+        imGroupUser.userId = ownerId;
+
+        List<ImGroupUser> imGroupUserList = new ArrayList<>();
+        imGroupUserList.add(imGroupUser);
+
+        ImGroupInfo imGroupInfo = new ImGroupInfo();
+        imGroupInfo.groupId = groupId;
+        imGroupInfo.ownerId = ownerId;
+        imGroupInfo.m_groupUser = imGroupUserList;
+        imGroupInfo.isQuietGroup = isQuietGroup;
+
+        if(use_tencent_Im){
+            resultParsing(TencentCloudImUtil.createGroup(TencentCloudImConstant.GROUP_CHAT_TYPE_COMMUNITY, String.valueOf(ownerId), String.valueOf(groupId), familyName));
+        }else {
+            resultParsing(SocketUtil.createGroup(imGroupInfo));
+        }
+    }
+
+    /**
+     * 更换群组的拥有者
+     *
+     * @param groupId 群组id
+     * @param ownerId 拥有这id
+     */
+    public static void changeGroupOwner(long groupId, long ownerId) {
+        resultParsing(SocketUtil.changeGroupOwner(groupId, ownerId));
+    }
+
+    /**
+     * 删除群组
+     *
+     * @param groupId 群组id
+     * @author jiang
+     * @description
+     * @date 2021/8/5 10:48
+     */
+    public static void delGroup(long groupId) {
+        resultParsing(SocketUtil.delGroup(groupId));
+    }
+
+    /**
+     * 用户添加到群组
+     *
+     * @param groupId 群组id
+     * @param userId  用户id
+     * @author jiang
+     * @description
+     * @date 2021/8/5 10:47
+     */
+    public static void addUserToGroup(long groupId, long userId) {
+        resultParsing(SocketUtil.addUserToGroup(groupId, userId));
+    }
+
+    /**
+     * 将用户删除群组
+     *
+     * @param groupId 群组id
+     * @param userId  用户id
+     * @author jiang
+     * @description
+     * @date 2021/8/5 10:51
+     */
+    public static void removeUserFromGroup(long groupId, long userId) {
+        resultParsing(SocketUtil.removeUserFromGroup(groupId, userId));
+    }
+
+    /**
+     * 结果转换
+     *
+     * @param apiResult 接口返回的实体
+     * @return null 表示成功 非null则为失败的消息
+     * @author jiang
+     * @description
+     * @date 2021/8/5 10:46
+     */
+    private static void resultParsing(ApiResult apiResult) {
+        logger.info(" ----------- 群组操作结果:{} ----------- ", apiResult.errMsg);
+    }
+
+
+    /**
+     * 发送群聊系统通知
+     *
+     * @param groupId    群组id
+     * @param msgType    消息类型
+     * @param msgContent 消息内容
+     * @author jiang
+     * @description
+     * @date 2021/8/5 14:00
+     */
+    public static void sendMsgToGroup(long groupId, int msgType, String msgContent) {
+        if(use_tencent_Im){
+            TencentCloudImUtil.sendGroupSystemNotification(String.valueOf(groupId), msgContent);
+        }else {
+            JSONObject msg = new JSONObject();
+            msg.put("eventText", msgContent);
+
+            JSONObject paramJson = new JSONObject();
+            paramJson.put("messageType", msgType);
+            paramJson.put("messageContent", msg);
+
+            SocketUtil.sendMsgToGroup(SYSTEM_MSG_USER_ID, groupId, paramJson, false);
+        }
+    }
+
+
+    /**
+     * 发送群聊系统通知
+     *
+     * @param groupId    群组id
+     * @param msgType    消息类型
+     * @param msgContent 消息内容
+     * @param isPlazaMsg 是否是广场消息
+     * @author jiang
+     * @description
+     * @date 2021/8/5 14:00
+     */
+    public static void sendMsgToGroup(long groupId, int msgType, String msgContent, boolean isPlazaMsg) {
+
+        JSONObject msg = new JSONObject();
+        msg.put("eventText", msgContent);
+
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("messageType", msgType);
+        paramJson.put("messageContent", msg);
+
+        SocketUtil.sendMsgToGroup(SYSTEM_MSG_USER_ID, groupId, paramJson, false, isPlazaMsg, isPlazaMsg);
+    }
+
+    /**
+     * 发送群聊系统通知
+     * isInstantMsg(缓存时间为10分钟)
+     *
+     * @param groupId    群组id
+     * @param msgType    消息类型
+     * @param extrJson   消息体内容
+     * @param isPlazaMsg 是否是广场消息
+     * @author jiang
+     * @date 2021/8/9 10:35
+     */
+    public static void sendMsgToGroup(long groupId, int msgType, JSONObject extrJson, boolean isPlazaMsg) {
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("messageType", msgType);
+        paramJson.put("messageContent", extrJson);
+
+        SocketUtil.sendMsgToGroup(SYSTEM_MSG_USER_ID, groupId, paramJson, false, isPlazaMsg, isPlazaMsg);
+    }
+
+    /**
+     * 发送群聊系统通知,发送给群聊某一个人
+     *
+     * @param groupId    群组id
+     * @param userId     用户id
+     * @param msgType    消息类型
+     * @param msgContent 消息内容
+     * @author jiang
+     * @date 2021/8/24 15:16
+     */
+    public static void sendMsgToGroupUser(long groupId, long userId, int msgType, String msgContent) {
+        JSONObject extrJson = new JSONObject();
+        extrJson.put("eventText", msgContent);
+
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("messageType", msgType);
+        paramJson.put("messageContent", extrJson);
+
+        SocketUtil.sendMsgToGroupUser(SYSTEM_MSG_USER_ID, groupId, paramJson, false, false, userId);
+    }
+
+    /**
+     * 用户向群组中发送消息,自己也接收
+     *
+     * @param fromUid    发送者id
+     * @param groupId    群组id
+     * @param msgType    消息类型
+     * @param msgContent 消息内容
+     * @author jiang
+     * @description
+     * @date 2021/8/5 14:14
+     */
+    public static void sendMsgToGroup(long fromUid, long groupId, int msgType, String msgContent, boolean isPlazaMsg) {
+
+        JSONObject msg = new JSONObject();
+        msg.put("eventText", msgContent);
+
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("messageType", msgType);
+        paramJson.put("messageContent", msg);
+
+        SocketUtil.sendMsgToGroup(fromUid, groupId, paramJson, true, isPlazaMsg, isPlazaMsg);
+    }
+
+    /**
+     * 用户向群组中发送消息,自己也接收
+     *
+     * @param fromUid 发送者id
+     * @param groupId 群组id
+     * @param msgType 消息类型
+     * @param msgJson 消息内容的json
+     * @author jiang
+     * @description
+     * @date 2021/8/5 14:14
+     */
+    public static void sendMsgToGroup(long fromUid, long groupId, int msgType, JSONObject msgJson, boolean isPlazaMsg) {
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("messageType", msgType);
+        paramJson.put("messageContent", msgJson);
+
+        SocketUtil.sendMsgToGroup(fromUid, groupId, paramJson, true, isPlazaMsg, isPlazaMsg);
+    }
+
+
+
+    /**
+     * 用户向群组中发送消息,自己也接收
+     *
+     * @param fromUid 发送者id
+     * @param groupId 群组id
+     * @param type 消息类型
+     * @param msgJson 消息内容的json
+     * @param isChatRecord app端是否是聊天记录 0,不是聊天记录(比如礼物的动图效果,不需要保存到历史记录)  1,是聊天记录(比如发送的红包,需要保存到历史记录)
+     * @param onlineOnlyFlag 1表示消息仅发送在线成员,默认0表示发送所有成员,AVChatRoom(直播群)不支持该参数,-1表示此参数无效(用于直播群)
+     * @author lilin
+     * @description
+     * @date 2022/6/8 14:14
+     */
+    public static void sendMsgToGroup(String fromUid, String groupId, String type, String subType, JSONObject msgJson, int isChatRecord, int onlineOnlyFlag) {
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("isChatRecord", isChatRecord);
+        if(isChatRecord == 1){
+            paramJson.put("messageType", type);
+            paramJson.put("messageContent", msgJson);
+        }else {
+            paramJson.put("type", type);
+            paramJson.put("subType", subType);
+            paramJson.put("content", msgJson);
+        }
+
+        TencentCloudImUtil.sendGroupMsg(groupId, fromUid, paramJson.toString(), onlineOnlyFlag);
+    }
+
+
+
+    /**
+     * @param toUid
+     * @param msgType 10001 语音检测应答
+     * @param msgJson
+     */
+    public static void sendSysMsgToUser(long toUid, GroupChatMsgEnum msgType, JSONObject msgJson) {
+
+        JSONObject jsonMsg = new JSONObject();
+
+
+        jsonMsg.put("messageType", msgType.getCode());
+        jsonMsg.put("messageContent", msgJson);
+
+
+        SocketUtil.sendMsgToUser(SYSTEM_MSG_USER_ID, toUid, jsonMsg, false, true);
+    }
+
+    /**
+     * 用户向另一个用户发送消息,自己也接收
+     *
+     * @param fromUid    发送者id
+     * @param toUid      接收者id
+     * @param msgType    消息类型
+     * @param msgContent 消息内容
+     * @author jiang
+     * @description
+     * @date 2021/8/5 14:14
+     */
+    public static void sendMsgToUser(long fromUid, long toUid, int msgType, String msgContent) {
+
+        JSONObject msg = new JSONObject();
+        msg.put("eventText", msgContent);
+        msg.put("txt", msgContent);
+
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("messageType", msgType);
+        paramJson.put("messageContent", msg);
+
+        SocketUtil.sendMsgToUser(fromUid, toUid, paramJson, true, false);
+    }
+
+    /**
+     * 用户向另一个用户发送消息,自己也接收
+     *
+     * @param fromUid 发送者id
+     * @param toUid   接收者id
+     * @param msgType 消息类型
+     * @param msgJson 消息内容的json
+     * @author jiang
+     * @description
+     * @date 2021/8/5 14:14
+     */
+    public static void sendMsgToUser(long fromUid, long toUid, int msgType, JSONObject msgJson) {
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("messageType", msgType);
+        paramJson.put("messageContent", msgJson);
+
+        SocketUtil.sendMsgToUser(fromUid, toUid, paramJson, true, false);
+    }
+
+
+    /**
+     * 用户向另一个用户发送消息,自己也接收
+     *
+     * @param fromUid 发送者id  (默认adminstrator, 给null)
+     * @param toUid   接收者id
+     * @param type 消息类型
+     * @param msgJson 消息内容的json
+     * @param isChatRecord app端是否是聊天记录 0,不是聊天记录(比如礼物的动图效果,不需要保存到历史记录)  1,是聊天记录(比如发送的红包,需要保存到历史记录)
+     * @param msgLifeTime 消息保存时间,-1表示默认(7天)
+     * @author lilin
+     * @description
+     * @date 2022/6/8 14:14
+     */
+    public static void sendMsgToUser(String fromUid, String toUid, String type, String subType, JSONObject msgJson, int isChatRecord, int msgLifeTime) {
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("isChatRecord", isChatRecord);
+        if(isChatRecord == 1){
+            paramJson.put("messageType", type);
+            paramJson.put("messageContent", msgJson);
+        }else {
+            paramJson.put("type", type);
+            paramJson.put("subType", subType);
+            paramJson.put("content", msgJson);
+        }
+
+
+        TencentCloudImUtil.sendMsg(1, fromUid, toUid, paramJson.toString(), msgLifeTime);
+    }
+
+
+    /**
+     * 用户向另一个用户发送消息,自己也接收, 用于一对一通话,结束时发送的消息
+     *
+     * @param fromUid 发送者id
+     * @param toUid   接收者id
+     * @param status  0:接通了 1:取消 2:拒绝 3:超时
+     * @param isVideo 是否是视频  1:视频 0:语音
+     * @param time    通话时间(秒)
+     * @author jiang
+     * @date 2021/8/5 14:14
+     */
+    public static void sendMsgToUserOoo(long fromUid, long toUid, int status, int isVideo, int time) {
+        JSONObject paramJson = new JSONObject();
+        if (isVideo == 1) {
+            paramJson.put("messageType", GroupChatMsgEnum.TYPE_CALL_VIDEO.getCode());
+        } else {
+            paramJson.put("messageType", GroupChatMsgEnum.TYPE_CALL_VOICE.getCode());
+        }
+
+        JSONObject msgJson = new JSONObject();
+        msgJson.put("status", status);
+        if (isVideo == 1) {
+            msgJson.put("title", "一对一视频");
+        } else {
+            msgJson.put("title", "一对一语音");
+        }
+        if (time > 0) {
+            msgJson.put("time", DateUtil.formatBetween(time * 1000, BetweenFormatter.Level.SECOND));
+        } else {
+            msgJson.put("time", "");
+        }
+        paramJson.put("messageContent", msgJson);
+
+        SocketUtil.sendMsgToUser(fromUid, toUid, paramJson, true, false);
+    }
+
+
+    /**
+     * 全员推送
+     *
+     * @param type 消息类型
+     * @param msgJson 消息内容的json
+     * @param isChatRecord app端是否是聊天记录 0,不是聊天记录(比如礼物的动图效果,不需要保存到历史记录)  1,是聊天记录(比如发送的红包,需要保存到历史记录)
+     * @author lilin
+     * @description
+     * @date 2022/6/8 14:14
+     */
+    public static void sendMsgToAll(String type, String subType, JSONObject msgJson, int isChatRecord) {
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("isChatRecord", isChatRecord);
+        if(isChatRecord == 1){
+            paramJson.put("messageType", type);
+            paramJson.put("messageContent", msgJson);
+        }else {
+            paramJson.put("type", type);
+            paramJson.put("subType", subType);
+            paramJson.put("content", msgJson);
+        }
+
+        TencentCloudImUtil.imAllGroupPush(paramJson.toString());
+    }
+
+    /**
+     * 全员推送
+     */
+    public static void batchSendMsgToAll(List<String> users, GlobalMsgObject msg) {
+//        JSONObject paramJson = new JSONObject();
+//        paramJson.put("isChatRecord", isChatRecord);
+//        if(isChatRecord == 1){
+//            paramJson.put("messageType", type);
+//            paramJson.put("messageContent", msgJson);
+//        }else {
+//            paramJson.put("type", type);
+//            paramJson.put("subType", subType);
+//            paramJson.put("content", msgJson);
+//        }
+        JSONObject paramJson = new JSONObject();
+        paramJson.put("type", msg.getType());
+        paramJson.put("subType", msg.getSubType());
+        paramJson.put("content", msg.getMsgJson());
+        TencentCloudImUtil.imPushBatchSendMsg(users, paramJson.toString());
+//        TencentCloudImUtil.imAllGroupPush(paramJson.toString());
+    }
+}

+ 14 - 0
game-business/src/main/java/com/game/business/util/im/GlobalMsgObject.java

@@ -0,0 +1,14 @@
+package com.game.business.util.im;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.Data;
+
+/**
+ * 发送礼物队列对象
+ */
+@Data
+public class GlobalMsgObject {
+    private String type;
+    private String subType;
+    private JSONObject msgJson;
+}

+ 94 - 0
game-business/src/main/java/com/game/business/util/im/GroupChatMsgEnum.java

@@ -0,0 +1,94 @@
+package com.game.business.util.im;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author jiang
+ */
+@Getter
+@AllArgsConstructor
+public enum GroupChatMsgEnum {
+
+    /**
+     * 未知消息
+     */
+    TYPE_UNKNOWN(-1, "11233"),
+    /**
+     * 图片
+     */
+    TYPE_IMAGE(0, "11234"),
+    /**
+     * GIFT
+     */
+    TYPE_GIFT(1, "11235"),
+    /**
+     * 音频
+     */
+    TYPE_VOICE(2, "11236"),
+    /**
+     * 视频
+     */
+    TYPE_VIDEO(3, "11238"),
+    /**
+     * 一对一语音
+     */
+    TYPE_CALL_VOICE(4, "11239"),
+    /**
+     * 一对一视频
+     */
+    TYPE_CALL_VIDEO(5, "11240"),
+    /**
+     * 红包样式1
+     */
+    TYPE_RED_ENVELOPE(6, "11241"),
+    /**
+     * 寻觅订单
+     */
+    TYPE_SEEK(7, "11230"),
+    /**
+     * 文本
+     */
+    TYPE_TEXT(8, "11242"),
+    /**
+     * 群组提示性信息
+     */
+    TYPE_GROUP(9, "11243"),
+    /**
+     * 购物
+     */
+    TYPE_SHOP_ORDER(10, "11244"),
+    /**
+     * 发红包
+     */
+    SEND_RED_PACKET(1101, "11245"),
+    /**
+     * 领红包
+     */
+    OPEN_RED_PACKET(1102, "11246"),
+    /**
+     * 加入家族
+     */
+    JOIN_CHAT_FAMILY(1201, "11247"),
+    /**
+     * 求赏
+     */
+    ASK_FOR_REWARD(1301, "11248"),
+
+    /**
+     * 语音消息检查回复
+     */
+    voiceMsgCheckCallBack(1001, "11249");
+
+    int code;
+    String description;
+
+    public static GroupChatMsgEnum getGroupChatMsgEnum(int code) {
+        for (GroupChatMsgEnum chatMsgEnum : GroupChatMsgEnum.values()) {
+            if (chatMsgEnum.getCode() == code) {
+                return chatMsgEnum;
+            }
+        }
+        return TYPE_UNKNOWN;
+    }
+}

+ 300 - 0
game-business/src/main/java/com/game/business/util/im/HttpClientUtils.java

@@ -0,0 +1,300 @@
+/**
+ * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
+ */
+package com.game.business.util.im;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.conn.ssl.TrustStrategy;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.util.EntityUtils;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSession;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.security.GeneralSecurityException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * HTTP客户端工具类(支持HTTPS)
+ * @author ThinkGem
+ * @version 2017-3-27
+ */
+public class HttpClientUtils {
+
+	/**
+	 * http的get请求
+	 * @param url
+	 */
+	public static String get(String url) {
+		return get(url, "UTF-8");
+	}
+
+	/**
+	 * http的get请求
+	 * @param url
+	 */
+	public static String get(String url, String charset) {
+		HttpGet httpGet = new HttpGet(url);
+		return executeRequest(httpGet, charset);
+	}
+
+	/**
+	 * http的get请求,增加异步请求头参数
+	 * @param url
+	 */
+	public static String ajaxGet(String url) {
+		return ajaxGet(url, "UTF-8");
+	}
+
+	/**
+	 * http的get请求,增加异步请求头参数
+	 * @param url
+	 */
+	public static String ajaxGet(String url, String charset) {
+		HttpGet httpGet = new HttpGet(url);
+		httpGet.setHeader("X-Requested-With", "XMLHttpRequest");
+		return executeRequest(httpGet, charset);
+	}
+
+	/**
+	 * http的post请求,传递map格式参数
+	 */
+	public static String post(String url, Map<String, String> dataMap) {
+		return post(url, dataMap, "UTF-8");
+	}
+
+	/**
+	 * http的post请求,传递map格式参数
+	 */
+	public static String post(String url, Map<String, String> dataMap, String charset) {
+		HttpPost httpPost = new HttpPost(url);
+		try {
+			if (dataMap != null){
+				List<NameValuePair> nvps = new ArrayList<NameValuePair>();
+				for (Map.Entry<String, String> entry : dataMap.entrySet()) {
+					nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
+				}
+				UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nvps, charset);
+				formEntity.setContentEncoding(charset);
+				httpPost.setEntity(formEntity);
+			}
+		} catch (UnsupportedEncodingException e) {
+		}
+		return executeRequest(httpPost, charset);
+	}
+
+
+	public static String JSONObjectPost(String url, JSONObject param) {
+		HttpPost httpPost = null;
+		String result = null;
+		try {
+			HttpClient client = new DefaultHttpClient();
+			httpPost = new HttpPost(url);
+			if (param != null) {
+				StringEntity se = new StringEntity(param.toString(), "utf-8");
+				httpPost.setEntity(se); // post方法中,加入json数据
+				httpPost.setHeader("Content-Type", "application/json");
+				httpPost.setHeader("Authorization", param.getString("authorization"));
+			}
+
+			HttpResponse response = client.execute(httpPost);
+			if (response != null) {
+				HttpEntity resEntity = response.getEntity();
+				if (resEntity != null) {
+					result = EntityUtils.toString(resEntity, "utf-8");
+				}
+			}
+
+		} catch (Exception ex) {
+			ex.printStackTrace();
+		}
+		return result;
+	}
+
+
+	/**
+	 * http的post请求,增加异步请求头参数,传递map格式参数
+	 */
+	public static String ajaxPost(String url, Map<String, String> dataMap) {
+		return ajaxPost(url, dataMap, "UTF-8");
+	}
+
+	/**
+	 * http的post请求,增加异步请求头参数,传递map格式参数
+	 */
+	public static String ajaxPost(String url, Map<String, String> dataMap, String charset) {
+		HttpPost httpPost = new HttpPost(url);
+		httpPost.setHeader("X-Requested-With", "XMLHttpRequest");
+		try {
+			if (dataMap != null){
+				List<NameValuePair> nvps = new ArrayList<NameValuePair>();
+				for (Map.Entry<String, String> entry : dataMap.entrySet()) {
+					nvps.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
+				}
+				UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nvps, charset);
+				formEntity.setContentEncoding(charset);
+				httpPost.setEntity(formEntity);
+			}
+		} catch (UnsupportedEncodingException e) {
+		}
+		return executeRequest(httpPost, charset);
+	}
+
+	/**
+	 * http的post请求,增加异步请求头参数,传递json格式参数
+	 */
+	public static String ajaxPostJson(String url, String jsonString) {
+		return ajaxPostJson(url, jsonString, "UTF-8");
+	}
+
+	/**
+	 * http的post请求,增加异步请求头参数,传递json格式参数
+	 */
+	public static String ajaxPostJson(String url, String jsonString, String charset) {
+		HttpPost httpPost = new HttpPost(url);
+		httpPost.setHeader("X-Requested-With", "XMLHttpRequest");
+//		try {
+			StringEntity stringEntity = new StringEntity(jsonString, charset);// 解决中文乱码问题
+			stringEntity.setContentEncoding(charset);
+			stringEntity.setContentType("application/json");
+			httpPost.setEntity(stringEntity);
+//		} catch (UnsupportedEncodingException e) {
+//			;
+//		}
+		return executeRequest(httpPost, charset);
+	}
+
+	/**
+	 * 执行一个http请求,传递HttpGet或HttpPost参数
+	 */
+	public static String executeRequest(HttpUriRequest httpRequest) {
+		return executeRequest(httpRequest, "UTF-8");
+	}
+
+	/**
+	 * 执行一个http请求,传递HttpGet或HttpPost参数
+	 */
+	public static String executeRequest(HttpUriRequest httpRequest, String charset) {
+		CloseableHttpClient httpclient;
+		if ("https".equals(httpRequest.getURI().getScheme())){
+			httpclient = createSSLInsecureClient();
+		}else{
+			httpclient = HttpClients.createDefault();
+		}
+		String result = "";
+		try {
+			try {
+				CloseableHttpResponse response = httpclient.execute(httpRequest);
+				HttpEntity entity = null;
+				try {
+					entity = response.getEntity();
+					result = EntityUtils.toString(entity, charset);
+				} finally {
+					EntityUtils.consume(entity);
+					response.close();
+				}
+			} finally {
+				httpclient.close();
+			}
+		}catch(IOException ex){
+		}
+		return result;
+	}
+
+	/**
+	 * 创建 SSL连接
+	 */
+	public static CloseableHttpClient createSSLInsecureClient() {
+		try {
+			SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(new TrustStrategy() {
+				@Override
+				public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+					return true;
+				}
+			}).build();
+			SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new HostnameVerifier() {
+				@Override
+				public boolean verify(String hostname, SSLSession session) {
+					return true;
+				}
+			});
+			return HttpClients.custom().setSSLSocketFactory(sslsf).build();
+		} catch (GeneralSecurityException ex) {
+			throw new RuntimeException(ex);
+		}
+	}
+
+
+	/**带参数和APPCOD的接口请求
+	 * <p>Title: requestGet</p>
+	 * <p>Description: </p>
+	 * @param strUrl 请求地址
+	 * @param reqtype 请求方式
+	 * @param param 参数
+	 * @param authparam 认证参数
+	 * @param appcode 认证方式
+	 * @return
+	 */
+    public static String requestGet(String strUrl,String reqtype, String param,String authparam,String appcode) {
+
+        String returnStr = null; // 返回结果定义
+        URL url = null;
+        HttpURLConnection httpURLConnection = null;
+        try {
+            url = new URL(strUrl + "?" + param);
+            httpURLConnection = (HttpURLConnection) url.openConnection();
+            httpURLConnection.setRequestProperty("Accept-Charset", "utf-8");
+            httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+            httpURLConnection.setRequestProperty("Authorization", "APPCODE " + appcode);
+            httpURLConnection.setDoOutput(true);
+            httpURLConnection.setDoInput(true);
+            httpURLConnection.setRequestMethod("GET"); // get方式
+            httpURLConnection.setUseCaches(false); // 不用缓存
+            httpURLConnection.connect();
+            BufferedReader reader = new BufferedReader(
+                    new InputStreamReader(httpURLConnection.getInputStream(), "utf-8"));
+            StringBuffer buffer = new StringBuffer();
+            String line = "";
+            while ((line = reader.readLine()) != null) {
+                buffer.append(line);
+            }
+
+            reader.close();
+            returnStr = buffer.toString();
+        } catch (Exception e) {
+
+            return null;
+        } finally {
+            if (httpURLConnection != null) {
+                httpURLConnection.disconnect();
+            }
+        }
+        return returnStr;
+    }
+
+}

+ 190 - 0
game-business/src/main/java/com/game/business/util/im/TencentCloudImApiConstant.java

@@ -0,0 +1,190 @@
+package com.game.business.util.im;
+
+/**
+ * @description: 腾讯im相关API接口
+ * @author: lilin
+ * @date: 2022/5/24 17:58
+ */
+public class TencentCloudImApiConstant {
+    /**
+     * 账号管理
+     */
+    public static class AccountManage {
+        /**导入单个帐号*/
+        public static final String ACCOUNT_IMPORT = "v4/im_open_login_svc/account_import";
+        /**导入多个帐号*/
+        public static final String MULTI_ACCOUNT_IMPORT = "v4/im_open_login_svc/multiaccount_import";
+        /**删除帐号*/
+        public static final String ACCOUNT_DELETE = "v4/im_open_login_svc/account_delete";
+        /**查询帐号*/
+        public static final String ACCOUNT_CHECK = "v4/im_open_login_svc/account_check";
+        /**查询账号在线状态*/
+        public static final String ACCOUNT_QUERY_STATE = "v4/openim/query_online_status";
+    }
+
+    /**
+     * 单聊消息
+     */
+    public static class SingleChatManage {
+        /**单发单聊消息*/
+        public static final String SEND_MSG = "v4/openim/sendmsg";
+        /**批量发单聊消息 单次上限500人*/
+        public static final String BATCH_SEND_MSG = "v4/openim/batchsendmsg";
+        /**导入单聊消息*/
+        public static final String IMPORT_MSG = "v4/openim/importmsg";
+        /**查询单聊消息*/
+        public static final String ADMIN_GET_ROAM_MSG = "v4/openim/admin_getroammsg";
+        /**撤回单聊消息*/
+        public static final String ADMIN_MSG_WITH_DRAW = "v4/openim/admin_msgwithdraw";
+        /**设置单聊消息已读*/
+        public static final String ADMIN_SET_MSG_READ = "v4/openim/admin_set_msg_read";
+    }
+
+    /**
+     * 全员推送
+     */
+    public static class AllPushManage {
+        /**全直播群下发广播消息*/
+        public static final String IM_ALL_GROUP_MSG = "/v4/group_open_http_svc/send_broadcast_msg";
+        /**全员推送*/
+        public static final String IM_PUSH = "v4/all_member_push/im_push";
+        /**设置应用属性名称*/
+        public static final String IM_SET_ATTR_NAME = "v4/all_member_push/im_set_attr_name";
+        /**获取应用属性名称*/
+        public static final String IM_GET_ATTR_NAME = "v4/all_member_push/im_get_attr_name";
+        /**获取用户属性*/
+        public static final String IM_GET_ATTR = "v4/all_member_push/im_get_attr";
+        /**设置用户属性*/
+        public static final String IM_SET_ATTR = "v4/all_member_push/im_set_attr";
+        /**删除用户属性*/
+        public static final String IM_REMOVE_ATTR = "v4/all_member_push/im_remove_attr";
+        /**获取用户标签*/
+        public static final String IM_GET_TAG = "v4/all_member_push/im_get_tag";
+        /**添加用户标签*/
+        public static final String IM_ADD_TAG = "v4/all_member_push/im_add_tag";
+        /**删除用户标签*/
+        public static final String IM_REMOVE_TAG = "v4/all_member_push/im_remove_tag";
+        /**删除用户所有标签*/
+        public static final String IM_REMOVE_ALL_TAGS = "v4/all_member_push/im_remove_all_tags";
+    }
+
+    /**
+     * 资料管理
+     */
+    public static class PortraitManage {
+        /**设置资料*/
+        public static final String PORTRAIT_SET = "v4/profile/portrait_set";
+        /**拉取资料*/
+        public static final String PORTRAIT_GET = "v4/profile/portrait_get";
+    }
+
+    /**
+     * 关系链管理
+     */
+    public static class RelationManage {
+        /**添加好友*/
+        public static final String FRIEND_ADD = "v4/sns/friend_add";
+        /**导入好友*/
+        public static final String FRIEND_IMPORT = "v4/sns/friend_import";
+        /**更新好友*/
+        public static final String FRIEND_UPDATE = "v4/sns/friend_update";
+        /**删除好友*/
+        public static final String FRIEND_DELETE = "v4/sns/friend_delete";
+        /**删除所有好友*/
+        public static final String FRIEND_DELETE_ALL = "v4/sns/friend_delete_all";
+        /**校验好友*/
+        public static final String FRIEND_CHECK = "v4/sns/friend_check";
+        /**拉取好友*/
+        public static final String FRIEND_GET = "v4/sns/friend_get";
+        /**拉取指定好友*/
+        public static final String FRIEND_GET_LIST = "v4/sns/friend_get_list";
+        /**添加黑名单*/
+        public static final String BLACK_LIST_ADD = "v4/sns/black_list_add";
+        /**删除黑名单*/
+        public static final String BLACK_LIST_DELETE = "v4/sns/black_list_delete";
+        /**拉取黑名单*/
+        public static final String BLACK_LIST_GET = "v4/sns/black_list_get";
+        /**校验黑名单*/
+        public static final String BLACK_LIST_CHECK = "v4/sns/black_list_check";
+        /**添加分组*/
+        public static final String GROUP_ADD = "v4/sns/group_add";
+        /**删除分组*/
+        public static final String GROUP_DELETE = "v4/sns/group_delete";
+        /**拉取分组*/
+        public static final String GROUP_GET = "v4/sns/group_get";
+    }
+
+    /**
+     * 群组管理
+     */
+    public static class GroupManage {
+        /**创建群组*/
+        public static final String CREATE_GROUP = "v4/group_open_http_svc/create_group";
+        /**获取群详细资料*/
+        public static final String GET_GROUP_INFO = "v4/group_open_http_svc/get_group_info";
+        /**获取群成员详细资料*/
+        public static final String GET_GROUP_MEMBER_INFO = "v4/group_open_http_svc/get_group_member_info";
+        /**修改群基础资料*/
+        public static final String MODIFY_GROUP_BASE_INFO = "v4/group_open_http_svc/modify_group_base_info";
+        /**增加群成员*/
+        public static final String ADD_GROUP_MEMBER = "v4/group_open_http_svc/add_group_member";
+        /**删除群成员*/
+        public static final String DELETE_GROUP_MEMBER = "v4/group_open_http_svc/delete_group_member";
+        /**修改群成员资料*/
+        public static final String MODIFY_GROUP_MEMBER_INFO = "v4/group_open_http_svc/modify_group_member_info";
+        /**解散群组*/
+        public static final String DESTROY_GROUP = "v4/group_open_http_svc/destroy_group";
+        /**获取用户所加入的群组*/
+        public static final String GET_JOINED_GROUP_LIST = "v4/group_open_http_svc/get_joined_group_list";
+        /**查询用户在群组中的身份*/
+        public static final String GET_ROLE_IN_GROUP = "v4/group_open_http_svc/get_role_in_group";
+        /**批量禁言和取消禁言*/
+        public static final String FORBID_SEND_MSG = "v4/group_open_http_svc/forbid_send_msg";
+        /**获取被禁言群成员列表*/
+        public static final String GET_GROUP_SHUT_UIN = "v4/group_open_http_svc/get_group_shutted_uin";
+        /**在群组中发送普通消息*/
+        public static final String SEND_GROUP_MSG = "v4/group_open_http_svc/send_group_msg";
+        /**在群组中发送系统通知*/
+        public static final String SEND_GROUP_SYSTEM_NOTIFICATION = "v4/group_open_http_svc/send_group_system_notification";
+        /**撤回群消息*/
+        public static final String GROUP_MSG_RECALL = "v4/group_open_http_svc/group_msg_recall";
+        /**转让群主*/
+        public static final String CHANGE_GROUP_OWNER = "v4/group_open_http_svc/change_group_owner";
+        /**导入群基础资料*/
+        public static final String IMPORT_GROUP = "v4/group_open_http_svc/import_group";
+        /**导入群消息*/
+        public static final String IMPORT_GROUP_MSG = "v4/group_open_http_svc/import_group_msg";
+        /**导入群成员*/
+        public static final String IMPORT_GROUP_MEMBER = "v4/group_open_http_svc/import_group_member";
+        /**设置成员未读消息计数*/
+        public static final String SET_UNREAD_MSG_NUM = "v4/group_open_http_svc/set_unread_msg_num";
+        /**删除指定用户发送的消息*/
+        public static final String DELETE_GROUP_MSG_BY_SENDER = "v4/group_open_http_svc/delete_group_msg_by_sender";
+        /**拉取群历史消息*/
+        public static final String GROUP_MSG_GET_SIMPLE = "v4/group_open_http_svc/group_msg_get_simple";
+        /**获取直播群在线人数*/
+        public static final String GET_ONLINE_MEMBER_NUM = "v4/group_open_http_svc/get_online_member_num";
+    }
+
+    /**
+     * 全局禁言管理
+     */
+    public static class AllSinentManage {
+        /**设置全局禁言*/
+        public static final String SET_NO_SPEAKING = "v4/openconfigsvr/setnospeaking";
+        /**查询全局禁言*/
+        public static final String GET_NO_SPEAKING = "v4/openconfigsvr/getnospeaking";
+    }
+
+    /**
+     * 运营管理
+     */
+    public static class OperationManage {
+        /**拉取运营数据*/
+        public static final String GET_APP_INFO = "v4/openconfigsvr/getappinfo";
+        /**下载消息记录*/
+        public static final String GET_HISTORY = "v4/open_msg_svc/get_history";
+        /**获取服务器 IP 地址*/
+        public static final String GET_IP_LIST = "v4/ConfigSvc/GetIPList";
+    }
+}

+ 63 - 0
game-business/src/main/java/com/game/business/util/im/TencentCloudImConstant.java

@@ -0,0 +1,63 @@
+package com.game.business.util.im;
+
+/**
+ * @description: 腾讯im相关常量
+ * @author: lilin
+ * @date: 2022/5/24 16:37
+ */
+public class TencentCloudImConstant {
+    /**
+     * IM请求处理结果
+     */
+    public final static String ACTION_STATUS_OK = "OK";
+    public final static String ACTION_STATUS_FAIL = "FAIL";
+
+    /**
+     * IM发消息是否同步到发送方(1-同步,2-不同步)
+     */
+    public final static Integer SYNC_OTHER_MACHINE_YES = 1;
+    public final static Integer SYNC_OTHER_MACHINE_NO = 2;
+
+    /**
+     * IM消息对象类型:
+     * TIMTextElem	文本消息。
+     * TIMLocationElem	地理位置消息。
+     * TIMFaceElem	表情消息。
+     * TIMCustomElem	自定义消息,当接收方为 iOS 系统且应用处在后台时,此消息类型可携带除文本以外的字段到 APNs。一条组合消息中只能包含一个 TIMCustomElem 自定义消息元素。
+     * TIMSoundElem	语音消息。
+     * TIMImageElem	图像消息。
+     * TIMFileElem	文件消息。
+     * TIMVideoFileElem	视频消息。
+     */
+    public final static String TIM_TEXT_ELEM = "TIMTextElem";
+    public final static String TIM_LOCATION_ELEM = "TIMLocationElem";
+    public final static String TIM_FACE_ELEM = "TIMFaceElem";
+    public final static String TIM_CUSTOM_ELEM = "TIMCustomElem";
+    public final static String TIM_SOUND_ELEM = "TIMSoundElem";
+    public final static String TIM_IMAGE_ELEM = "TIMImageElem";
+    public final static String TIM_FILE_ELEM = "TIMFileElem";
+    public final static String TIM_VIDEOFILE_ELEM = "TIMVideoFileElem";
+
+    /**
+     * 微信响应消息类型
+     * WX_MSG_TYPE_EVENT:事件类型,事件类型对应"user_enter_tempsession"表示建立会话
+     * WX_MSG_TYPE_TEXT:文本类型
+     * WX_MSG_TYPE_TEXT:图片类型
+     * WX_MSG_TYPE_TEXT:小程序卡片
+     */
+    public final static String WX_MSG_TYPE_EVENT = "event";
+    public final static String WX_MSG_TYPE_TEXT = "text";
+    public final static String WX_MSG_TYPE_IMAGE = "image";
+    public final static String WX_MSG_TYPE_APPLET_CARD = "miniprogrampage";
+
+
+    /**
+     * 群聊类型
+     * */
+    public final static String GROUP_CHAT_TYPE_PRIVATE = "Private";
+    public final static String GROUP_CHAT_TYPE_PUBLIC = "Public";
+    public final static String GROUP_CHAT_TYPE_CHATROOM = "ChatRoom";
+    public final static String GROUP_CHAT_TYPE_AVCHATROOM = "AVChatRoom";
+    public final static String GROUP_CHAT_TYPE_COMMUNITY = "Community";
+
+}

+ 552 - 0
game-business/src/main/java/com/game/business/util/im/TencentCloudImUtil.java

@@ -0,0 +1,552 @@
+package com.game.business.util.im;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.RandomUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.imsocket.util.ApiResult;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.zip.Deflater;
+
+
+/**
+ * @description: 腾讯im基础配置
+ * @author: lilin
+ * @date: 2022/5/27 17:32
+ */
+@Slf4j
+public class TencentCloudImUtil {
+    private static String HTTPS_URL_PREFIX = "https://adminapisgp.im.qcloud.com/";
+    private static String APP_MANAGER = "administrator";
+    private static long sdkAppId = 20009542;
+    private static String key = "3cc3c3c35228510985ce4a6f1933ee941bbf646fa385d7aee3dd459c531b935a";
+    private static final int EXPIRETIME = 30 * 24 * 60 * 60;
+
+
+    /**
+     * 初始化
+     *
+     * @author lilin
+     * @date 2022/5/26 17:16
+     */
+    public static void init(long sdkAppId, String APP_MANAGER, String key) {
+        TencentCloudImUtil.sdkAppId = sdkAppId;
+        TencentCloudImUtil.APP_MANAGER = APP_MANAGER;
+        TencentCloudImUtil.key = key;
+    }
+
+    public static long getSdkAppId(){
+        return sdkAppId;
+    }
+
+
+    private static class Base64URL {
+        private static byte[] base64EncodeUrl(byte[] input) {
+            byte[] base64 = Base64.getEncoder().encode(input);
+            for (int i = 0; i < base64.length; ++i){
+                switch (base64[i]) {
+                    case '+':
+                        base64[i] = '*';
+                        break;
+                    case '/':
+                        base64[i] = '-';
+                        break;
+                    case '=':
+                        base64[i] = '_';
+                        break;
+                    default:
+                        break;
+                }
+            }
+            return base64;
+        }
+    }
+
+    /**
+     * 获取腾讯云用户签名
+     */
+    public static String genUserSig(String userid, byte[] userbuf) {
+
+        long currTime = System.currentTimeMillis() / 1000;
+
+        JSONObject sigDoc = new JSONObject();
+        sigDoc.put("TLS.ver", "2.0");
+        sigDoc.put("TLS.identifier", userid);
+        sigDoc.put("TLS.sdkappid", sdkAppId);
+        sigDoc.put("TLS.expire", EXPIRETIME);
+        sigDoc.put("TLS.time", currTime);
+
+        String base64UserBuf = null;
+        if (null != userbuf) {
+            base64UserBuf = Base64.getEncoder().encodeToString(userbuf).replaceAll("\\s*", "");
+            sigDoc.put("TLS.userbuf", base64UserBuf);
+        }
+        String sig = hmacsha256(userid, currTime, EXPIRETIME, base64UserBuf);
+        if (sig.length() == 0) {
+            return "";
+        }
+        sigDoc.put("TLS.sig", sig);
+        Deflater compressor = new Deflater();
+        compressor.setInput(sigDoc.toString().getBytes(StandardCharsets.UTF_8));
+        compressor.finish();
+        byte[] compressedBytes = new byte[2048];
+        int compressedBytesLength = compressor.deflate(compressedBytes);
+        compressor.end();
+        return (new String(Base64URL.base64EncodeUrl(Arrays.copyOfRange(compressedBytes,
+                0, compressedBytesLength)))).replaceAll("\\s*", "");
+    }
+
+
+    private static String hmacsha256(String identifier, long currTime, long expire, String base64Userbuf) {
+        String contentToBeSigned = "TLS.identifier:" + identifier + "\n"
+                + "TLS.sdkappid:" + sdkAppId + "\n"
+                + "TLS.time:" + currTime + "\n"
+                + "TLS.expire:" + expire + "\n";
+        if (null != base64Userbuf) {
+            contentToBeSigned += "TLS.userbuf:" + base64Userbuf + "\n";
+        }
+        try {
+            byte[] byteKey = key.getBytes(StandardCharsets.UTF_8);
+            Mac hmac = Mac.getInstance("HmacSHA256");
+            SecretKeySpec keySpec = new SecretKeySpec(byteKey, "HmacSHA256");
+            hmac.init(keySpec);
+            byte[] byteSig = hmac.doFinal(contentToBeSigned.getBytes(StandardCharsets.UTF_8));
+            return (Base64.getEncoder().encodeToString(byteSig)).replaceAll("\\s*", "");
+        } catch (NoSuchAlgorithmException | InvalidKeyException e) {
+            return "";
+        }
+    }
+
+
+    /**
+     * 获取腾讯im请求路径
+     */
+    private static String getHttpsUrl(String imServiceApi, Integer random) {
+        return String.format("%s%s?sdkappid=%s&identifier=%s&usersig=%s&random=%s&contenttype=json",
+                HTTPS_URL_PREFIX, imServiceApi, sdkAppId, APP_MANAGER, genUserSig("administrator", null), random);
+    }
+
+    /**
+     * 导入单个账号
+     * @param userId 用户id
+     */
+    public static void accountImport(String userId) {
+        accountImport(userId, null);
+    }
+
+    public static void accountImport(String userId, String userName) {
+        accountImport(userId, userName, null);
+    }
+
+    public static void accountImport(String userId, String userName, String faceUrl) {
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.AccountManage.ACCOUNT_IMPORT, random);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("UserID", userId);
+        if (StringUtils.isNotEmpty(userName)) {
+            jsonObject.put("Nick", userName);
+        }
+        if (StringUtils.isNotEmpty(faceUrl)) {
+            jsonObject.put("FaceUrl", faceUrl);
+        }
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+    }
+
+    /**
+     * 导入多个账号
+     * @param userIds 用户id集合
+     */
+    public static void multiAccountImport(List<String> userIds) {
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.AccountManage.MULTI_ACCOUNT_IMPORT, random);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("Accounts", userIds);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+    }
+
+    /**
+     * 删除账号
+     * @param userIds 用户id集合
+     */
+    public static void accountDelete(List<String> userIds) {
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.AccountManage.ACCOUNT_DELETE, random);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("DeleteItem", getUserIdJsonList(userIds));
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+    }
+
+
+    /**
+     * 查询帐号在线状态
+     * @param userId 用户id集合
+     */
+    public static boolean queryOnlineStatus(String userId) {
+        boolean isOnline = false;
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.AccountManage.ACCOUNT_QUERY_STATE, random);
+        JSONObject jsonObject = new JSONObject();
+        List<String> list = new ArrayList<>();
+        list.add(userId);
+        jsonObject.put("To_Account", list);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+        if("OK".equals(JSONObject.parseObject(result).get("ActionStatus"))){
+            JSONArray jsonArray = JSONObject.parseObject(result).getJSONArray("QueryResult");
+            JSONObject jb = (JSONObject)jsonArray.get(0);
+            if("Online".equals(jb.getString("Status"))){
+                isOnline = true;
+            }
+        }
+        return isOnline;
+    }
+
+
+
+    private static List<JSONObject> getUserIdJsonList(List<String> userIds) {
+        return userIds.stream().map(v -> {
+            JSONObject userIdJson = new JSONObject();
+            userIdJson.put("UserID", v);
+            return userIdJson;
+        }).collect(Collectors.toList());
+    }
+
+
+    /**
+     * 单发单聊消息
+     * @param syncOtherMachine 是否同步消息到发送方(1-同步,2-不同步)
+     * @param fromUserId 发送方用户id (默认adminstrator, 给null)
+     * @param toUserId 接收方用户id
+     * @param msgContent 消息内容
+     * @param msgLifeTime 消息保存时间,-1表示默认(7天)
+     */
+    public static String sendMsg(Integer syncOtherMachine, String fromUserId, String toUserId, String msgContent, int msgLifeTime) {
+        if(StringUtils.isEmpty(fromUserId)){
+            fromUserId = "administrator";
+        }
+
+        if(sdkAppId > 0){
+            Integer random = RandomUtils.nextInt(0, 999999999);
+            String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.SingleChatManage.SEND_MSG, random);
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("SyncOtherMachine", syncOtherMachine);
+            if (StringUtils.isNotEmpty(fromUserId)) {
+                // 发送方不为空表示指定发送用户,为空表示为管理员发送消息
+                jsonObject.put("From_Account", fromUserId);
+            }
+            if(msgLifeTime == -1){
+                msgLifeTime = 604800;
+            }
+            jsonObject.put("MsgLifeTime", msgLifeTime);
+            jsonObject.put("To_Account", toUserId);
+            jsonObject.put("MsgRandom", random);
+            List<JSONObject> msgBody = getMsgBody(TencentCloudImConstant.TIM_CUSTOM_ELEM, msgContent);
+            jsonObject.put("MsgBody", msgBody);
+            String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+            System.out.println("单发结果:"+ result.toString());
+            return result;
+        }
+
+        return null;
+    }
+
+
+    /**
+     * 拼接发送消息内容
+     * @param msgType 消息类型
+     * @param msgContent 发送消息内容
+     * @return 消息内容
+     */
+    private static List<JSONObject> getMsgBody(String msgType, String msgContent) {
+        List<JSONObject> msgBody = new ArrayList<>();
+        if (msgType.equals(TencentCloudImConstant.TIM_CUSTOM_ELEM)) {
+            // 文本类型
+            JSONObject msgBodyJson = new JSONObject();
+            msgBodyJson.put("MsgType", msgType);
+
+            JSONObject contentJson = new JSONObject();
+            contentJson.put("Data", msgContent);
+
+            msgBodyJson.put("MsgContent", contentJson);
+            msgBody.add(msgBodyJson);
+        }
+        return msgBody;
+    }
+
+
+    /**
+     * 腾讯云im创建群聊
+     * @param type 群组类型:Private/Public/ChatRoom/AVChatRoom/Community(必填)
+     * @param ownerUserId 群主
+     * @param groupId 群聊id
+     * @param groupName 群聊名称
+     *
+     */
+    public static ApiResult createGroup(String type, String ownerUserId, String groupId, String groupName) {
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.GroupManage.CREATE_GROUP, random);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("Owner_Account", ownerUserId);
+        jsonObject.put("Type", type);
+        jsonObject.put("Name", groupName);
+        jsonObject.put("GroupId", groupId);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        if("OK".equals((String)resultJson.get("ActionStatus"))){
+            return new ApiResult(1, "创建成功");
+        }else {
+            return new ApiResult((Integer)resultJson.get("ErrorCode"), (String)resultJson.get("ErrorInfo"));
+        }
+    }
+
+
+    /**
+     * 腾讯云im解散群组
+     * @param groupId 群聊id
+     *
+     */
+    public static void destroyGroup(String groupId) {
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.GroupManage.DESTROY_GROUP, random);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("GroupId", groupId);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+    }
+
+
+    /**
+     * 加入群聊
+     * @param groupId 群id
+     * @param userid 加入群聊用户id
+     */
+    public static void addGroupMember(String groupId, String userid){
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.GroupManage.ADD_GROUP_MEMBER, random);
+        List<Map> mapList = new ArrayList<>();
+        Map map = new HashMap();
+        map.put("Member_Account", userid);
+        mapList.add(map);
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("GroupId", groupId);
+        jsonObject.put("MemberList", mapList);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+    }
+
+    /**
+     * 删除群成员
+     * @param groupId 群id
+     * @param userid 加入群聊用户id
+     * @param silence 0.非静默删除  1.静默删除
+     */
+    public static void delGroupMember(String groupId, String userid, int silence){
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.GroupManage.DELETE_GROUP_MEMBER, random);
+        List<String> accountList = new ArrayList<>();
+        accountList.add(userid);
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("GroupId", groupId);
+        jsonObject.put("Silence", silence);
+        jsonObject.put("MemberToDel_Account", accountList);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+    }
+
+
+    /**
+     * 在群组中发送系统通知
+     * @param groupId 群id
+     * @param Content 通知内容
+     */
+    public static void sendGroupSystemNotification(String groupId, String Content){
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.GroupManage.SEND_GROUP_SYSTEM_NOTIFICATION, random);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("GroupId", groupId);
+        jsonObject.put("Content", Content);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+    }
+
+
+    /***
+     * 在群组中发送普通消息
+     * @param GroupId 群组id
+     * @param fromUserId 发送者id
+     * @param msgContent 消息内容
+     * @param onlineOnlyFlag 1表示消息仅发送在线成员,默认0表示发送所有成员,AVChatRoom(直播群)不支持该参数,-1表示此参数无效(用于直播群)
+     */
+    public static String sendGroupMsg(String GroupId, String fromUserId, String msgContent, int onlineOnlyFlag) {
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.GroupManage.SEND_GROUP_MSG, random);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("GroupId", GroupId);
+        jsonObject.put("Random", random);
+        if(onlineOnlyFlag != -1){
+            jsonObject.put("OnlineOnlyFlag", onlineOnlyFlag);
+        }
+        if (StringUtils.isNotEmpty(fromUserId)) {
+            // 发送方不为空表示指定发送用户,为空表示为管理员发送消息
+            jsonObject.put("From_Account", fromUserId);
+        }
+        List<JSONObject> msgBody = getMsgBody(TencentCloudImConstant.TIM_CUSTOM_ELEM, msgContent);
+        jsonObject.put("MsgBody", msgBody);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+        return result;
+    }
+
+
+    /**
+     * 获取用户所加入的群组
+     * @param userId 用户id
+     * @param type 群聊类型
+     */
+    public static JSONArray getJoinedGroupList(String userId, String type){
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.GroupManage.GET_JOINED_GROUP_LIST, random);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("Member_Account", userId);
+        jsonObject.put("GroupType", type);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+        JSONArray jsonArray = new JSONArray();
+        if("OK".equals(JSONObject.parseObject(result).get("ActionStatus"))){
+            jsonArray = JSONObject.parseObject(result).getJSONArray("GroupIdList");
+        }
+        return jsonArray;
+    }
+
+
+    /**
+     * 获取群详细资料
+     * @param groupIdList 群id数组
+     */
+    public static JSONObject getGroupInfo(List<String> groupIdList){
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.GroupManage.GET_GROUP_INFO, random);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("GroupIdList", groupIdList);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+        JSONObject resultJson = JSONObject.parseObject(result);
+        return resultJson;
+    }
+
+    /**
+     * 判断群是否被创建过
+     * @param groupId 群id
+     */
+    public static boolean haveGroup(String groupId){
+        List<String> stringList = new ArrayList<>();
+        stringList.add(groupId);
+        JSONObject jsonObject = getGroupInfo(stringList);
+        JSONObject groupInfo = (JSONObject)jsonObject.getJSONArray("GroupInfo").get(0);
+        Integer errorCode = (Integer) groupInfo.get("ErrorCode");
+        if(errorCode == 0){
+            return true;
+        }else {
+            return false;
+        }
+    }
+
+
+    /**
+     * 直播群广播消息
+     */
+    public static String imAllGroupPush(String msgContent) {
+        if(sdkAppId > 0){
+            Integer random = RandomUtils.nextInt(0, 999999999);
+            String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.AllPushManage.IM_ALL_GROUP_MSG, random);
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("From_Account", "administrator");
+            jsonObject.put("Random", random);
+
+            List<JSONObject> msgBody = getMsgBody(TencentCloudImConstant.TIM_CUSTOM_ELEM, msgContent);
+            jsonObject.put("MsgBody", msgBody);
+            String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+            return result;
+        }
+        return null;
+    }
+
+
+    /***
+     * 批量发送单聊消息,一次500人上限
+     * @param msgContent 消息内容
+     */
+    public static String imPushBatchSendMsg(List<String> userIdList, String msgContent) {
+        if(sdkAppId > 0){
+            log.info("调用IM接口,IM_PUSH, msgContent:{}", msgContent);
+            Integer random = RandomUtils.nextInt(0, 999999999);
+            String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.SingleChatManage.BATCH_SEND_MSG, random);
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("SyncOtherMachine", 2);  // 消息不同步至发送方
+            jsonObject.put("From_Account", "administrator");
+            JSONArray jsonArray = new JSONArray();
+            for (String s : userIdList) {
+                jsonArray.add(s);
+            }
+            jsonObject.put("To_Account", jsonArray);
+            jsonObject.put("MsgRandom", random);
+            jsonObject.put("MsgLifeTime", 0);
+            List<JSONObject> msgBody = getMsgBody(TencentCloudImConstant.TIM_CUSTOM_ELEM, msgContent);
+            jsonObject.put("MsgBody", msgBody);
+            log.info("发起请求,request:{}", jsonObject);
+            String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+            log.info("imPushBatchSendMsg result: {}", result);
+            return result;
+        }
+        return null;
+    }
+
+    /***
+     * 全员推送
+     * @param msgContent 消息内容
+     */
+    public static String imPush(String msgContent) {
+        if(sdkAppId > 0){
+            log.info("调用IM接口,IM_PUSH, msgContent:{}", msgContent);
+            Integer random = RandomUtils.nextInt(0, 999999999);
+            String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.AllPushManage.IM_PUSH, random);
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("From_Account", "administrator");
+            jsonObject.put("MsgRandom", random);
+            jsonObject.put("MsgLifeTime", 0);
+
+            List<JSONObject> msgBody = getMsgBody(TencentCloudImConstant.TIM_CUSTOM_ELEM, msgContent);
+            jsonObject.put("MsgBody", msgBody);
+            String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+            log.info("IM_PUSH result: {}", result);
+            return result;
+        }
+        return null;
+    }
+
+
+
+    /***
+     * 拉取运营数据
+     * @param requestField 指定需要拉取的字段
+     */
+    public static Object getAppInfo(String requestField) {
+        Integer random = RandomUtils.nextInt(0, 999999999);
+        String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.OperationManage.GET_APP_INFO, random);
+        JSONObject jsonObject = new JSONObject();
+        List<String> list = new ArrayList<>();
+        list.add(requestField);
+        jsonObject.put("RequestField", list);
+        String result = HttpClientUtils.JSONObjectPost(httpsUrl, jsonObject);
+
+        if((Integer) JSONObject.parseObject(result).get("ErrorCode") == 0){
+            JSONArray jsonArray = (JSONArray)JSONObject.parseObject(result).get("Result");
+            JSONObject jb = (JSONObject)jsonArray.get(0);
+            return jb.get(requestField);
+        }
+        return null;
+    }
+
+}