|
@@ -18,8 +18,13 @@ import com.cyksj.config.corp.YHLXWxCorpConfig;
|
|
|
import com.cyksj.dto.CorpOauth2UserInfo;
|
|
import com.cyksj.dto.CorpOauth2UserInfo;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
import com.cyksj.mapper.corp.*;
|
|
import com.cyksj.mapper.corp.*;
|
|
|
|
|
+import com.cyksj.mapper.corp.kf.CorpKfAccountMapper;
|
|
|
|
|
+import com.cyksj.mapper.corp.kf.CorpKfAccountSessionConfigMapper;
|
|
|
import com.cyksj.model.dto.WxCorpEncryptDto;
|
|
import com.cyksj.model.dto.WxCorpEncryptDto;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
|
|
+import com.cyksj.model.kf.WxCorpKfMsgSendRequest;
|
|
|
|
|
+import com.cyksj.model.kf.WxCpKfEventMsg;
|
|
|
|
|
+import com.cyksj.model.kf.WxCpKfMsgListResp;
|
|
|
import com.cyksj.model.request.corp.Attachments;
|
|
import com.cyksj.model.request.corp.Attachments;
|
|
|
import com.cyksj.model.request.corp.CorpXmlMessage;
|
|
import com.cyksj.model.request.corp.CorpXmlMessage;
|
|
|
import com.cyksj.model.request.corp.CorpXmlOutMessage;
|
|
import com.cyksj.model.request.corp.CorpXmlOutMessage;
|
|
@@ -46,6 +51,7 @@ import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
*项目名: netflix
|
|
*项目名: netflix
|
|
@@ -97,6 +103,12 @@ public class CorpServiceImpl implements CorpService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private CorpUserFollowRelationMapper corpUserFollowRelationMapper;
|
|
private CorpUserFollowRelationMapper corpUserFollowRelationMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CorpKfAccountMapper corpKfAccountMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CorpKfAccountSessionConfigMapper corpKfAccountSessionConfigMapper;
|
|
|
|
|
+
|
|
|
@PostConstruct
|
|
@PostConstruct
|
|
|
private void init() {
|
|
private void init() {
|
|
|
corpMessageRouter = new CorpMessageRouter(this)
|
|
corpMessageRouter = new CorpMessageRouter(this)
|
|
@@ -208,6 +220,16 @@ public class CorpServiceImpl implements CorpService {
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
.end()
|
|
.end()
|
|
|
|
|
+ //企业微信客服 用户进入会话事件
|
|
|
|
|
+ .rule().async(false).msgType("event").event("kf_msg_or_event")
|
|
|
|
|
+ .handler(new CorpMessageHandler() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CorpXmlOutMessage handle(CorpXmlMessage message, Map<String, Object> context, CorpService corpService) throws Exception {
|
|
|
|
|
+ //
|
|
|
|
|
+ return kfMsgOrEvent(message, context);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .end()
|
|
|
;
|
|
;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -489,4 +511,70 @@ public class CorpServiceImpl implements CorpService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 企业微信客服 时间消息回调
|
|
|
|
|
+ */
|
|
|
|
|
+ private CorpXmlOutMessage kfMsgOrEvent(CorpXmlMessage message, Map<String, Object> context) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String openKfId = message.getOpenKfId();
|
|
|
|
|
+ WxCpKfMsgListResp wxCpKfMsgListResp = wxCorpOps.syncMsg(message.getToUserName(), null, message.getToken(), null, openKfId);
|
|
|
|
|
+ List<WxCpKfMsgListResp.WxCpKfMsgItem> msgList = wxCpKfMsgListResp.getMsgList();
|
|
|
|
|
+ //欢迎语
|
|
|
|
|
+ sendWelcomeMsg(message, msgList);
|
|
|
|
|
+ //消息发送失败事件
|
|
|
|
|
+ //拒收客户消息变更事件
|
|
|
|
|
+ //同步客服聊天记录
|
|
|
|
|
+ syncChatMsg(message, msgList);
|
|
|
|
|
+ //发送
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("企业微信客服 事件消息回调 错误");
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance(StringUtil.getErrorMsg(e));
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 微信客服欢迎语
|
|
|
|
|
+ */
|
|
|
|
|
+ public void sendWelcomeMsg(CorpXmlMessage message, List<WxCpKfMsgListResp.WxCpKfMsgItem> msgList) throws Exception {
|
|
|
|
|
+ String openKfId = message.getOpenKfId();
|
|
|
|
|
+ List<WxCpKfMsgListResp.WxCpKfMsgItem> enterSessionList = msgList.stream()
|
|
|
|
|
+ .filter((item) -> item.getEvent() != null && item.getEvent().getEventType().equals("enter_session")).collect(Collectors.toList());
|
|
|
|
|
+ //欢迎语
|
|
|
|
|
+ if (enterSessionList.size() > 0) {
|
|
|
|
|
+ WxCpKfMsgListResp.WxCpKfMsgItem wxCpKfMsgItem = enterSessionList.get(enterSessionList.size() - 1);
|
|
|
|
|
+ WxCpKfEventMsg event = wxCpKfMsgItem.getEvent();
|
|
|
|
|
+ String welcomeCode = event.getWelcomeCode();
|
|
|
|
|
+ CorpKfAccount corpKfAccount = corpKfAccountMapper.selectOne(Wrappers.lambdaQuery(CorpKfAccount.class)
|
|
|
|
|
+ .eq(CorpKfAccount::getOpenKfId, openKfId)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (corpKfAccount == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ WxCorpKfMsgSendRequest wxCpKfMsgSendRequest = new WxCorpKfMsgSendRequest();
|
|
|
|
|
+ wxCpKfMsgSendRequest.setMsgType("text");
|
|
|
|
|
+ wxCpKfMsgSendRequest.setCode(welcomeCode);
|
|
|
|
|
+ WxCorpKfMsgSendRequest.WxCpKfTextMsg textMsg = new WxCorpKfMsgSendRequest.WxCpKfTextMsg();
|
|
|
|
|
+ //账号会话设置
|
|
|
|
|
+ CorpKfAccountSessionConfig corpKfAccountSessionConfig = corpKfAccountSessionConfigMapper.selectOne(Wrappers.lambdaQuery(CorpKfAccountSessionConfig.class)
|
|
|
|
|
+ .eq(CorpKfAccountSessionConfig::getOpenKfId, openKfId)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (corpKfAccountSessionConfig == null) {
|
|
|
|
|
+ log.info("openKfId:{}未设置会话设置", openKfId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.isEmpty(corpKfAccountSessionConfig.getWelcomeContent())) {
|
|
|
|
|
+ log.info("openKfId:{}未设置会话欢迎语设置", openKfId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ textMsg.setContent(corpKfAccountSessionConfig.getWelcomeContent());
|
|
|
|
|
+ wxCpKfMsgSendRequest.setText(textMsg);
|
|
|
|
|
+ wxCpKfMsgSendRequest.setToUser(welcomeCode);
|
|
|
|
|
+ wxCpKfMsgSendRequest.setOpenKfid(event.getOpenKfid());
|
|
|
|
|
+ wxCorpOps.sendMsgOnEvent(message.getToUserName(), wxCpKfMsgSendRequest);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("企业微信客服 事件消息回调 时间内容为空.");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|