Commit be8498f0 authored by shiyu's avatar shiyu

获取IM用户签名

parent 4f81a347
package com.wwdz.ch.admin.controller;
import com.alibaba.fastjson.JSON;
import com.wwdz.ch.admin.service.SysIMService;
import com.wwdz.ch.core.consts.ResultCode;
import com.wwdz.ch.core.entity.im.IMChatRequestDto;
import com.wwdz.ch.core.entity.im.SendChatMsgRequestDto;
import com.wwdz.ch.core.type.Result;
import com.xxdxxs.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 后台管理人工介入ai会话
*/
@RestController
@RequestMapping("/admin/sysIM")
public class SysIMController {
private static final Logger logger = LoggerFactory.getLogger(SysIMController.class);
@Autowired
SysIMService sysIMService;
@ApiOperation(value = "人工介入ai发送聊天消息")
@PostMapping("/sendChatMsg")
public Result sendChatMsg(@RequestBody SendChatMsgRequestDto dto) {
logger.info("【请求开始】人工介入ai发送聊天消息,请求参数:{}", JSON.toJSONString(dto));
if (!StringUtils.isAllNotEmpty(dto.getFromAccount(), dto.getToAccount(), dto.getMsgType())) {
return Result.failed(ResultCode.PARAM_ERROR);
}
return sysIMService.sendChatMsg(dto);
}
@ApiOperation(value = "获取用户签名")
@PostMapping("/getUserSig")
public Result getUserSig(@RequestBody IMChatRequestDto dto) {
logger.info("【请求开始】获取用户签名,请求参数:{}", JSON.toJSONString(dto));
if (StringUtils.isEmpty(dto.getUserId())) {
return Result.failed(ResultCode.PARAM_ERROR);
}
return sysIMService.getUserSig(dto);
}
}
package com.wwdz.ch.admin.impl;
import com.wwdz.ch.admin.service.SysIMService;
import com.wwdz.ch.core.entity.im.IMChatRequestDto;
import com.wwdz.ch.core.entity.im.SendChatMsgRequestDto;
import com.wwdz.ch.core.im.api.ConversationApi;
import com.wwdz.ch.core.im.api.TLSSigApi;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.IMUtil;
import com.xxdxxs.utils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Service
public class SysIMServiceImpl implements SysIMService {
private static final Logger logger = LoggerFactory.getLogger(SysIMServiceImpl.class);
@Autowired
ConversationApi conversationApi;
@Autowired
TLSSigApi tlsSigApi;
@Autowired
IMUtil imUtil;
@Override
public Result sendChatMsg(SendChatMsgRequestDto dto) {
try {
//转人工需要设置人工的id,放入自定义数据字段中
if (dto.getIsRealPersonAnswer() != null && dto.getIsRealPersonAnswer() == 1) {
dto.setCloudCustomData(JsonUtils.fromMap(new HashMap<String, Object>(){{put("realPersonId", dto.getRealPersonId());}}));
}
Result result = conversationApi.sendChatMsg(dto);
return result;
} catch (Exception e) {
logger.error("人工介入ai发送聊天消息失败:{}", e);
}
return Result.failed();
}
@Override
public Result getUserSig(IMChatRequestDto dto) {
try {
String userSig = tlsSigApi.getUserSig(imUtil.formatUserId(String.valueOf(dto.getUserId())));
Map<String, String> map = new HashMap<>();
map.put("userSig", userSig);
logger.info(">>>>>>>>>>>>> 获取用户签名 userId:{}, userSig:{} <<<<<<<<<<<<<", dto.getUserId(), userSig);
return Result.success(map);
} catch (Exception e) {
logger.error("获取用户签名失败:{}", e);
}
return Result.failed();
}
}
package com.wwdz.ch.admin.service;
import com.wwdz.ch.core.entity.im.IMChatRequestDto;
import com.wwdz.ch.core.entity.im.SendChatMsgRequestDto;
import com.wwdz.ch.core.type.Result;
public interface SysIMService {
/**
* 人工介入ai会话
* 发送会话消息
* @param dto
* @return
*/
Result sendChatMsg(SendChatMsgRequestDto dto);
/**
* 获取用户签名
* @param dto
* @return
*/
Result getUserSig(IMChatRequestDto dto);
}
......@@ -72,10 +72,8 @@ public class IMUtil {
msgContentMap.put("MsgType", IMEnum.MsgTypeEnum.getValueByCode(dto.getMsgType()));
msgContentMap.put("MsgContent", new HashMap(){{put("Text", dto.getMsgContent());}});
imChatMsg.setMsgBody(Arrays.asList(msgContentMap));
//转人工需要设置人工的id,放入自定义数据字段中
if (dto.getIsRealPersonAnswer() != null && dto.getIsRealPersonAnswer() == 1) {
imChatMsg.setCloudCustomData(JsonUtils.fromMap(new HashMap<String, Object>(){{put("realPersonId", dto.getRealPersonId());}}));
}
imChatMsg.setCloudCustomData(dto.getCloudCustomData());
return imChatMsg;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment