通过openid给用户推送模板消息
if(templateSendExecutor.isShutdown()){
this.initThreadPoolExecutor();
}
openids.stream().filter(StringUtils::isNotEmpty).forEach(openid -> {
templateSendExecutor.execute(() ->{
try {
//公众号发送模板消息
this.sendTemplateMsg(detailDto.getThirdPartTemplateId(), openid, sendUrl, buildTemplateData(detailDto.getParams()));
}catch (WxErrorException e){
log.error("send template msg error,openid:{}",openid,e);
if(e.getError().getErrorCode() == WxMpErrorMsgEnum.CODE_45009.getCode()){
log.error("=========模板推送当日调用上限=========");
templateSendExecutor.shutdownNow();
}
}
});
});
@PostConstruct
public void initThreadPoolExecutor(){
templateSendExecutor = new ThreadPoolExecutor(0, 8, 30,
TimeUnit.SECONDS, new LinkedBlockingQueue<>(1000),new ThreadPoolExecutor.CallerRunsPolicy());
}