zoujiajian před 1 rokem
rodič
revize
7392b14e73

+ 41 - 27
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpServiceImpl.java

@@ -571,10 +571,8 @@ public class CorpServiceImpl implements CorpService {
 		String openKfId = corpKfAccount.getOpenKfId();
 		WxCpKfMsgListResp wxCpKfMsgListResp = wxCorpOps.syncMsg(corpId, cursor, token, limit, openKfId);
 		List<WxCpKfMsgListResp.WxCpKfMsgItem> msgList = wxCpKfMsgListResp.getMsgList();
-		List<WxCpKfMsgListResp.WxCpKfMsgItem> enterSessionList = null;
-		List<WxCpKfMsgListResp.WxCpKfMsgItem> sessionStatusChanges = null;
 		for (WxCpKfMsgListResp.WxCpKfMsgItem item : msgList) {
-			if (item.getEvent() != null && item.getEvent().getEventType().equals("enter_session")) {
+			if (item.getEvent() != null) {
 				//会话事件
 				if (item.getEvent().getEventType().equals("enter_session")) {
 					//进入会话事件
@@ -598,43 +596,29 @@ public class CorpServiceImpl implements CorpService {
 	}
 
 	private void syncKfChatMsg(WxCpKfMsgListResp.WxCpKfMsgItem item) throws Exception {
-		String openKfid = item.getOpenKfid();
-		//客户id
-		String externalUserId = item.getExternalUserId();
-		//接待人员id
-		String servicerUserId = item.getServicerUserId();
-		//消息来源。3-微信客户发送的消息 4-系统推送的事件消息 5-接待人员在企业微信客户端发送的消息
-		Integer origin = item.getOrigin();
-		//发送时间
-		Long sendTime = item.getSendTime();
-		//消息id
-		String msgId = item.getMsgId();
-		//消息类型
-		String msgType = item.getMsgType();
 		CorpKfAccountSessionChat corpKfAccountSessionChat = new CorpKfAccountSessionChat();
-		corpKfAccountSessionChat.setOpenKfId(openKfid);
-		corpKfAccountSessionChat.setMsgid(msgId);
-		corpKfAccountSessionChat.setServicerUserid(servicerUserId);
-		corpKfAccountSessionChat.setExternalUserid(externalUserId);
-		corpKfAccountSessionChat.setOrign(origin);
-		corpKfAccountSessionChat.setMsgType(msgType);
-		corpKfAccountSessionChat.setSendTime(sendTime);
-		corpKfAccountSessionChat.setSendDate(DateTime.of(sendTime * 1000));
+		Boolean record = false;
 		//文本
 		if (item.getText() != null) {
 			corpKfAccountSessionChat.setMsgContent(item.getText().getContent());
+			record = true;
 		} else if (item.getMergedMsg() != null) {
 			//聊天记录 转发
+			corpKfAccountSessionChat.setLinkTitle(item.getMergedMsg().getTitle());
 			corpKfAccountSessionChat.setMsgContent(Jsons.toJson(item.getMergedMsg().getItem()));
+			record = true;
 		} else if (item.getVideo() != null) {
 			//视频记录
 			setMediaUrl(corpKfAccountSessionChat, item.getVideo().getMedia_id());
+			record = true;
 		} else if (item.getFile() != null) {
 			//文件
 			setMediaUrl(corpKfAccountSessionChat, item.getFile().getMedia_id());
+			record = true;
 		} else if (item.getImage() != null) {
 			//图片
 			setMediaUrl(corpKfAccountSessionChat, item.getImage().getMedia_id());
+			record = true;
 		} else if (item.getLink() != null) {
 			//链接
 			WxCorpLinkMsg link = item.getLink();
@@ -642,12 +626,37 @@ public class CorpServiceImpl implements CorpService {
 			corpKfAccountSessionChat.setLinkDesc(link.getDesc());
 			corpKfAccountSessionChat.setLinkUrl(link.getUrl());
 			corpKfAccountSessionChat.setLinkPicUrl(link.getPic_url());
+			record = true;
 		} else if (item.getMsgmenu() != null) {
 			//菜单 结束语统计
-
+			corpKfAccountSessionChat.setMsgContent(Jsons.toJson(item.getMsgmenu()));
+			record = true;
+		}
+		if (record) {
+			//新增
+			String openKfid = item.getOpenKfid();
+			//客户id
+			String externalUserId = item.getExternalUserId();
+			//接待人员id
+			String servicerUserId = item.getServicerUserId();
+			//消息来源。3-微信客户发送的消息 4-系统推送的事件消息 5-接待人员在企业微信客户端发送的消息
+			Integer origin = item.getOrigin();
+			//发送时间
+			Long sendTime = item.getSendTime();
+			//消息id
+			String msgId = item.getMsgId();
+			//消息类型
+			String msgType = item.getMsgType();
+			corpKfAccountSessionChat.setOpenKfId(openKfid);
+			corpKfAccountSessionChat.setMsgid(msgId);
+			corpKfAccountSessionChat.setServicerUserid(servicerUserId);
+			corpKfAccountSessionChat.setExternalUserid(externalUserId);
+			corpKfAccountSessionChat.setOrign(origin);
+			corpKfAccountSessionChat.setMsgType(msgType);
+			corpKfAccountSessionChat.setSendTime(sendTime);
+			corpKfAccountSessionChat.setSendDate(DateTime.of(sendTime * 1000));
+			saveChatMsg(corpKfAccountSessionChat);
 		}
-		//新增
-		saveChatMsg(corpKfAccountSessionChat);
 	}
 
 	private void syncSessionSatisfaction(String openKfId, List<WxCpKfMsgListResp.WxCpKfMsgItem> textList, String corpId, CorpKfAccountSessionConfig corpKfAccountSessionConfig) throws Exception {
@@ -798,6 +807,11 @@ public class CorpServiceImpl implements CorpService {
 				}
 			}
 		}
+		//查询用户会话状态 0待处理就进行处理
+		Integer sessionStatus = wxCorpOps.getCorpKfSessionStatus(corpId, openKfId, event.getExternalUserId());
+		if (sessionStatus != 0) {
+			return;
+		}
 		//用户是否已有会话
 		Integer selectCount = corpKfServicerSessionRecordMapper.selectCount(Wrappers.lambdaQuery(CorpKfServicerSessionRecord.class)
 				.eq(CorpKfServicerSessionRecord::getOpenKfId, openKfId)

+ 10 - 34
netflix-service/src/main/java/com/cyksj/service/corp/impl/WxCorpOpsImpl.java

@@ -41,6 +41,8 @@ import java.io.File;
 import java.net.URLEncoder;
 import java.net.http.HttpRequest;
 import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.*;
 
 /*
@@ -1165,40 +1167,14 @@ public class WxCorpOpsImpl implements WxCorpOps {
 			fileName = contentDisposition.substring(contentDisposition.indexOf("filename=") + 9).replace("\"", "");
 		}
 		byte[] body = res.body();
-		File file = new File(System.currentTimeMillis() + "." + StrUtil.subAfter(fileName, StrUtil.DOT, true));
-		FileImageOutputStream imageOutput = new FileImageOutputStream(file);
-
-		imageOutput.write(body, 0, body.length);
-		//关闭流
-		imageOutput.flush();
-		Map<String, Object> paramMap = new HashMap<>();
-		//文件上传只需将参数中的键指定(默认file),值设为文件对象即可,对于使用者来说,文件上传与普通表单提交并无区别
-		paramMap.put("file", FileUtil.file(file.getAbsolutePath()));
-		String result= HttpUtil.post(" https://files.yicanggongyi.com/pic/ups?ossAccount=Sx", paramMap);
-		FileUtil.del(file);
-		return JSONUtil.parseObj(result).getJSONObject("value").getJSONArray("saved").getJSONObject(0).getJSONObject("info").getStr("cdnUrl");
-	}
-
-	public static void main(String[] args) throws Exception {
-		String accessToken = "cLKd5cAJOW_0OW2Dv0Lk91_cbYBhUrKDfk-DOwdf2395J6yxoshl9BEpVIq0s4vXunYLDA8IU6-fz8ZN4yZRAARFdXEhcS8Hi9LdXhjYLqD8fGtCr2AV7ZkXOGAMzbyWDbPUERRcERE9Zp3nWnIl4xS7IBJx3AHcujPVDyqxocKRrvtBP3Rv-7QH6yU81p-VF-AdteZMrCkLC_kjFiloQg";
-		String url = "https://qyapi.weixin.qq.com/cgi-bin/kf/service_state/get?access_token=" + accessToken;
-		JSONObject jsonObject = new JSONObject();
-		jsonObject.putOpt("open_kfid", "wkvj2DPQAAS0g4Ik06VjeqGL2VTUGggg");
-		jsonObject.putOpt("external_userid", "wmvj2DPQAAWBEnCK39MVr7EO3eoxIgg");
-		HttpResponse<String> res =
-				J11HttpC.custom()
-						.ofPost()
-						.url(url)
-						.headers(J11HttpC.ReqType.raw_json)
-						.body(HttpRequest.BodyPublishers.ofString(Jsons.toJson(jsonObject), IoKit.Charsets.UTF_8.getCharset()))
-						.send(HttpResponse.BodyHandlers.ofString());
-		if (200 != res.statusCode()) {
-			throw BusinessRuntimeException.getInstance("用户会话状态消息: " + res.body());
+		Path tempFile = Files.createTempFile("media" + System.currentTimeMillis(), StrUtil.subAfter(fileName, StrUtil.DOT, true));
+		try (FileImageOutputStream imageOutput = new FileImageOutputStream(tempFile.toFile())) {
+			imageOutput.write(body, 0, body.length);
 		}
-		JSONObject re = Jsons.parseObject(res.body(), JSONObject.class);
-		if (re.getInt("errcode") != 0) {
-			throw BusinessRuntimeException.getInstance("添加接待人员信息错误: " + re.getStr("errmsg"));
-		}
-		System.out.println(re.getInt("service_state"));
+		Map<String, Object> paramMap = new HashMap<>();
+		paramMap.put("file", tempFile.toFile());
+		JSONObject result = JSONUtil.parseObj(HttpUtil.post("https://files.liuliangbang.vip/pic/ups", paramMap));
+		FileUtil.del(tempFile);
+		return result.getJSONObject("value").getJSONArray("saved").getJSONObject(0).getJSONObject("info").getStr("cdnUrl");
 	}
 }