...
|
...
|
@@ -6,7 +6,9 @@ import com.yoho.core.common.utils.DateUtil; |
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.message.dal.IMiniSubscribeDAO;
|
|
|
import com.yoho.message.dal.IMiniappMsgFormDAO;
|
|
|
import com.yoho.message.dal.model.MiniSubscribe;
|
|
|
import com.yoho.message.dal.model.MiniappMsgForm;
|
|
|
import com.yoho.service.model.msgcenter.wechat.MiniappMsgReqBO;
|
|
|
import com.yoho.yhmessage.constants.RedisCacheKeyConstant;
|
...
|
...
|
@@ -42,6 +44,8 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
|
@Value("${miniapp.send.tempalte:/cgi-bin/message/wxopen/template/send?}")
|
|
|
private String sendMsgTemplate;
|
|
|
|
|
|
private static final String sendSubscribeMsg = "/cgi-bin/message/subscribe/send?";
|
|
|
|
|
|
@Autowired
|
|
|
private IMiniappMsgFormDAO miniappMsgFormDAO;
|
|
|
|
...
|
...
|
@@ -49,7 +53,7 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
|
private IMiniAppAccessTokenService miniAppAccessTokenService;
|
|
|
|
|
|
public String getMsgSendUrl(){
|
|
|
return wechatHost + sendMsgTemplate;
|
|
|
return wechatHost + sendSubscribeMsg;
|
|
|
}
|
|
|
|
|
|
@Autowired
|
...
|
...
|
@@ -64,6 +68,9 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
|
@Autowired
|
|
|
private IFilterSensitiveWordService filterSensitiveWordService;
|
|
|
|
|
|
@Autowired
|
|
|
private IMiniSubscribeDAO miniSubscribeDAO;
|
|
|
|
|
|
/**
|
|
|
* 发送小程序模板消息
|
|
|
* @param reqBO
|
...
|
...
|
@@ -78,10 +85,7 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
|
}
|
|
|
|
|
|
//过滤敏感词目前只过滤了‘测试’相关字眼,以后若要加敏感词,则改为该方法过滤 将敏感词维护在 q_msg_system.message_sensitive_words 表中
|
|
|
/*if(filterSensitiveWordService.isContainSensitiveWord(reqBO.getData().toJSONString())){
|
|
|
logger.warn("sendMiniappMsg with sensitiveWord exist,reqBO is {}",reqBO);
|
|
|
return new JSONObject();
|
|
|
}*/
|
|
|
|
|
|
if(filterSensitiveWordService.checkTestWord(reqBO.getData().toJSONString())){
|
|
|
logger.warn("sendMiniappMsg with sensitiveWord exist,uid is {},reqBO is {}",reqBO.getUid(),reqBO);
|
|
|
return new JSONObject();
|
...
|
...
|
@@ -92,33 +96,40 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
|
throw new ServiceException(ServiceError.WECHAT_PARAM_ISNULL);
|
|
|
}
|
|
|
|
|
|
// 获取有效的formid
|
|
|
//判断该模板用户是否已经订阅
|
|
|
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
|
|
|
/* // 新获取的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, miniappMsgForm);
|
|
|
JSONObject result = sendMsgUpdateDB(reqBO, miniSubscribe);
|
|
|
|
|
|
// token过期重新获取
|
|
|
if (result == null || result.getInteger("errcode") == 40001){
|
|
|
logger.warn("retry send msg because error is {}, uid is {},reqBO is {}", result != null ? result.toJSONString() : null, reqBO.getUid(), reqBO);
|
|
|
if (result == null || (Integer)result.get("errcode") == 40001){
|
|
|
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, miniappMsgForm);
|
|
|
return sendMsgUpdateDB(reqBO, miniSubscribe);
|
|
|
}
|
|
|
// 过期的formId 和 不合法的formid
|
|
|
else if(result.getInteger("errcode") == 41028 || result.getInteger("errcode")== 41029){
|
|
|
logger.info("retry send msg because error is {}, uid is {},reqBO is {}", result.toJSONString(),reqBO.getUid(),reqBO);
|
|
|
miniappMsgForm.setAvailableTimes(0);
|
|
|
miniappMsgFormDAO.updateByPrimaryKey(miniappMsgForm);
|
|
|
|
|
|
// 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);
|
|
|
miniSubscribe.setAvailableTimes(0);
|
|
|
miniappMsgFormDAO.updateByPrimaryKey(miniSubscribe);
|
|
|
|
|
|
MiniappMsgForm miniappMsgFormNew = miniappMsgFormDAO.selectLastedAvailabByUid(reqBO.getUid(), reqBO.getMiniappType());
|
|
|
|
...
|
...
|
@@ -130,19 +141,20 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
|
}
|
|
|
|
|
|
return sendMsgUpdateDB(reqBO, miniappMsgFormNew);
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
private JSONObject sendMsgUpdateDB(MiniappMsgReqBO reqBO, MiniappMsgForm miniappMsgForm) {
|
|
|
private JSONObject sendMsgUpdateDB(MiniappMsgReqBO reqBO, MiniSubscribe miniSubscribe) {
|
|
|
reqBO.setTouser(miniSubscribe.getOpenId());
|
|
|
JSONObject result = sendTemplateMsg(reqBO);
|
|
|
|
|
|
if (result != null && result.getInteger("errcode") == 0){
|
|
|
miniappMsgForm.setAvailableTimes(miniappMsgForm.getAvailableTimes()-1);
|
|
|
miniappMsgFormDAO.updateByPrimaryKey(miniappMsgForm);
|
|
|
if (result != null && (Integer)result.get("errcode") == 0){
|
|
|
miniSubscribe.setAvailableTimes(miniSubscribe.getAvailableTimes()-1);
|
|
|
miniSubscribeDAO.updateMiniSubscribe("mini_subscribe_" + reqBO.getMiniappType(), miniSubscribe);
|
|
|
//miniappMsgFormDAO.updateByPrimaryKey(miniappMsgForm);
|
|
|
//发送成功,记入发送数至 redis
|
|
|
saveSendRedis(reqBO.getPage());
|
|
|
}
|
...
|
...
|
@@ -163,6 +175,7 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
|
String msgId = page.substring(index + MSG_ID_INDEX);
|
|
|
//组装key:日期,value部分为 以场景id为key的hash结构 设置超时时间2天
|
|
|
RedisKeyBuilder redisKey = RedisKeyBuilder.newInstance().appendFixed(RedisCacheKeyConstant.MINI_SEND_NUM_KEY).appendVar(DateUtil.getToday("yyyyMMdd"));
|
|
|
//todo 若是
|
|
|
long result = pushRedisService.hashIncrement(redisKey,msgId,1,TWO_DAYS_HOURS);
|
|
|
logger.info("saveSendRedis end with msgId is {},result is {}",msgId,result);
|
|
|
}catch (Exception e){
|
...
|
...
|
@@ -196,7 +209,6 @@ public class MiniServiceAppImpl implements IMiniAppService { |
|
|
bodyParam.put("touser", reqBO.getTouser());
|
|
|
bodyParam.put("template_id", reqBO.getTemplateId());
|
|
|
bodyParam.put("page", reqBO.getPage());
|
|
|
bodyParam.put("form_id", reqBO.getFormId());
|
|
|
bodyParam.put("data", reqBO.getData());
|
|
|
|
|
|
if (StringUtils.isNotBlank(reqBO.getEmphasisKeyword())){
|
...
|
...
|
|