| 
						
						
							
								
							
						
						
					 | 
					@ -19,32 +19,28 @@ package com.epmet.service.impl; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.alibaba.fastjson.JSON; | 
					 | 
					 | 
					import com.alibaba.fastjson.JSON; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.alibaba.fastjson.JSONObject; | 
					 | 
					 | 
					import com.alibaba.fastjson.JSONObject; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.constant.AppClientConstant; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.constant.NumConstant; | 
					 | 
					 | 
					import com.epmet.commons.tools.constant.NumConstant; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.enums.EnvEnum; | 
					 | 
					 | 
					import com.epmet.commons.tools.enums.EnvEnum; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.exception.RenException; | 
					 | 
					 | 
					import com.epmet.commons.tools.exception.RenException; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import com.epmet.commons.tools.exception.ValidateException; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.utils.ConvertUtils; | 
					 | 
					 | 
					import com.epmet.commons.tools.utils.ConvertUtils; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.utils.HttpClientManager; | 
					 | 
					 | 
					import com.epmet.commons.tools.utils.HttpClientManager; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.utils.Result; | 
					 | 
					 | 
					import com.epmet.commons.tools.utils.Result; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					import com.epmet.constant.WxMsgTemplateSubscribeStatus; | 
					 | 
					 | 
					import com.epmet.commons.tools.validator.ValidatorUtils; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.constant.WxmpMessageConstant; | 
					 | 
					 | 
					import com.epmet.constant.WxmpMessageConstant; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dao.WxmpResiUserSubscribeDao; | 
					 | 
					 | 
					import com.epmet.dao.WxmpResiUserSubscribeDao; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dao.WxmpTemplateMsgSubscribeStatusDao; | 
					 | 
					 | 
					import com.epmet.dao.WxmpTemplateMsgSubscribeStatusDao; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dao.WxmpUserSubscribeRecordDao; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dao.WxmpWorkUserSubscribeDao; | 
					 | 
					 | 
					import com.epmet.dao.WxmpWorkUserSubscribeDao; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dto.form.GetTemplateListFormDTO; | 
					 | 
					 | 
					import com.epmet.dto.form.GetTemplateListFormDTO; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dto.form.StaffBasicInfoFormDTO; | 
					 | 
					 | 
					import com.epmet.dto.form.StaffBasicInfoFormDTO; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dto.form.UserBasicInfoFormDTO; | 
					 | 
					 | 
					import com.epmet.dto.form.UserBasicInfoFormDTO; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dto.form.WxSubscribeMessageFormDTO; | 
					 | 
					 | 
					import com.epmet.dto.form.WxSubscribeMessageFormDTO; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dto.result.GetTemplateListResultDTO; | 
					 | 
					 | 
					import com.epmet.dto.result.GetTemplateListResultDTO; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					import com.epmet.dto.result.StaffBasicInfo; | 
					 | 
					 | 
					import com.epmet.entity.WxmpMsgSendRecordEntity; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					import com.epmet.dto.result.UserBasicInfo; | 
					 | 
					 | 
					import com.epmet.entity.WxmpTemplateMsgSubscribeStatusEntity; | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dto.result.WxMsgAuthInfoResultDTO; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.entity.*; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.exception.WxSubscribeException; | 
					 | 
					 | 
					import com.epmet.exception.WxSubscribeException; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.feign.EpmetUserOpenFeignClient; | 
					 | 
					 | 
					import com.epmet.feign.EpmetUserOpenFeignClient; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.redis.WxmpMessageRedis; | 
					 | 
					 | 
					import com.epmet.redis.WxmpMessageRedis; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.redis.WxmpMsgSendRecordRedis; | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.service.WxmpMessageService; | 
					 | 
					 | 
					import com.epmet.service.WxmpMessageService; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.service.WxmpMsgSendRecordService; | 
					 | 
					 | 
					import com.epmet.service.WxmpMsgSendRecordService; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import org.apache.commons.lang3.StringUtils; | 
					 | 
					 | 
					import org.apache.commons.lang3.StringUtils; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -54,6 +50,7 @@ import org.springframework.beans.factory.annotation.Autowired; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import org.springframework.stereotype.Service; | 
					 | 
					 | 
					import org.springframework.stereotype.Service; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import javax.annotation.Resource; | 
					 | 
					 | 
					import javax.annotation.Resource; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import java.text.ParseException; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.text.SimpleDateFormat; | 
					 | 
					 | 
					import java.text.SimpleDateFormat; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.util.Date; | 
					 | 
					 | 
					import java.util.Date; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.util.HashMap; | 
					 | 
					 | 
					import java.util.HashMap; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -68,25 +65,25 @@ import java.util.Map; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 */ | 
					 | 
					 | 
					 */ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					@Service | 
					 | 
					 | 
					@Service | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					public class WxmpMessageServiceImpl implements WxmpMessageService { | 
					 | 
					 | 
					public class WxmpMessageServiceImpl implements WxmpMessageService { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
						private Logger logger = LoggerFactory.getLogger(getClass()); | 
					 | 
					 | 
					    private Logger logger = LoggerFactory.getLogger(getClass()); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
						@Autowired | 
					 | 
					 | 
					    @Autowired | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						private WxmpTemplateMsgSubscribeStatusDao msgSubscribeStatusDao; | 
					 | 
					 | 
					    private WxmpTemplateMsgSubscribeStatusDao msgSubscribeStatusDao; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
						@Autowired | 
					 | 
					 | 
					    @Autowired | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						private EpmetUserOpenFeignClient epmetUserOpenFeignClient; | 
					 | 
					 | 
					    private EpmetUserOpenFeignClient epmetUserOpenFeignClient; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
						@Autowired | 
					 | 
					 | 
					    @Autowired | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						private WxmpMessageRedis wxmpMessageRedis; | 
					 | 
					 | 
					    private WxmpMessageRedis wxmpMessageRedis; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
						@Resource | 
					 | 
					 | 
					    @Resource | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						private WxmpResiUserSubscribeDao wxmpResiUserSubscribeDao; | 
					 | 
					 | 
					    private WxmpResiUserSubscribeDao wxmpResiUserSubscribeDao; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
						@Resource | 
					 | 
					 | 
					    @Resource | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						private WxmpWorkUserSubscribeDao wxmpWorkUserSubscribeDao; | 
					 | 
					 | 
					    private WxmpWorkUserSubscribeDao wxmpWorkUserSubscribeDao; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
						@Autowired | 
					 | 
					 | 
					    @Autowired | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						private WxmpMsgSendRecordService wxmpMsgSendRecordService; | 
					 | 
					 | 
					    private WxmpMsgSendRecordService wxmpMsgSendRecordService; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
						@Autowired | 
					 | 
					 | 
						@Autowired | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
						private WxmpUserSubscribeRecordDao subscribeRecordDao; | 
					 | 
					 | 
						private WxmpUserSubscribeRecordDao subscribeRecordDao; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -123,189 +120,189 @@ public class WxmpMessageServiceImpl implements WxmpMessageService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
							msgSubscribeStatusDao.insert(userSubscribeStatusEntity); | 
					 | 
					 | 
							msgSubscribeStatusDao.insert(userSubscribeStatusEntity); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
						} | 
					 | 
					 | 
						} | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
						/** | 
					 | 
					 | 
					    /** | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						 * @param msgList | 
					 | 
					 | 
					     * @param msgList | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						 * @return void | 
					 | 
					 | 
					     * @return void | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						 * @Description 发送订阅消息 | 
					 | 
					 | 
					     * @Description 发送订阅消息 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						 * @Author liushaowen | 
					 | 
					 | 
					     * @Author liushaowen | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						 * @Date 2020/10/21 15:34 | 
					 | 
					 | 
					     * @Date 2020/10/21 15:34 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						 */ | 
					 | 
					 | 
					     */ | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						@Override | 
					 | 
					 | 
					    @Override | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						public void sendWxSubscribeMessage(List<WxSubscribeMessageFormDTO> msgList) { | 
					 | 
					 | 
					    public void sendWxSubscribeMessage(List<WxSubscribeMessageFormDTO> msgList) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							logger.info("待发送订阅消息数量:{}", msgList.size()); | 
					 | 
					 | 
					        logger.info("待发送订阅消息数量:{}", msgList.size()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							int succecssCount = 0; | 
					 | 
					 | 
					        int succecssCount = 0; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							for (WxSubscribeMessageFormDTO msg : msgList) { | 
					 | 
					 | 
					        for (WxSubscribeMessageFormDTO msg : msgList) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
								try { | 
					 | 
					 | 
					            try { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									String userId = msg.getUserId(); | 
					 | 
					 | 
					                String userId = msg.getUserId(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									String clientType = msg.getClientType(); | 
					 | 
					 | 
					                String clientType = msg.getClientType(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									String customerId = msg.getCustomerId(); | 
					 | 
					 | 
					                String customerId = msg.getCustomerId(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									String templateId = null; | 
					 | 
					 | 
					                String templateId = null; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									String openId = null; | 
					 | 
					 | 
					                String openId = null; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									//通过userId获取openId
 | 
					 | 
					 | 
					                //通过userId获取openId
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									try { | 
					 | 
					 | 
					                try { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										if (WxmpMessageConstant.RESI.equals(clientType)) { | 
					 | 
					 | 
					                    if (WxmpMessageConstant.RESI.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											UserBasicInfoFormDTO userBasicInfoFormDTO = new UserBasicInfoFormDTO(); | 
					 | 
					 | 
					                        UserBasicInfoFormDTO userBasicInfoFormDTO = new UserBasicInfoFormDTO(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											userBasicInfoFormDTO.setUserId(userId); | 
					 | 
					 | 
					                        userBasicInfoFormDTO.setUserId(userId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											openId = epmetUserOpenFeignClient.getUserBasicInfo(userBasicInfoFormDTO).getData().getOpenId(); | 
					 | 
					 | 
					                        openId = epmetUserOpenFeignClient.getUserBasicInfo(userBasicInfoFormDTO).getData().getOpenId(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										} else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
					 | 
					 | 
					                    } else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											StaffBasicInfoFormDTO staffBasicInfoFormDTO = new StaffBasicInfoFormDTO(); | 
					 | 
					 | 
					                        StaffBasicInfoFormDTO staffBasicInfoFormDTO = new StaffBasicInfoFormDTO(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											staffBasicInfoFormDTO.setStaffId(userId); | 
					 | 
					 | 
					                        staffBasicInfoFormDTO.setStaffId(userId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											openId = epmetUserOpenFeignClient.getStaffBasicInfo(staffBasicInfoFormDTO).getData().getOpenId(); | 
					 | 
					 | 
					                        openId = epmetUserOpenFeignClient.getStaffBasicInfo(staffBasicInfoFormDTO).getData().getOpenId(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										} else { | 
					 | 
					 | 
					                    } else { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											throw new WxSubscribeException("clientType有误", "", openId); | 
					 | 
					 | 
					                        throw new WxSubscribeException("clientType有误", "", openId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										} | 
					 | 
					 | 
					                    } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} catch (Exception e) { | 
					 | 
					 | 
					                } catch (Exception e) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										throw new WxSubscribeException("连接User服务失败", "", ""); | 
					 | 
					 | 
					                    throw new WxSubscribeException("连接User服务失败", "", ""); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if (StringUtils.isBlank(openId)) { | 
					 | 
					 | 
					                if (StringUtils.isBlank(openId)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										throw new WxSubscribeException("openId获取失败", "", ""); | 
					 | 
					 | 
					                    throw new WxSubscribeException("openId获取失败", "", ""); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									//获取accessToken
 | 
					 | 
					 | 
					                //获取accessToken
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									StringBuilder key = new StringBuilder(msg.getCustomerId()).append(":").append(msg.getClientType()); | 
					 | 
					 | 
					                StringBuilder key = new StringBuilder(msg.getCustomerId()).append(":").append(msg.getClientType()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									Map<String, Object> authorizerRefreshToken = new HashMap<>(); | 
					 | 
					 | 
					                Map<String, Object> authorizerRefreshToken = new HashMap<>(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									try { | 
					 | 
					 | 
					                try { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										authorizerRefreshToken = wxmpMessageRedis.getAuthorizerRefreshToken(key.toString()); | 
					 | 
					 | 
					                    authorizerRefreshToken = wxmpMessageRedis.getAuthorizerRefreshToken(key.toString()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} catch (Exception e) { | 
					 | 
					 | 
					                } catch (Exception e) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										throw new WxSubscribeException("连接缓存服务器失败", "", openId); | 
					 | 
					 | 
					                    throw new WxSubscribeException("连接缓存服务器失败", "", openId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									String accessToken = (String) authorizerRefreshToken.get(WxmpMessageConstant.AUTHORIZER_ACCESS_TOKEN); | 
					 | 
					 | 
					                String accessToken = (String) authorizerRefreshToken.get(WxmpMessageConstant.AUTHORIZER_ACCESS_TOKEN); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if (StringUtils.isBlank(accessToken)) { | 
					 | 
					 | 
					                if (StringUtils.isBlank(accessToken)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										throw new WxSubscribeException("accessToken获取失败", "", openId); | 
					 | 
					 | 
					                    throw new WxSubscribeException("accessToken获取失败", "", openId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									//获取模板id
 | 
					 | 
					 | 
					                //获取模板id
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if (WxmpMessageConstant.RESI.equals(clientType)) { | 
					 | 
					 | 
					                if (WxmpMessageConstant.RESI.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										templateId = wxmpResiUserSubscribeDao.getResiSubscribeTemplateId(openId, templateId, customerId); | 
					 | 
					 | 
					                    templateId = wxmpResiUserSubscribeDao.getResiSubscribeTemplateId(openId, templateId, customerId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
					 | 
					 | 
					                } else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										templateId = wxmpWorkUserSubscribeDao.getWorkSubscribeTemplateId(openId, templateId, customerId); | 
					 | 
					 | 
					                    templateId = wxmpWorkUserSubscribeDao.getWorkSubscribeTemplateId(openId, templateId, customerId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if (StringUtils.isBlank(templateId)) { | 
					 | 
					 | 
					                if (StringUtils.isBlank(templateId)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										throw new WxSubscribeException("获取模板id失败", "", openId); | 
					 | 
					 | 
					                    throw new WxSubscribeException("获取模板id失败", "", openId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									//判断用户是否有次数
 | 
					 | 
					 | 
					                //判断用户是否有次数
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									Integer count = null; | 
					 | 
					 | 
					                Integer count = null; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if (WxmpMessageConstant.RESI.equals(clientType)) { | 
					 | 
					 | 
					                if (WxmpMessageConstant.RESI.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										count = wxmpResiUserSubscribeDao.getResiSubscribeInfo(openId, templateId, customerId); | 
					 | 
					 | 
					                    count = wxmpResiUserSubscribeDao.getResiSubscribeInfo(openId, templateId, customerId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
					 | 
					 | 
					                } else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										count = wxmpWorkUserSubscribeDao.getWorkSubscribeInfo(openId, templateId, customerId); | 
					 | 
					 | 
					                    count = wxmpWorkUserSubscribeDao.getWorkSubscribeInfo(openId, templateId, customerId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if (count == null) { | 
					 | 
					 | 
					                if (count == null) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										//用户未订阅
 | 
					 | 
					 | 
					                    //用户未订阅
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										throw new WxSubscribeException("用户未订阅", templateId, openId); | 
					 | 
					 | 
					                    throw new WxSubscribeException("用户未订阅", templateId, openId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if (count == 0) { | 
					 | 
					 | 
					                if (count == 0) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										throw new WxSubscribeException("用户可用额度不足", templateId, openId); | 
					 | 
					 | 
					                    throw new WxSubscribeException("用户可用额度不足", templateId, openId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									//发送消息
 | 
					 | 
					 | 
					                //发送消息
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									JSONObject jsonObject = new JSONObject(); | 
					 | 
					 | 
					                JSONObject jsonObject = new JSONObject(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									JSONObject data = new JSONObject(); | 
					 | 
					 | 
					                JSONObject data = new JSONObject(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									//必填项
 | 
					 | 
					 | 
					                //必填项
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									jsonObject.put(WxmpMessageConstant.ACCESS_TOKEN, accessToken); | 
					 | 
					 | 
					                jsonObject.put(WxmpMessageConstant.ACCESS_TOKEN, accessToken); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									jsonObject.put(WxmpMessageConstant.TOUSER, openId); | 
					 | 
					 | 
					                jsonObject.put(WxmpMessageConstant.TOUSER, openId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									jsonObject.put(WxmpMessageConstant.TEMPLATE_ID, templateId); | 
					 | 
					 | 
					                jsonObject.put(WxmpMessageConstant.TEMPLATE_ID, templateId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									data.put(WxmpMessageConstant.TITLE, new JSONObject().put("value", ("您有一条" + msg.getBehaviorType()).substring(0, WxmpMessageConstant.TITLE_LIMIT))); | 
					 | 
					 | 
					                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_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(new Date()))); | 
					 | 
					 | 
					                data.put(WxmpMessageConstant.MESSAGE_TIME, new JSONObject().put("value", new SimpleDateFormat("yyyy-MM-dd HH:mm").format(msg.getMessageTime()))); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									jsonObject.put(WxmpMessageConstant.DATA, data); | 
					 | 
					 | 
					                jsonObject.put(WxmpMessageConstant.DATA, data); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									EnvEnum envEnum = EnvEnum.getCurrentEnv(); | 
					 | 
					 | 
					                EnvEnum envEnum = EnvEnum.getCurrentEnv(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									//选填项
 | 
					 | 
					 | 
					                //选填项
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if (WxmpMessageConstant.RESI.equals(clientType)) { | 
					 | 
					 | 
					                if (WxmpMessageConstant.RESI.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										jsonObject.put(WxmpMessageConstant.PAGE, WxmpMessageConstant.PAGE_RESI); | 
					 | 
					 | 
					                    jsonObject.put(WxmpMessageConstant.PAGE, WxmpMessageConstant.PAGE_RESI); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
					 | 
					 | 
					                } else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										jsonObject.put(WxmpMessageConstant.PAGE, WxmpMessageConstant.PAGE_WORK); | 
					 | 
					 | 
					                    jsonObject.put(WxmpMessageConstant.PAGE, WxmpMessageConstant.PAGE_WORK); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									//开发环境
 | 
					 | 
					 | 
					                //开发环境
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if ("dev".equals(envEnum.getCode())) { | 
					 | 
					 | 
					                if ("dev".equals(envEnum.getCode())) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										jsonObject.put(WxmpMessageConstant.MINIPROGRAM_STATE, WxmpMessageConstant.STATE_DEV); | 
					 | 
					 | 
					                    jsonObject.put(WxmpMessageConstant.MINIPROGRAM_STATE, WxmpMessageConstant.STATE_DEV); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									//测试环境
 | 
					 | 
					 | 
					                //测试环境
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if ("test".equals(envEnum.getCode())) { | 
					 | 
					 | 
					                if ("test".equals(envEnum.getCode())) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										jsonObject.put(WxmpMessageConstant.MINIPROGRAM_STATE, WxmpMessageConstant.STATE_TEST); | 
					 | 
					 | 
					                    jsonObject.put(WxmpMessageConstant.MINIPROGRAM_STATE, WxmpMessageConstant.STATE_TEST); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									String resultStr = HttpClientManager.getInstance().sendPostByJSON(WxmpMessageConstant.SEND_MESSAGE + accessToken, JSON.toJSONString(jsonObject)).getData(); | 
					 | 
					 | 
					                String resultStr = HttpClientManager.getInstance().sendPostByJSON(WxmpMessageConstant.SEND_MESSAGE + accessToken, JSON.toJSONString(jsonObject)).getData(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									Map<String, Object> resultMap = JSON.parseObject(resultStr, Map.class); | 
					 | 
					 | 
					                Map<String, Object> resultMap = JSON.parseObject(resultStr, Map.class); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									Object errcode = resultMap.get(WxmpMessageConstant.ERR_CODE); | 
					 | 
					 | 
					                Object errcode = resultMap.get(WxmpMessageConstant.ERR_CODE); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									if (errcode.equals(NumConstant.ZERO)) { | 
					 | 
					 | 
					                if (errcode.equals(NumConstant.ZERO)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										//发送成功
 | 
					 | 
					 | 
					                    //发送成功
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										//订阅条数-1
 | 
					 | 
					 | 
					                    //订阅条数-1
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										int decrease = 0; | 
					 | 
					 | 
					                    int decrease = 0; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										if (WxmpMessageConstant.RESI.equals(clientType)) { | 
					 | 
					 | 
					                    if (WxmpMessageConstant.RESI.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											decrease = wxmpResiUserSubscribeDao.decreaseResiSubscribeCount(openId, templateId, customerId, 1); | 
					 | 
					 | 
					                        decrease = wxmpResiUserSubscribeDao.decreaseResiSubscribeCount(openId, templateId, customerId, 1); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										} else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
					 | 
					 | 
					                    } else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											decrease = wxmpWorkUserSubscribeDao.decreaseWorkSubscribeCount(openId, templateId, customerId, 1); | 
					 | 
					 | 
					                        decrease = wxmpWorkUserSubscribeDao.decreaseWorkSubscribeCount(openId, templateId, customerId, 1); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										} | 
					 | 
					 | 
					                    } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										if (decrease == 0) { | 
					 | 
					 | 
					                    if (decrease == 0) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											logger.error("消息{}发送成功但订阅条数-1失败", JSON.toJSONString(msg)); | 
					 | 
					 | 
					                        logger.error("消息{}发送成功但订阅条数-1失败", JSON.toJSONString(msg)); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										} | 
					 | 
					 | 
					                    } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										//存表
 | 
					 | 
					 | 
					                    //存表
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										int saveRes = wxmpMsgSendRecordService.saveRecord(initRecord(msg, templateId, openId, WxmpMessageConstant.SUCCESS)); | 
					 | 
					 | 
					                    int saveRes = wxmpMsgSendRecordService.saveRecord(initRecord(msg, templateId, openId, WxmpMessageConstant.SUCCESS)); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										if (saveRes == 0) { | 
					 | 
					 | 
					                    if (saveRes == 0) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											logger.error("消息{}发送成功但存入记录表失败", JSON.toJSONString(msg)); | 
					 | 
					 | 
					                        logger.error("消息{}发送成功但存入记录表失败", JSON.toJSONString(msg)); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										} | 
					 | 
					 | 
					                    } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} else { | 
					 | 
					 | 
					                } else { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										//发送失败
 | 
					 | 
					 | 
					                    //发送失败
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										//用户拒绝,需清空订阅表条数,修改订阅状态
 | 
					 | 
					 | 
					                    //用户拒绝,需清空订阅表条数,修改订阅状态
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										if (errcode.equals(WxmpMessageConstant.USER_REFUSED)) { | 
					 | 
					 | 
					                    if (errcode.equals(WxmpMessageConstant.USER_REFUSED)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											int clear = 0; | 
					 | 
					 | 
					                        int clear = 0; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											if (WxmpMessageConstant.RESI.equals(clientType)) { | 
					 | 
					 | 
					                        if (WxmpMessageConstant.RESI.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
												clear = wxmpResiUserSubscribeDao.clearResiSubscribeCount(openId, templateId, customerId); | 
					 | 
					 | 
					                            clear = wxmpResiUserSubscribeDao.clearResiSubscribeCount(openId, templateId, customerId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											} else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
					 | 
					 | 
					                        } else if (WxmpMessageConstant.WORK.equals(clientType)) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
												clear = wxmpWorkUserSubscribeDao.clearWorkSubscribeCount(openId, templateId, customerId); | 
					 | 
					 | 
					                            clear = wxmpWorkUserSubscribeDao.clearWorkSubscribeCount(openId, templateId, customerId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											} | 
					 | 
					 | 
					                        } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											if (clear == 0) { | 
					 | 
					 | 
					                        if (clear == 0) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
												logger.error("消息{}发送失败且清空订阅条数失败", JSON.toJSONString(msg)); | 
					 | 
					 | 
					                            logger.error("消息{}发送失败且清空订阅条数失败", JSON.toJSONString(msg)); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											} | 
					 | 
					 | 
					                        } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										} | 
					 | 
					 | 
					                    } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										//抛出错误
 | 
					 | 
					 | 
					                    //抛出错误
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										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++; | 
					 | 
					 | 
					                succecssCount++; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
								} catch (Exception e) { | 
					 | 
					 | 
					            } catch (Exception e) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									String errMsg = e.getMessage(); | 
					 | 
					 | 
					                String errMsg = e.getMessage(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									//ValidateException错误信息为getMsg
 | 
					 | 
					 | 
					                //ValidateException错误信息为getMsg
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					//				if (StringUtils.isBlank(errMsg) && e instanceof ValidateException) {
 | 
					 | 
					 | 
					//				if (StringUtils.isBlank(errMsg) && e instanceof ValidateException) {
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					//					errMsg = ((ValidateException) e).getMsg();
 | 
					 | 
					 | 
					//					errMsg = ((ValidateException) e).getMsg();
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					//				}
 | 
					 | 
					 | 
					//				}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
									if (e instanceof WxSubscribeException) { | 
					 | 
					 | 
					                if (e instanceof WxSubscribeException) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										//存表
 | 
					 | 
					 | 
					                    //存表
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										WxmpMsgSendRecordEntity wxmpMsgSendRecordEntity = initRecord(msg, ((WxSubscribeException) e).getTemplateId(), ((WxSubscribeException) e).getOpenId(), WxmpMessageConstant.ERROR); | 
					 | 
					 | 
					                    WxmpMsgSendRecordEntity wxmpMsgSendRecordEntity = initRecord(msg, ((WxSubscribeException) e).getTemplateId(), ((WxSubscribeException) e).getOpenId(), WxmpMessageConstant.ERROR); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										wxmpMsgSendRecordEntity.setReason(errMsg); | 
					 | 
					 | 
					                    wxmpMsgSendRecordEntity.setReason(errMsg); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										int saveRes = wxmpMsgSendRecordService.saveRecord(wxmpMsgSendRecordEntity); | 
					 | 
					 | 
					                    int saveRes = wxmpMsgSendRecordService.saveRecord(wxmpMsgSendRecordEntity); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										if (saveRes == 0) { | 
					 | 
					 | 
					                    if (saveRes == 0) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
											logger.error("消息{}发送失败且存入记录表失败", JSON.toJSONString(msg)); | 
					 | 
					 | 
					                        logger.error("消息{}发送失败且存入记录表失败", JSON.toJSONString(msg)); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
										} | 
					 | 
					 | 
					                    } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									} | 
					 | 
					 | 
					                } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									logger.error("消息:{}发送失败,原因是:{}", JSON.toJSONString(msg), errMsg); | 
					 | 
					 | 
					                logger.error("消息:{}发送失败,原因是:{}", JSON.toJSONString(msg), errMsg); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
									continue; | 
					 | 
					 | 
					                continue; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
								} | 
					 | 
					 | 
					            } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							} | 
					 | 
					 | 
					        } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							logger.info("{}条消息中的{}条发送成功", msgList.size(), succecssCount); | 
					 | 
					 | 
					        logger.info("{}条消息中的{}条发送成功", msgList.size(), succecssCount); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						} | 
					 | 
					 | 
					    } | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						//初始化记录对象
 | 
					 | 
					 | 
					    //初始化记录对象
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						private WxmpMsgSendRecordEntity initRecord(WxSubscribeMessageFormDTO msg, String templateId, String openId, String status) { | 
					 | 
					 | 
					    private WxmpMsgSendRecordEntity initRecord(WxSubscribeMessageFormDTO msg, String templateId, String openId, String status) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							WxmpMsgSendRecordEntity wxmpMsgSendRecordEntity = new WxmpMsgSendRecordEntity(); | 
					 | 
					 | 
					        WxmpMsgSendRecordEntity wxmpMsgSendRecordEntity = new WxmpMsgSendRecordEntity(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							wxmpMsgSendRecordEntity.setCustomerId(msg.getCustomerId()); | 
					 | 
					 | 
					        wxmpMsgSendRecordEntity.setCustomerId(msg.getCustomerId()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							wxmpMsgSendRecordEntity.setClientType(msg.getClientType()); | 
					 | 
					 | 
					        wxmpMsgSendRecordEntity.setClientType(msg.getClientType()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							wxmpMsgSendRecordEntity.setTemplateId(templateId); | 
					 | 
					 | 
					        wxmpMsgSendRecordEntity.setTemplateId(templateId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							wxmpMsgSendRecordEntity.setUserId(msg.getUserId()); | 
					 | 
					 | 
					        wxmpMsgSendRecordEntity.setUserId(msg.getUserId()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							wxmpMsgSendRecordEntity.setWxOpenId(openId); | 
					 | 
					 | 
					        wxmpMsgSendRecordEntity.setWxOpenId(openId); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							wxmpMsgSendRecordEntity.setBehaviorType(msg.getBehaviorType()); | 
					 | 
					 | 
					        wxmpMsgSendRecordEntity.setBehaviorType(msg.getBehaviorType()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							wxmpMsgSendRecordEntity.setTitle("您有一条" + msg.getBehaviorType()); | 
					 | 
					 | 
					        wxmpMsgSendRecordEntity.setTitle("您有一条" + msg.getBehaviorType()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							wxmpMsgSendRecordEntity.setMessageContent(msg.getMessageContent()); | 
					 | 
					 | 
					        wxmpMsgSendRecordEntity.setMessageContent(msg.getMessageContent()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							wxmpMsgSendRecordEntity.setMessageTime(new Date()); | 
					 | 
					 | 
					        wxmpMsgSendRecordEntity.setMessageTime(msg.getMessageTime()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							wxmpMsgSendRecordEntity.setResult(status); | 
					 | 
					 | 
					        wxmpMsgSendRecordEntity.setResult(status); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							return wxmpMsgSendRecordEntity; | 
					 | 
					 | 
					        return wxmpMsgSendRecordEntity; | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
						} | 
					 | 
					 | 
					    } | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
						/** | 
					 | 
					 | 
						/** | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
						 * @return | 
					 | 
					 | 
						 * @return | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |