|
|
@ -150,10 +150,10 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
|
|
|
|
//获取accessToken
|
|
|
|
String clientTypeRedis = null; |
|
|
|
if (WxmpMessageConstant.RESI.equals(msg.getClientType())){ |
|
|
|
if (WxmpMessageConstant.RESI.equals(msg.getClientType())) { |
|
|
|
clientTypeRedis = WxmpMessageConstant.RESI; |
|
|
|
} |
|
|
|
if (WxmpMessageConstant.GOV_DB.equals(msg.getClientType())){ |
|
|
|
if (WxmpMessageConstant.GOV_DB.equals(msg.getClientType())) { |
|
|
|
clientTypeRedis = WxmpMessageConstant.GOV_REDIS; |
|
|
|
} |
|
|
|
StringBuilder key = new StringBuilder(msg.getCustomerId()).append(":").append(clientTypeRedis); |
|
|
@ -169,15 +169,30 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
} |
|
|
|
|
|
|
|
//获取模板id
|
|
|
|
if (WxmpMessageConstant.RESI.equals(clientType)) { |
|
|
|
templateId = wxmpResiUserSubscribeDao.getResiSubscribeTemplateId(openId, customerId); |
|
|
|
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) { |
|
|
|
templateId = wxmpWorkUserSubscribeDao.getWorkSubscribeTemplateId(openId, customerId); |
|
|
|
// if (WxmpMessageConstant.RESI.equals(clientType)) {
|
|
|
|
// templateId = wxmpResiUserSubscribeDao.getResiSubscribeTemplateId(openId, customerId);
|
|
|
|
// } else if (WxmpMessageConstant.GOV_DB.equals(clientType)) {
|
|
|
|
// templateId = wxmpWorkUserSubscribeDao.getWorkSubscribeTemplateId(openId, customerId);
|
|
|
|
// }
|
|
|
|
CustomerTemplateListFormDTO customerTemplateListFormDTO = new CustomerTemplateListFormDTO(); |
|
|
|
customerTemplateListFormDTO.setCustomerId(customerId); |
|
|
|
customerTemplateListFormDTO.setPublicId(WxmpMessageConstant.TEMPLATE_TYPE); |
|
|
|
List<CustomerTemplateListResultDTO> customerTemplateListResultDTOS = customerTemplateList(customerTemplateListFormDTO); |
|
|
|
if (customerTemplateListResultDTOS.size() > NumConstant.ZERO) { |
|
|
|
for (CustomerTemplateListResultDTO customerTemplateListResultDTO : customerTemplateListResultDTOS) { |
|
|
|
if (WxmpMessageConstant.GOV_REDIS.equals(customerTemplateListResultDTO.getClientType())){ |
|
|
|
customerTemplateListResultDTO.setClientType(WxmpMessageConstant.GOV_DB); |
|
|
|
} |
|
|
|
if (clientType.equals(customerTemplateListResultDTO.getClientType())) { |
|
|
|
templateId = customerTemplateListResultDTO.getTemplateId(); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
throw new WxSubscribeException("获取模板id失败", "", openId); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(templateId)) { |
|
|
|
throw new WxSubscribeException("获取模板id失败", "", openId); |
|
|
|
} |
|
|
|
|
|
|
|
//判断用户是否有次数
|
|
|
|
Integer count = null; |
|
|
|
if (WxmpMessageConstant.RESI.equals(clientType)) { |
|
|
@ -200,23 +215,30 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
jsonObject.put(WxmpMessageConstant.ACCESS_TOKEN, accessToken); |
|
|
|
jsonObject.put(WxmpMessageConstant.TOUSER, openId); |
|
|
|
jsonObject.put(WxmpMessageConstant.TEMPLATE_ID, templateId); |
|
|
|
//标题
|
|
|
|
String title = "您有一条" + msg.getBehaviorType(); |
|
|
|
JSONObject titleJson = new JSONObject(); |
|
|
|
titleJson.put("value", title.length() > WxmpMessageConstant.TITLE_LIMIT ? title.substring(0, WxmpMessageConstant.TITLE_LIMIT) : title); |
|
|
|
data.put(WxmpMessageConstant.TITLE, titleJson); |
|
|
|
//内容
|
|
|
|
JSONObject contentJson = new JSONObject(); |
|
|
|
contentJson.put("value", msg.getMessageContent().length() > WxmpMessageConstant.MESSAGE_CONTENT_LIMIT ? msg.getMessageContent().substring(0, WxmpMessageConstant.MESSAGE_CONTENT_LIMIT) : msg.getMessageContent()); |
|
|
|
data.put(WxmpMessageConstant.MESSAGE_CONTENT, contentJson); |
|
|
|
//时间
|
|
|
|
JSONObject timeJson = new JSONObject(); |
|
|
|
timeJson.put("value", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(msg.getMessageTime())); |
|
|
|
data.put(WxmpMessageConstant.MESSAGE_TIME,timeJson); |
|
|
|
data.put(WxmpMessageConstant.MESSAGE_TIME, timeJson); |
|
|
|
jsonObject.put(WxmpMessageConstant.DATA, data); |
|
|
|
EnvEnum envEnum = EnvEnum.getCurrentEnv(); |
|
|
|
//选填项
|
|
|
|
if (WxmpMessageConstant.RESI.equals(clientType)) { |
|
|
|
jsonObject.put(WxmpMessageConstant.PAGE, WxmpMessageConstant.PAGE_RESI); |
|
|
|
StringBuilder resiPage = new StringBuilder(WxmpMessageConstant.PAGE_URL); |
|
|
|
resiPage.append("?customerId=").append(customerId).append("&gridId=").append(msg.getGridId()); |
|
|
|
jsonObject.put(WxmpMessageConstant.PAGE, resiPage.toString()); |
|
|
|
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) { |
|
|
|
jsonObject.put(WxmpMessageConstant.PAGE, WxmpMessageConstant.PAGE_WORK); |
|
|
|
StringBuilder govPage = new StringBuilder(WxmpMessageConstant.PAGE_URL); |
|
|
|
govPage.append("?customerId=").append(customerId).append("&userId=").append(userId); |
|
|
|
jsonObject.put(WxmpMessageConstant.PAGE, govPage.toString()); |
|
|
|
} |
|
|
|
//开发环境
|
|
|
|
if ("dev".equals(envEnum.getCode())) { |
|
|
@ -266,7 +288,6 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
//抛出错误
|
|
|
|
throw new WxSubscribeException(String.valueOf(resultMap.get(WxmpMessageConstant.ERR_MSG)), templateId, openId); |
|
|
|
} |
|
|
|
|
|
|
|
succecssCount++; |
|
|
|
} catch (Exception e) { |
|
|
|
String errMsg = e.getMessage(); |
|
|
@ -297,6 +318,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
wxmpMsgSendRecordEntity.setCustomerId(msg.getCustomerId()); |
|
|
|
wxmpMsgSendRecordEntity.setClientType(msg.getClientType()); |
|
|
|
wxmpMsgSendRecordEntity.setTemplateId(templateId); |
|
|
|
wxmpMsgSendRecordEntity.setGridId(msg.getGridId()==null?"":msg.getGridId()); |
|
|
|
wxmpMsgSendRecordEntity.setUserId(msg.getUserId()); |
|
|
|
wxmpMsgSendRecordEntity.setWxOpenId(openId); |
|
|
|
wxmpMsgSendRecordEntity.setBehaviorType(msg.getBehaviorType()); |
|
|
@ -331,6 +353,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
List<GetTemplateListResultDTO> resultList = (List<GetTemplateListResultDTO>) mapToResult.getData(); |
|
|
|
return resultList; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @return |
|
|
|
* @Description 查询客户两个端小程序对应的站内信模板Id |
|
|
|