old mode 100644
new mode 100755
| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.core.annotation.Java110Synchronized; |
| | | import com.java110.core.factory.GenerateCodeFactory; |
| | | import com.java110.core.factory.WechatFactory; |
| | | import com.java110.core.smo.ISaveTransactionLogSMO; |
| | | import com.java110.dto.RoomDto; |
| | | import com.java110.dto.app.AppDto; |
| | | import com.java110.dto.community.CommunityDto; |
| | | import com.java110.dto.logSystemError.LogSystemErrorDto; |
| | | import com.java110.dto.notice.NoticeDto; |
| | | import com.java110.dto.owner.OwnerAppUserDto; |
| | | import com.java110.dto.owner.OwnerRoomRelDto; |
| | |
| | | import com.java110.intf.user.IOwnerAppUserInnerServiceSMO; |
| | | import com.java110.intf.user.IOwnerRoomRelInnerServiceSMO; |
| | | import com.java110.job.quartz.TaskSystemQuartz; |
| | | import com.java110.po.logSystemError.LogSystemErrorPo; |
| | | import com.java110.po.transactionLog.TransactionLogPo; |
| | | import com.java110.service.smo.ISaveSystemErrorSMO; |
| | | import com.java110.utils.cache.MappingCache; |
| | | import com.java110.utils.constant.WechatConstant; |
| | | import com.java110.utils.util.DateUtil; |
| | | import com.java110.utils.util.ExceptionUtil; |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | @Autowired |
| | | private RestTemplate outRestTemplate; |
| | | |
| | | @Autowired |
| | | private ISaveSystemErrorSMO saveSystemErrorSMOImpl; |
| | | |
| | | //模板信息推送地址 |
| | | private static String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="; |
| | | private static String getUser = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN"; |
| | |
| | | try { |
| | | publishMsg(taskDto, communityDto); |
| | | } catch (Exception e) { |
| | | LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo(); |
| | | logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId)); |
| | | logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_NOTICE); |
| | | logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e)); |
| | | saveSystemErrorSMOImpl.saveLog(logSystemErrorPo); |
| | | logger.error("推送消息失败", e); |
| | | } |
| | | } |
| | |
| | | try { |
| | | doSentWechat(tmpNotice, templateId, accessToken, weChatDto); |
| | | } catch (Exception e) { |
| | | LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo(); |
| | | logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId)); |
| | | logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_NOTICE); |
| | | logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e)); |
| | | saveSystemErrorSMOImpl.saveLog(logSystemErrorPo); |
| | | logger.error("通知异常", e); |
| | | } |
| | | } |
| | |
| | | |
| | | private void doSentWechat(NoticeDto noticeDto, String templateId, String accessToken, SmallWeChatDto weChatDto) throws Exception { |
| | | |
| | | Date startTime = DateUtil.getDateFromString(noticeDto.getStartTime(), DateUtil.DATE_FORMATE_STRING_A); |
| | | Date nowTime = DateUtil.getCurrentDate(); |
| | | if (startTime.getTime() > nowTime.getTime()) { //还没有到时间 |
| | | return; |
| | | } |
| | | // Date startTime = DateUtil.getDateFromString(noticeDto.getStartTime(), DateUtil.DATE_FORMATE_STRING_A); |
| | | // Date nowTime = DateUtil.getCurrentDate(); |
| | | // if (startTime.getTime() > nowTime.getTime()) { //还没有到时间 |
| | | // return; |
| | | // } |
| | | |
| | | |
| | | String objType = noticeDto.getObjType(); |
| | |
| | | private void doSend(List<OwnerAppUserDto> ownerAppUserDtos, NoticeDto noticeDto, String templateId, String accessToken, SmallWeChatDto weChatDto) { |
| | | String wechatUrl = MappingCache.getValue("OWNER_WECHAT_URL") + "/#/pages/notice/detail/detail?noticeId="; |
| | | ResponseEntity<String> responseEntity = null; |
| | | String sendTemplate = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN,WechatConstant.SEND_TEMPLATE_URL); |
| | | if(StringUtil.isEmpty(sendTemplate)){ |
| | | sendTemplate = sendMsgUrl; |
| | | } |
| | | for (OwnerAppUserDto appUserDto : ownerAppUserDtos) { |
| | | Date startTime = DateUtil.getCurrentDate(); |
| | | PropertyFeeTemplateMessage templateMessage = new PropertyFeeTemplateMessage(); |
| | |
| | | templateMessage.setData(data); |
| | | templateMessage.setUrl(wechatUrl + noticeDto.getNoticeId() + "&wAppId=" + weChatDto.getAppId()); |
| | | logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage)); |
| | | responseEntity = outRestTemplate.postForEntity(sendMsgUrl + accessToken, JSON.toJSONString(templateMessage), String.class); |
| | | responseEntity = outRestTemplate.postForEntity(sendTemplate + accessToken, JSON.toJSONString(templateMessage), String.class); |
| | | logger.info("微信模板返回内容:{}", responseEntity); |
| | | } catch (Exception e) { |
| | | LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo(); |
| | | logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId)); |
| | | logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_NOTICE); |
| | | logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e)); |
| | | saveSystemErrorSMOImpl.saveLog(logSystemErrorPo); |
| | | logger.error("发送失败", e); |
| | | } finally { |
| | | doSaveLog(startTime, DateUtil.getCurrentDate(), "/pages/notice/detail/detail", JSON.toJSONString(templateMessage), responseEntity, appUserDto.getOpenId()); |
| | |
| | | } |
| | | |
| | | private void doSendToOpenId(NoticeDto noticeDto, String templateId, String accessToken, String nextOpenid, SmallWeChatDto weChatDto) { |
| | | String url = getUser.replace("ACCESS_TOKEN", accessToken); |
| | | String url = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN,WechatConstant.GET_USER_URL); |
| | | if(StringUtil.isEmpty(url)){ |
| | | url = getUser; |
| | | } |
| | | url = url.replace("ACCESS_TOKEN", accessToken); |
| | | if (!StringUtil.isEmpty(nextOpenid)) { |
| | | url += ("&next_openid=" + nextOpenid); |
| | | } |
| | |
| | | miniprogram = new Miniprogram(); |
| | | miniprogram.setAppid(wechatUrl); |
| | | } |
| | | |
| | | String sendTemplate = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN,WechatConstant.SEND_TEMPLATE_URL); |
| | | if(StringUtil.isEmpty(sendTemplate)){ |
| | | sendTemplate = sendMsgUrl; |
| | | } |
| | | ResponseEntity<String> responseEntity = null; |
| | | for (int openIndex = 0; openIndex < openids.size(); openIndex++) { |
| | | Date startTime = DateUtil.getCurrentDate(); |
| | |
| | | } |
| | | } |
| | | logger.info("发送模板消息内容:{}", JSON.toJSONString(templateMessage)); |
| | | responseEntity = outRestTemplate.postForEntity(sendMsgUrl + accessToken, JSON.toJSONString(templateMessage), String.class); |
| | | responseEntity = outRestTemplate.postForEntity(sendTemplate + accessToken, JSON.toJSONString(templateMessage), String.class); |
| | | logger.info("微信模板返回内容:{}", responseEntity); |
| | | } catch (Exception e) { |
| | | LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo(); |
| | | logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId)); |
| | | logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_NOTICE); |
| | | logSystemErrorPo.setMsg(ExceptionUtil.getStackTrace(e)); |
| | | saveSystemErrorSMOImpl.saveLog(logSystemErrorPo); |
| | | logger.error("发送失败", e); |
| | | } finally { |
| | | doSaveLog(startTime, DateUtil.getCurrentDate(), "/pages/notice/detail/detail", JSON.toJSONString(templateMessage), responseEntity, openId); |