|
|
@ -90,8 +90,8 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
private WxmpUserSubscribeRecordDao subscribeRecordDao; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 保存系统授权信息 |
|
|
|
* @return void |
|
|
|
* @Description 保存系统授权信息 |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.21 17:29 |
|
|
|
*/ |
|
|
@ -139,7 +139,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
UserBasicInfoFormDTO userBasicInfoFormDTO = new UserBasicInfoFormDTO(); |
|
|
|
userBasicInfoFormDTO.setUserId(userId); |
|
|
|
openId = epmetUserOpenFeignClient.getUserBasicInfo(userBasicInfoFormDTO).getData().getOpenId(); |
|
|
|
} else if (WxmpMessageConstant.WORK.equals(clientType)) { |
|
|
|
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) { |
|
|
|
StaffBasicInfoFormDTO staffBasicInfoFormDTO = new StaffBasicInfoFormDTO(); |
|
|
|
staffBasicInfoFormDTO.setStaffId(userId); |
|
|
|
openId = epmetUserOpenFeignClient.getStaffBasicInfo(staffBasicInfoFormDTO).getData().getOpenId(); |
|
|
@ -155,7 +155,14 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
} |
|
|
|
|
|
|
|
//获取accessToken
|
|
|
|
StringBuilder key = new StringBuilder(msg.getCustomerId()).append(":").append(msg.getClientType()); |
|
|
|
String clientTypeRedis = null; |
|
|
|
if (WxmpMessageConstant.RESI.equals(msg.getClientType())){ |
|
|
|
clientTypeRedis = WxmpMessageConstant.RESI; |
|
|
|
} |
|
|
|
if (WxmpMessageConstant.GOV_DB.equals(msg.getClientType())){ |
|
|
|
clientTypeRedis = WxmpMessageConstant.GOV_REDIS; |
|
|
|
} |
|
|
|
StringBuilder key = new StringBuilder(msg.getCustomerId()).append(":").append(clientTypeRedis); |
|
|
|
Map<String, Object> authorizerRefreshToken = new HashMap<>(); |
|
|
|
try { |
|
|
|
authorizerRefreshToken = wxmpMessageRedis.getAuthorizerRefreshToken(key.toString()); |
|
|
@ -170,7 +177,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
//获取模板id
|
|
|
|
if (WxmpMessageConstant.RESI.equals(clientType)) { |
|
|
|
templateId = wxmpResiUserSubscribeDao.getResiSubscribeTemplateId(openId, customerId); |
|
|
|
} else if (WxmpMessageConstant.WORK.equals(clientType)) { |
|
|
|
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) { |
|
|
|
templateId = wxmpWorkUserSubscribeDao.getWorkSubscribeTemplateId(openId, customerId); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(templateId)) { |
|
|
@ -181,7 +188,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
Integer count = null; |
|
|
|
if (WxmpMessageConstant.RESI.equals(clientType)) { |
|
|
|
count = wxmpResiUserSubscribeDao.getResiSubscribeInfo(openId, templateId, customerId); |
|
|
|
} else if (WxmpMessageConstant.WORK.equals(clientType)) { |
|
|
|
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) { |
|
|
|
count = wxmpWorkUserSubscribeDao.getWorkSubscribeInfo(openId, templateId, customerId); |
|
|
|
} |
|
|
|
if (count == null) { |
|
|
@ -199,15 +206,22 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
jsonObject.put(WxmpMessageConstant.ACCESS_TOKEN, accessToken); |
|
|
|
jsonObject.put(WxmpMessageConstant.TOUSER, openId); |
|
|
|
jsonObject.put(WxmpMessageConstant.TEMPLATE_ID, templateId); |
|
|
|
data.put(WxmpMessageConstant.TITLE, new JSONObject().put("value", ("您有一条" + msg.getBehaviorType()).substring(0, WxmpMessageConstant.TITLE_LIMIT))); |
|
|
|
data.put(WxmpMessageConstant.MESSAGE_CONTENT, new JSONObject().put("value", msg.getMessageContent().substring(0, WxmpMessageConstant.MESSAGE_CONTENT_LIMIT))); |
|
|
|
data.put(WxmpMessageConstant.MESSAGE_TIME, new JSONObject().put("value", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(msg.getMessageTime()))); |
|
|
|
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); |
|
|
|
jsonObject.put(WxmpMessageConstant.DATA, data); |
|
|
|
EnvEnum envEnum = EnvEnum.getCurrentEnv(); |
|
|
|
//选填项
|
|
|
|
if (WxmpMessageConstant.RESI.equals(clientType)) { |
|
|
|
jsonObject.put(WxmpMessageConstant.PAGE, WxmpMessageConstant.PAGE_RESI); |
|
|
|
} else if (WxmpMessageConstant.WORK.equals(clientType)) { |
|
|
|
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) { |
|
|
|
jsonObject.put(WxmpMessageConstant.PAGE, WxmpMessageConstant.PAGE_WORK); |
|
|
|
} |
|
|
|
//开发环境
|
|
|
@ -229,7 +243,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
int decrease = 0; |
|
|
|
if (WxmpMessageConstant.RESI.equals(clientType)) { |
|
|
|
decrease = wxmpResiUserSubscribeDao.decreaseResiSubscribeCount(openId, templateId, customerId, 1); |
|
|
|
} else if (WxmpMessageConstant.WORK.equals(clientType)) { |
|
|
|
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) { |
|
|
|
decrease = wxmpWorkUserSubscribeDao.decreaseWorkSubscribeCount(openId, templateId, customerId, 1); |
|
|
|
} |
|
|
|
if (decrease == 0) { |
|
|
@ -247,7 +261,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
int clear = 0; |
|
|
|
if (WxmpMessageConstant.RESI.equals(clientType)) { |
|
|
|
clear = wxmpResiUserSubscribeDao.clearResiSubscribeCount(openId, templateId, customerId); |
|
|
|
} else if (WxmpMessageConstant.WORK.equals(clientType)) { |
|
|
|
} else if (WxmpMessageConstant.GOV_DB.equals(clientType)) { |
|
|
|
clear = wxmpWorkUserSubscribeDao.clearWorkSubscribeCount(openId, templateId, customerId); |
|
|
|
} |
|
|
|
if (clear == 0) { |
|
|
@ -256,7 +270,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
} |
|
|
|
|
|
|
|
//抛出错误
|
|
|
|
throw new WxSubscribeException(String.valueOf(resultMap.get(WxmpMessageConstant.ERR_MSG)),templateId, openId); |
|
|
|
throw new WxSubscribeException(String.valueOf(resultMap.get(WxmpMessageConstant.ERR_MSG)), templateId, openId); |
|
|
|
} |
|
|
|
|
|
|
|
succecssCount++; |
|
|
@ -310,7 +324,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
String url = "https://epmet-cloud.elinkservice.cn/api/third/personaltemplate/templatelist"; |
|
|
|
//String url = "http://localhost:8080/api/third/personaltemplate/templatelist";
|
|
|
|
String data = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(dto)).getData(); |
|
|
|
logger.info("ThirdLoginServiceImpl.getUserWeChat:httpclient->url:"+url+",结果->"+data); |
|
|
|
logger.info("ThirdLoginServiceImpl.getUserWeChat:httpclient->url:" + url + ",结果->" + data); |
|
|
|
JSONObject toResult = JSON.parseObject(data); |
|
|
|
Result mapToResult = ConvertUtils.mapToEntity(toResult, Result.class); |
|
|
|
if (null != toResult.get("code")) { |
|
|
@ -377,8 +391,8 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 保存居民端微信订阅信息 |
|
|
|
* @return void |
|
|
|
* @Description 保存居民端微信订阅信息 |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.22 09:56 |
|
|
|
*/ |
|
|
@ -404,8 +418,8 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 保存工作端订阅信息 |
|
|
|
* @return void |
|
|
|
* @Description 保存工作端订阅信息 |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.22 14:21 |
|
|
|
*/ |
|
|
@ -420,7 +434,7 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
insert.setWxOpenId(openId); |
|
|
|
insert.setWxSubscribeStatus(wxSubscribeStatus); |
|
|
|
wxmpWorkUserSubscribeDao.insert(insert); |
|
|
|
return ; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (WxMsgTemplateSubscribeStatus.SUBSCRIBE.equals(wxSubscribeStatus)) { |
|
|
@ -432,8 +446,8 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 根据UserId查询居民OpenId |
|
|
|
* @return string |
|
|
|
* @Description 根据UserId查询居民OpenId |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.22 13:35 |
|
|
|
*/ |
|
|
@ -442,18 +456,18 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
bif.setUserId(userId); |
|
|
|
Result<UserBasicInfo> result = epmetUserOpenFeignClient.getUserBasicInfo(bif); |
|
|
|
if (!result.success()) { |
|
|
|
throw new RenException(String.format("查询居民OpenId失败,userId:%s,错误信息:%s",userId , result.getInternalMsg())); |
|
|
|
throw new RenException(String.format("查询居民OpenId失败,userId:%s,错误信息:%s", userId, result.getInternalMsg())); |
|
|
|
} |
|
|
|
UserBasicInfo userBasicInfo = result.getData(); |
|
|
|
if (userBasicInfo == null) { |
|
|
|
throw new RenException(String.format("根据userId:%s,没有查询到居民OpenId",userId)); |
|
|
|
throw new RenException(String.format("根据userId:%s,没有查询到居民OpenId", userId)); |
|
|
|
} |
|
|
|
return userBasicInfo.getOpenId(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 查询工作人员openId |
|
|
|
* @return java.lang.String |
|
|
|
* @Description 查询工作人员openId |
|
|
|
* @author wxz |
|
|
|
* @date 2020.10.22 14:46 |
|
|
|
*/ |
|
|
@ -462,11 +476,11 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { |
|
|
|
form.setStaffId(userId); |
|
|
|
Result<StaffBasicInfo> result = epmetUserOpenFeignClient.getStaffBasicInfo(form); |
|
|
|
if (!result.success()) { |
|
|
|
throw new RenException(String.format("查询工作人员OpenId失败,userId:%s,错误信息:%s",userId , result.getInternalMsg())); |
|
|
|
throw new RenException(String.format("查询工作人员OpenId失败,userId:%s,错误信息:%s", userId, result.getInternalMsg())); |
|
|
|
} |
|
|
|
StaffBasicInfo staffBasicInfo = result.getData(); |
|
|
|
if (staffBasicInfo == null) { |
|
|
|
throw new RenException(String.format("根据userId:%s,没有查询到工作人员OpenId",userId)); |
|
|
|
throw new RenException(String.format("根据userId:%s,没有查询到工作人员OpenId", userId)); |
|
|
|
} |
|
|
|
return staffBasicInfo.getOpenId(); |
|
|
|
} |
|
|
|