|
@@ -63,7 +63,83 @@ public class WechatCustomerServiceImpl implements WechatCustomerService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void callbackSendMsgOnEvent(String wechatEncrypt) throws Exception {
|
|
|
|
|
|
|
+ public void callbackSendMsgOnEventOld(String wechatEncrypt) throws Exception {
|
|
|
|
|
+ log.info("回调参数为{}", wechatEncrypt);
|
|
|
|
|
+ WechatEncryptVo wechatEncryptVo = xmlMapper.readValue(wechatEncrypt, WechatEncryptVo.class);
|
|
|
|
|
+ WxCryptUtil wxCryptUtil = wechatCustomerComponents.getWxCryptUtil();
|
|
|
|
|
+ log.info("解密参数为{}", wechatEncryptVo.getEncrypt());
|
|
|
|
|
+ String encrypt = wxCryptUtil.decrypt(wechatEncryptVo.getEncrypt());
|
|
|
|
|
+ log.info("解密后的参数为{}", encrypt);
|
|
|
|
|
+ WechatCustomerCallbackVo wechatCustomerCallbackVo = xmlMapper.readValue(encrypt, WechatCustomerCallbackVo.class);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取消息
|
|
|
|
|
+ WxCpKfMsgListResp wxCpKfMsgListResp = wxCpKfService.syncMsg(null, wechatCustomerCallbackVo.getToken(), null, null, wechatCustomerCallbackVo.getOpenKfId());
|
|
|
|
|
+
|
|
|
|
|
+ while (wxCpKfMsgListResp.getHasMore() == 1) {
|
|
|
|
|
+ String nextCursor = wxCpKfMsgListResp.getNextCursor();
|
|
|
|
|
+ wxCpKfMsgListResp = wxCpKfService.syncMsg(nextCursor, wechatCustomerCallbackVo.getToken(), null, null, wechatCustomerCallbackVo.getOpenKfId());
|
|
|
|
|
+ }
|
|
|
|
|
+ List<WxCpKfMsgListResp.WxCpKfMsgItem> msgList = wxCpKfMsgListResp.getMsgList();
|
|
|
|
|
+ WxCpKfMsgListResp.WxCpKfMsgItem wxCpKfMsgItem = wxCpKfMsgListResp.getMsgList().get(msgList.size() - 1);
|
|
|
|
|
+
|
|
|
|
|
+ SysWechatCustomer sysWechatCustomer = sysWechatCustomerService.lambdaQuery().eq(SysWechatCustomer::getOpenKfId, wechatCustomerCallbackVo.getOpenKfId()).one();
|
|
|
|
|
+
|
|
|
|
|
+ distributedLockComponent.executeWithLock(wxCpKfMsgItem.getMsgId(), () -> {
|
|
|
|
|
+ // 改变会话状态
|
|
|
|
|
+ if (wxCpKfMsgItem.getOrigin() == 3) {
|
|
|
|
|
+ WxCpKfServiceStateResp serviceState;
|
|
|
|
|
+ try {
|
|
|
|
|
+ serviceState = wxCpKfService.getServiceState(wxCpKfMsgItem.getOpenKfid(), wxCpKfMsgItem.getExternalUserId());
|
|
|
|
|
+ } catch (WxErrorException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer state1 = serviceState.getServiceState();
|
|
|
|
|
+ if (state1 == 0 || state1 == 1) {
|
|
|
|
|
+ state1 = 3;
|
|
|
|
|
+ try {
|
|
|
|
|
+ wxCpKfService.transServiceState(wxCpKfMsgItem.getOpenKfid(), wxCpKfMsgItem.getExternalUserId(), state1, sysWechatCustomer.getReceptionistId());
|
|
|
|
|
+ } catch (WxErrorException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (wxCpKfMsgItem.getOrigin() == 4) {
|
|
|
|
|
+ // 发送欢迎语
|
|
|
|
|
+ WxCpKfEventMsg event = wxCpKfMsgItem.getEvent();
|
|
|
|
|
+ WxCpKfServiceStateResp serviceState = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ serviceState = wxCpKfService.getServiceState(event.getOpenKfid(), event.getExternalUserId());
|
|
|
|
|
+ } catch (WxErrorException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer state = serviceState.getServiceState();
|
|
|
|
|
+ if (ObjectUtils.isEmpty(event)) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ String scene = event.getScene();
|
|
|
|
|
+ if (!StringUtils.isEmpty(scene)) {
|
|
|
|
|
+ SysUser sysUser = sysUserService.getById(scene);
|
|
|
|
|
+ sysUser.setExternalUserId(event.getExternalUserId());
|
|
|
|
|
+ sysUserService.updateById(sysUser);
|
|
|
|
|
+ CustomerSendMsgOnEventRequest customerSendMsgOnEventRequest = CustomerSendMsgOnEventRequest.sendMsgOnEvent(sysUser, event.getWelcomeCode(), true);
|
|
|
|
|
+ wechatCustomerComponents.sendMsgOnEvent(customerSendMsgOnEventRequest);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (state == 0 || state == 1) {
|
|
|
|
|
+ state = 3;
|
|
|
|
|
+ List<SysWechatCustomer> list = sysWechatCustomerService.lambdaQuery().eq(SysWechatCustomer::getOpenKfId, wxCpKfMsgItem.getEvent().getOpenKfid()).list();
|
|
|
|
|
+ String receptionistId = list.get(0).getReceptionistId();
|
|
|
|
|
+ try {
|
|
|
|
|
+ wxCpKfService.transServiceState(wxCpKfMsgItem.getEvent().getOpenKfid(), wxCpKfMsgItem.getEvent().getExternalUserId(), state, receptionistId);
|
|
|
|
|
+ } catch (WxErrorException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 2, 2);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void callbackSendMsgOnEventNew(String wechatEncrypt) throws Exception {
|
|
|
log.info("回调参数为{}", wechatEncrypt);
|
|
log.info("回调参数为{}", wechatEncrypt);
|
|
|
WechatEncryptVo wechatEncryptVo = xmlMapper.readValue(wechatEncrypt, WechatEncryptVo.class);
|
|
WechatEncryptVo wechatEncryptVo = xmlMapper.readValue(wechatEncrypt, WechatEncryptVo.class);
|
|
|
WxCryptUtil wxCryptUtil = wechatCustomerComponents.getWxCryptUtil();
|
|
WxCryptUtil wxCryptUtil = wechatCustomerComponents.getWxCryptUtil();
|
|
@@ -171,9 +247,9 @@ public class WechatCustomerServiceImpl implements WechatCustomerService {
|
|
|
|
|
|
|
|
private void restTimeSendMsg(boolean workingHours, String externalUserId, String openKfId) {
|
|
private void restTimeSendMsg(boolean workingHours, String externalUserId, String openKfId) {
|
|
|
String message;
|
|
String message;
|
|
|
- if(!workingHours){
|
|
|
|
|
- message = "您好~当前客服暂时不在服务时间,服务时间为:周一至周五:8:30-12:00,14:00-18:30,周六至周日:9:00-12:00,14:00-18:30,当前未到服务时间,请您在服务时段内咨询~";
|
|
|
|
|
- }else {
|
|
|
|
|
|
|
+ if (!workingHours) {
|
|
|
|
|
+ message = "您好~当前客服暂时不在服务时间,服务时间为:周一至周五:8:30-12:00,14:00-18:30,周六至周日:9:00-12:00,14:00-18:30,当前未到服务时间,请您在服务时段内咨询~";
|
|
|
|
|
+ } else {
|
|
|
message = "您咨询的客服目前暂时不在服务时间,请您前往“晋掌柜App”点击“微信客服”,将为您安排新的客服为您提供服务~(客服服务时间:周一至周五 8:30-18:30,周六至周日 9:00-18:30,午间 12:00-14:00 休息)";
|
|
message = "您咨询的客服目前暂时不在服务时间,请您前往“晋掌柜App”点击“微信客服”,将为您安排新的客服为您提供服务~(客服服务时间:周一至周五 8:30-18:30,周六至周日 9:00-18:30,午间 12:00-14:00 休息)";
|
|
|
}
|
|
}
|
|
|
WxCpKfMsgSendRequest wxCpKfMsgSendRequest = new WxCpKfMsgSendRequest();
|
|
WxCpKfMsgSendRequest wxCpKfMsgSendRequest = new WxCpKfMsgSendRequest();
|