...
|
...
|
@@ -77,71 +77,36 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
|
*/
|
|
|
public JSONObject sendMiniappMsg(MiniappMsgReqBO reqBO){
|
|
|
logger.info("enter sendMiniappMsg with templateId is {},uid is {},reqBO is {}",reqBO.getTemplateId(),reqBO.getUid(),reqBO);
|
|
|
|
|
|
// 入口参数 order_code不能为空
|
|
|
if (StringUtils.isBlank(reqBO.getUid())){
|
|
|
logger.warn("sendMiniappMsg uid not exist, reqBO is {}", reqBO);
|
|
|
if (StringUtils.isBlank(reqBO.getUid()) || StringUtils.isBlank(reqBO.getTemplateId())){
|
|
|
logger.warn("sendMiniappMsg uid , reqBO is {}", reqBO);
|
|
|
throw new ServiceException(ServiceError.WECHAT_PARAM_ISNULL);
|
|
|
}
|
|
|
|
|
|
//过滤敏感词目前只过滤了‘测试’相关字眼,以后若要加敏感词,则改为该方法过滤 将敏感词维护在 q_msg_system.message_sensitive_words 表中
|
|
|
|
|
|
//过滤敏感词目前只过滤了‘测试’相关字眼
|
|
|
if(filterSensitiveWordService.checkTestWord(reqBO.getData().toJSONString())){
|
|
|
logger.warn("sendMiniappMsg with sensitiveWord exist,uid is {},reqBO is {}",reqBO.getUid(),reqBO);
|
|
|
return new JSONObject();
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isBlank(reqBO.getTemplateId())){
|
|
|
logger.warn("sendMiniappMsg template not exist, uid is {}, reqBO is {}",reqBO.getUid(), reqBO);
|
|
|
throw new ServiceException(ServiceError.WECHAT_PARAM_ISNULL);
|
|
|
}
|
|
|
|
|
|
//判断该模板用户是否已经订阅
|
|
|
MiniSubscribe miniSubscribe = miniSubscribeDAO.selectAvailableTemplateId("mini_subscribe_"+reqBO.getMiniappType(), Integer.valueOf(reqBO.getUid()), reqBO.getTemplateId());
|
|
|
if(miniSubscribe == null){
|
|
|
return new JSONObject();
|
|
|
}
|
|
|
/*// 获取有效的formid
|
|
|
MiniappMsgForm miniappMsgForm = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid(), reqBO.getMiniappType());
|
|
|
if (miniappMsgForm == null) {
|
|
|
logger.warn("validate form not exist, uid is {},reqBO is {}",reqBO.getUid(),reqBO);
|
|
|
return new JSONObject();
|
|
|
}*/
|
|
|
|
|
|
/* // 新获取的formid
|
|
|
if (!reqBO.getFormId().equals(miniappMsgForm.getFormId())){
|
|
|
logger.info("reset form id, uid is {},old formid is {}, new formid is {}", reqBO.getUid(),reqBO.getFormId(), miniappMsgForm.getFormId());
|
|
|
reqBO.setFormId(miniappMsgForm.getFormId());
|
|
|
}*/
|
|
|
|
|
|
// 发送消息
|
|
|
JSONObject result = sendMsgUpdateDB(reqBO, miniSubscribe);
|
|
|
|
|
|
// token过期重新获取
|
|
|
if (result == null || (Integer)result.get("errcode") == 40001){
|
|
|
// token过期重新获取
|
|
|
logger.warn("retry send msg because error is {}, uid is {},reqBO is {}", result != null ? result.toString() : null, reqBO.getUid(), reqBO);
|
|
|
miniAppAccessTokenService.deletAccessToken(reqBO.getMiniappType());
|
|
|
return sendMsgUpdateDB(reqBO, miniSubscribe);
|
|
|
}
|
|
|
|
|
|
// TODO用户拒绝订阅需清空订阅次数
|
|
|
/*// 过期的formId 和 不合法的formid
|
|
|
else if((Integer)result.get("errcode") == 41028 || (Integer)result.get("errcode")== 41029){
|
|
|
logger.info("retry send msg because error is {}, uid is {},reqBO is {}", result.toString(),reqBO.getUid(),reqBO);
|
|
|
}else if((Integer)result.get("errcode") == 43101){
|
|
|
// 返回用户拒绝订阅该模板,则将用户订阅次数清空
|
|
|
miniSubscribe.setAvailableTimes(0);
|
|
|
miniappMsgFormDAO.updateByPrimaryKey(miniSubscribe);
|
|
|
|
|
|
MiniappMsgForm miniappMsgFormNew = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid(), reqBO.getMiniappType());
|
|
|
|
|
|
if (miniappMsgFormNew == null
|
|
|
|| StringUtils.isBlank(miniappMsgFormNew.getFormId())
|
|
|
|| StringUtils.isBlank(miniappMsgFormNew.getOpenId())){
|
|
|
logger.warn("validate form not exist, uid is {}, req is {}",reqBO.getUid(),reqBO);
|
|
|
return new JSONObject();
|
|
|
}
|
|
|
|
|
|
return sendMsgUpdateDB(reqBO, miniappMsgFormNew);
|
|
|
}*/
|
|
|
miniSubscribe.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
miniSubscribeDAO.updateMiniSubscribe("mini_subscribe_" + reqBO.getMiniappType(), miniSubscribe);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
...
|
...
|
@@ -153,8 +118,8 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
|
JSONObject result = sendTemplateMsg(reqBO);
|
|
|
if (result != null && (Integer)result.get("errcode") == 0){
|
|
|
miniSubscribe.setAvailableTimes(miniSubscribe.getAvailableTimes()-1);
|
|
|
miniSubscribe.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
miniSubscribeDAO.updateMiniSubscribe("mini_subscribe_" + reqBO.getMiniappType(), miniSubscribe);
|
|
|
//miniappMsgFormDAO.updateByPrimaryKey(miniappMsgForm);
|
|
|
//发送成功,记入发送数至 redis
|
|
|
saveSendRedis(reqBO.getPage());
|
|
|
}
|
...
|
...
|
|