【应急】IM视频通话
This commit is contained in:
@@ -5,12 +5,13 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.renkang.consultation.api.ConSessionHelloApi;
|
||||
import com.renkang.consultation.entity.ConSessionDO;
|
||||
import com.renkang.im.dto.AddGroupMemberDTO;
|
||||
import com.renkang.im.entity.*;
|
||||
import com.renkang.im.service.IImMsgRecordAllService;
|
||||
import com.renkang.im.util.IdWorker;
|
||||
import com.renkang.im.util.TencentCloudImUtil;
|
||||
import com.renkang.im.util.UniqId;
|
||||
import com.renkang.im.entity.ImMsgRecordAll;
|
||||
import com.renkang.im.vo.AddGroupMemberVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
@@ -64,7 +65,6 @@ public class TXController {
|
||||
private ConSessionHelloApi conSessionHelloApi;
|
||||
|
||||
|
||||
|
||||
@GetMapping("/userSigAndroid")
|
||||
@Operation(summary = "获取userSigAndroid")
|
||||
public Result<Map> userSigAndroid() {
|
||||
@@ -80,6 +80,7 @@ public class TXController {
|
||||
|
||||
/**
|
||||
* 拉取群组消息 v1
|
||||
*
|
||||
* @param groupId
|
||||
* @return
|
||||
*/
|
||||
@@ -89,16 +90,16 @@ public class TXController {
|
||||
|
||||
Integer MsgSeq = null;
|
||||
boolean haveData = true;
|
||||
while(haveData){
|
||||
String s = tencentCloudImUtil.groupMessage(groupId,1,MsgSeq,0);
|
||||
while (haveData) {
|
||||
String s = tencentCloudImUtil.groupMessage(groupId, 1, MsgSeq, 0);
|
||||
JSONObject jsonObjectResult = JSONObject.parseObject(s);
|
||||
JSONArray rsqMsgList = jsonObjectResult.getJSONArray("RspMsgList");
|
||||
if(CollectionUtils.isEmpty(rsqMsgList)){
|
||||
if (CollectionUtils.isEmpty(rsqMsgList)) {
|
||||
haveData = false;
|
||||
break;
|
||||
}
|
||||
JSONObject one = rsqMsgList.getJSONObject(0);
|
||||
MsgSeq = one.getInteger("MsgSeq")+1;
|
||||
MsgSeq = one.getInteger("MsgSeq") + 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -110,26 +111,26 @@ public class TXController {
|
||||
|
||||
Result<List<ConSessionDO>> resultList = conSessionHelloApi.sekectSessionListByDate();
|
||||
|
||||
if(resultList.isSuccess()){
|
||||
if (resultList.isSuccess()) {
|
||||
|
||||
List<ConSessionDO> list = resultList.getResult();
|
||||
for (ConSessionDO conSessionDO : list) {
|
||||
boolean flag = true;
|
||||
Integer MsgSeq = null;
|
||||
while(flag){
|
||||
while (flag) {
|
||||
|
||||
if(MsgSeq != null && MsgSeq < 0){
|
||||
if (MsgSeq != null && MsgSeq < 0) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
String s = tencentCloudImUtil.groupMessage(conSessionDO.getImId(),1,MsgSeq,0);
|
||||
if(StringUtils.isEmpty(s)){
|
||||
String s = tencentCloudImUtil.groupMessage(conSessionDO.getImId(), 1, MsgSeq, 0);
|
||||
if (StringUtils.isEmpty(s)) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
JSONObject jsonObjectResult = JSONObject.parseObject(s);
|
||||
JSONArray rsqMsgList = jsonObjectResult.getJSONArray("RspMsgList");
|
||||
if(CollectionUtils.isEmpty(rsqMsgList)){
|
||||
if (CollectionUtils.isEmpty(rsqMsgList)) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
@@ -146,33 +147,33 @@ public class TXController {
|
||||
|
||||
JSONArray ImageInfoArray = MsgContent.getJSONArray("ImageInfoArray");
|
||||
for (Object o : ImageInfoArray) {
|
||||
JSONObject AA = (JSONObject)o;
|
||||
JSONObject AA = (JSONObject) o;
|
||||
String oldUrl = AA.getString("URL");
|
||||
String newUrl = "";
|
||||
if(oldUrl.contains("https://cn.imrich.qcloud.com")){
|
||||
if (oldUrl.contains("https://cn.imrich.qcloud.com")) {
|
||||
newUrl = oldUrl.replace("https://cn.imrich.qcloud.com", "http://101.201.149.156:8609/qc");
|
||||
}
|
||||
if(oldUrl.contains("https://cos.ap-guangzhou.myqcloud.com")){
|
||||
if (oldUrl.contains("https://cos.ap-guangzhou.myqcloud.com")) {
|
||||
newUrl = oldUrl.replace("https://cos.ap-guangzhou.myqcloud.com", "http://101.201.149.156:8609/gmc");
|
||||
}
|
||||
if(oldUrl.contains("https://cn.rich.my-imcloud.com")){
|
||||
if (oldUrl.contains("https://cn.rich.my-imcloud.com")) {
|
||||
newUrl = oldUrl.replace("https://cn.rich.my-imcloud.com", "http://101.201.149.156:8609/ic");
|
||||
}
|
||||
if(oldUrl.contains("https://cos.ap-shanghai.myqcloud.com")){
|
||||
if (oldUrl.contains("https://cos.ap-shanghai.myqcloud.com")) {
|
||||
newUrl = oldUrl.replace("https://cos.ap-shanghai.myqcloud.com", "http://101.201.149.156:8609/smc");
|
||||
}
|
||||
if(oldUrl.contains("https://cos.ap-shanghai.tencentcos.cn")){
|
||||
if (oldUrl.contains("https://cos.ap-shanghai.tencentcos.cn")) {
|
||||
newUrl = oldUrl.replace("https://cos.ap-shanghai.tencentcos.cn", " http://101.201.149.156:8609/tc");
|
||||
}
|
||||
if(!StringUtils.isEmpty(newUrl)){
|
||||
if (!StringUtils.isEmpty(newUrl)) {
|
||||
imageList.add(newUrl);
|
||||
}
|
||||
}
|
||||
Map<String,String> msgBodyMap = tencentCloudImUtil.changeUrelArray(imageList, msgType);
|
||||
Map<String, String> msgBodyMap = tencentCloudImUtil.changeUrelArray(imageList, msgType);
|
||||
for (Map.Entry<String, String> entry : msgBodyMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
s=s.replace(key,value);
|
||||
s = s.replace(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +189,7 @@ public class TXController {
|
||||
imMsgRecordAll.setMsgtype("2");
|
||||
imMsgRecordAll.setCreateTime(date);
|
||||
flag = imMsgRecordAllService.save(imMsgRecordAll);
|
||||
MsgSeq = MsgSeqOne-1;
|
||||
MsgSeq = MsgSeqOne - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +198,6 @@ public class TXController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 单发单聊消息
|
||||
*
|
||||
@@ -268,10 +268,10 @@ public class TXController {
|
||||
aa = "(专家)";
|
||||
}
|
||||
String auatr = loginUser.getAvatar();
|
||||
if(!StringUtils.isEmpty(auatr)){
|
||||
auatr = auatr.replace("\\","/");
|
||||
if (!StringUtils.isEmpty(auatr)) {
|
||||
auatr = auatr.replace("\\", "/");
|
||||
auatr = encodeChineseCharacters(headUrl + auatr);
|
||||
}else{
|
||||
} else {
|
||||
auatr = "";
|
||||
}
|
||||
tencentCloudImUtil.accountImport(loginUser.getId(), loginUser.getRealname() + aa, auatr);
|
||||
@@ -308,10 +308,10 @@ public class TXController {
|
||||
aa = "(专家)";
|
||||
}
|
||||
String auatr = loginUser.getAvatar();
|
||||
if(!StringUtils.isEmpty(auatr)){
|
||||
auatr = auatr.replace("\\","/");
|
||||
if (!StringUtils.isEmpty(auatr)) {
|
||||
auatr = auatr.replace("\\", "/");
|
||||
auatr = encodeChineseCharacters(headUrl + auatr);
|
||||
}else{
|
||||
} else {
|
||||
auatr = "";
|
||||
}
|
||||
tencentCloudImUtil.accountImport(loginUser.getId(), loginUser.getRealname() + aa, auatr);
|
||||
@@ -341,7 +341,6 @@ public class TXController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "创建群聊-应急")
|
||||
@PostMapping(value = "/creatGroupMagNewHelper")
|
||||
public Result<Map<String, Object>> creatGroupMagNewHelper(@RequestBody ConSessionRequestDO conSessionRequestDO) {
|
||||
@@ -360,10 +359,10 @@ public class TXController {
|
||||
|
||||
if (loginUser != null) {
|
||||
String auatr = loginUser.getAvatar();
|
||||
if(!StringUtils.isEmpty(auatr)){
|
||||
auatr = auatr.replace("\\","/");
|
||||
if (!StringUtils.isEmpty(auatr)) {
|
||||
auatr = auatr.replace("\\", "/");
|
||||
auatr = encodeChineseCharacters(headUrl + auatr);
|
||||
}else{
|
||||
} else {
|
||||
auatr = "";
|
||||
}
|
||||
tencentCloudImUtil.accountImport(loginUser.getId(), loginUser.getRealname(), auatr);
|
||||
@@ -392,11 +391,13 @@ public class TXController {
|
||||
return Result.OK(res);
|
||||
}
|
||||
|
||||
@Operation(summary = "添加群成员", description = "添加群成员")
|
||||
@PostMapping("/addGroupMember")
|
||||
public Result<AddGroupMemberVO> addGroupMember(@RequestBody @Validated AddGroupMemberDTO dto) {
|
||||
return Result.OK(tencentCloudImUtil.addGroupMember(dto));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private String encodeChineseCharacters(String str) {
|
||||
private String encodeChineseCharacters(String str) {
|
||||
return str.codePoints()
|
||||
.mapToObj(c -> {
|
||||
try {
|
||||
|
||||
@@ -6,10 +6,13 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.renkang.im.ImSendEnum;
|
||||
import com.renkang.im.common.TencentCloudImApiConstant;
|
||||
import com.renkang.im.common.TencentCloudImConstant;
|
||||
import com.renkang.im.dto.AddGroupMemberDTO;
|
||||
import com.renkang.im.entity.*;
|
||||
import com.renkang.im.vo.AddGroupMemberVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -52,6 +55,8 @@ public class TencentCloudImUtil {
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisServiceUtil;
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
||||
public static Integer getRandomNum(int length) {
|
||||
@@ -225,7 +230,7 @@ public class TencentCloudImUtil {
|
||||
*/
|
||||
public IMGroupMsgResDO sendGroupMsgText(ImGroupMsgTextReqDO imGroupMsgTextReqVO) {
|
||||
IMGroupMsgResDO res = new IMGroupMsgResDO();
|
||||
String url = HTTPS_URL_PREFIX+"v4/group_open_http_svc/send_group_msg";
|
||||
String url = HTTPS_URL_PREFIX + "v4/group_open_http_svc/send_group_msg";
|
||||
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("GroupId", imGroupMsgTextReqVO.getGroupId());
|
||||
@@ -271,7 +276,7 @@ public class TencentCloudImUtil {
|
||||
*/
|
||||
public IMGroupMsgResDO sendGroupMsgTextNew(ImGroupMsgTextReqDO imGroupMsgTextReqVO) {
|
||||
IMGroupMsgResDO res = new IMGroupMsgResDO();
|
||||
String url = HTTPS_URL_PREFIX+"v4/group_open_http_svc/send_group_msg";
|
||||
String url = HTTPS_URL_PREFIX + "v4/group_open_http_svc/send_group_msg";
|
||||
|
||||
JSONObject param = new JSONObject();
|
||||
param.put("GroupId", imGroupMsgTextReqVO.getGroupId());
|
||||
@@ -316,7 +321,7 @@ public class TencentCloudImUtil {
|
||||
*/
|
||||
public IMBaseDO sendGroupNotify(String groupId, String content) {
|
||||
|
||||
String url = HTTPS_URL_PREFIX+"v4/group_open_http_svc/send_group_system_notification";
|
||||
String url = HTTPS_URL_PREFIX + "v4/group_open_http_svc/send_group_system_notification";
|
||||
|
||||
// 云通信包参数
|
||||
JSONObject obj1 = new JSONObject();
|
||||
@@ -330,7 +335,7 @@ public class TencentCloudImUtil {
|
||||
|
||||
public IMBaseDO sendGroupNotifyToUser(String groupId, List<String> userIds, String content) {
|
||||
|
||||
String url = HTTPS_URL_PREFIX+"v4/group_open_http_svc/send_group_system_notification";
|
||||
String url = HTTPS_URL_PREFIX + "v4/group_open_http_svc/send_group_system_notification";
|
||||
|
||||
// 云通信包参数
|
||||
JSONObject obj1 = new JSONObject();
|
||||
@@ -450,20 +455,28 @@ public class TencentCloudImUtil {
|
||||
/**
|
||||
* 添加群成员
|
||||
*
|
||||
* @param GroupId
|
||||
* @param MemberList
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
public String addGroupMember(String GroupId, List MemberList) {
|
||||
Integer random = RandomUtils.nextInt(0, 999999999);
|
||||
String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.GroupManage.ADD_GROUP_MEMBER, random);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("GroupId", GroupId);
|
||||
jsonObject.put("MemberList", MemberList);
|
||||
log.info("腾讯云im创建群聊,请求参数:{}", jsonObject);
|
||||
String result = HttpUtil.doPost(httpsUrl, jsonObject);
|
||||
log.info("腾讯云im创建群聊,返回结果:{}", result);
|
||||
return result;
|
||||
public AddGroupMemberVO addGroupMember(AddGroupMemberDTO dto) {
|
||||
try {
|
||||
Integer random = RandomUtils.nextInt(0, 999999999);
|
||||
String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.GroupManage.ADD_GROUP_MEMBER, random);
|
||||
String jsonString = objectMapper.writeValueAsString(dto);
|
||||
JSONObject jsonObject = JSONObject.parseObject(jsonString);
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("GroupId", dto.getGroupId());
|
||||
// jsonObject.put("MemberList", dto.getMemberList());
|
||||
log.info("腾讯云im添加群成员,请求参数:{}", jsonObject);
|
||||
String result = HttpUtil.doPost(httpsUrl, jsonObject);
|
||||
log.info("腾讯云im添加群成员,返回结果:{}", result);
|
||||
return JSONObject.toJavaObject(JSONObject.parseObject(result), AddGroupMemberVO.class);
|
||||
} catch (Exception e) {
|
||||
log.error("添加群成员异常:{}", e.getMessage());
|
||||
}
|
||||
AddGroupMemberVO addGroupMemberVO = new AddGroupMemberVO();
|
||||
addGroupMemberVO.setActionStatus("FAIL");
|
||||
return addGroupMemberVO;
|
||||
}
|
||||
|
||||
|
||||
@@ -614,7 +627,7 @@ public class TencentCloudImUtil {
|
||||
List<ImgMsg> img1 = img.getImageInfoArray();
|
||||
img1.forEach(imgMsg -> {
|
||||
|
||||
String newImgMsg = changeOldUrlToNew(imgMsg.getURL());
|
||||
String newImgMsg = changeOldUrlToNew(imgMsg.getURL());
|
||||
imgMsg.setURL(newImgMsg);
|
||||
|
||||
FileInputStream fileInputStream = null;
|
||||
@@ -650,10 +663,10 @@ public class TencentCloudImUtil {
|
||||
try {
|
||||
|
||||
|
||||
String newImgMsg = changeOldUrlToNew(img.getThumbUrl());
|
||||
String newImgMsg = changeOldUrlToNew(img.getThumbUrl());
|
||||
img.setThumbUrl(newImgMsg);
|
||||
|
||||
String newBideo = changeOldUrlToNew(img.getVideoUrl());
|
||||
String newBideo = changeOldUrlToNew(img.getVideoUrl());
|
||||
img.setVideoUrl(newBideo);
|
||||
|
||||
// 根据url下载图片
|
||||
@@ -692,7 +705,7 @@ public class TencentCloudImUtil {
|
||||
File fileByUrl = null;
|
||||
try {
|
||||
|
||||
String newImgMsg = changeOldUrlToNew(file.getUrl());
|
||||
String newImgMsg = changeOldUrlToNew(file.getUrl());
|
||||
file.setUrl(newImgMsg);
|
||||
|
||||
// 根据url下载文件
|
||||
@@ -721,7 +734,7 @@ public class TencentCloudImUtil {
|
||||
File fileByUrl = null;
|
||||
try {
|
||||
|
||||
String newImgMsg = changeOldUrlToNew(file.getUrl());
|
||||
String newImgMsg = changeOldUrlToNew(file.getUrl());
|
||||
file.setUrl(newImgMsg);
|
||||
|
||||
// 根据url下载文件
|
||||
@@ -749,21 +762,21 @@ public class TencentCloudImUtil {
|
||||
return msgBody;
|
||||
}
|
||||
|
||||
public String changeOldUrlToNew(String url){
|
||||
public String changeOldUrlToNew(String url) {
|
||||
String newUrl = "";
|
||||
if(url.contains("https://cn.imrich.qcloud.com")){
|
||||
if (url.contains("https://cn.imrich.qcloud.com")) {
|
||||
newUrl = url.replace("https://cn.imrich.qcloud.com", "http://101.201.149.156:8609/qc");
|
||||
}
|
||||
if(url.contains("https://cos.ap-guangzhou.myqcloud.com")){
|
||||
if (url.contains("https://cos.ap-guangzhou.myqcloud.com")) {
|
||||
newUrl = url.replace("https://cos.ap-guangzhou.myqcloud.com", "http://101.201.149.156:8609/gmc");
|
||||
}
|
||||
if(url.contains("https://cn.rich.my-imcloud.com")){
|
||||
if (url.contains("https://cn.rich.my-imcloud.com")) {
|
||||
newUrl = url.replace("https://cn.rich.my-imcloud.com", "http://101.201.149.156:8609/ic");
|
||||
}
|
||||
if(url.contains("https://cos.ap-shanghai.myqcloud.com")){
|
||||
if (url.contains("https://cos.ap-shanghai.myqcloud.com")) {
|
||||
newUrl = url.replace("https://cos.ap-shanghai.myqcloud.com", "http://101.201.149.156:8609/smc");
|
||||
}
|
||||
if(url.contains("https://cos.ap-shanghai.tencentcos.cn")){
|
||||
if (url.contains("https://cos.ap-shanghai.tencentcos.cn")) {
|
||||
newUrl = url.replace("https://cos.ap-shanghai.tencentcos.cn", " http://101.201.149.156:8609/tc");
|
||||
}
|
||||
return newUrl;
|
||||
@@ -781,10 +794,8 @@ public class TencentCloudImUtil {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public Map<String,String> changeUrelArray(List<String> urlArray, String msgType) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
public Map<String, String> changeUrelArray(List<String> urlArray, String msgType) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (CollectionUtil.isNotEmpty(urlArray)) {
|
||||
if (msgType != null) {
|
||||
String flieName = UUID.randomUUID().toString();
|
||||
@@ -801,7 +812,7 @@ public class TencentCloudImUtil {
|
||||
fileInputStream = new FileInputStream(fileByUrl);
|
||||
String url = MyUploadUtil.upload(fileInputStream, bizPath, flieName + fileByUrl.getName());
|
||||
// 更新图片地址
|
||||
map.put(imgMsg,url);
|
||||
map.put(imgMsg, url);
|
||||
} catch (Exception ignored) {
|
||||
// 如果出异常了,就不更新聊天记录的图片了
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user