| | |
| | | import com.matrix.system.shopXcx.bean.ShopWxtemplateMsg; |
| | | import com.matrix.system.shopXcx.dao.ShopWxtemplateMsgDao; |
| | | import com.matrix.system.wechart.templateMsg.GzhTemplateMessagePojo; |
| | | import com.matrix.system.wechart.templateMsg.TemplateNameConstance; |
| | | import com.matrix.system.wechart.templateMsg.UniformMsgPojo; |
| | | import com.rabbitmq.client.DeliverCallback; |
| | | import com.rabbitmq.client.Delivery; |
| | | import io.swagger.models.auth.In; |
| | | import org.apache.commons.collections.map.HashedMap; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | String messages = new String(message.getBody(), "UTF-8"); |
| | | JSONObject messageJsonParam=JSONObject.parseObject(messages); |
| | | |
| | | if(!messageJsonParam.containsKey("companyId")){ |
| | | LogUtil.error("小程序消息推送参数格式异常发送模板消息需要传JSONO字符串作为格式 例如:{\"companyId\":17} companyId 是必须属性"); |
| | | if(!messageJsonParam.containsKey("companyId")||(!messageJsonParam.containsKey("templateCode"))){ |
| | | LogUtil.error("小程序消息推送参数格式异常发送模板消息需要传JSONO字符串作为格式 例如:{\"companyId\":17,\"templateCode\":10000} companyId 、templateCode 是必须属性"); |
| | | return; |
| | | } |
| | | |
| | | Long companyId = Long.parseLong( messageJsonParam.get("companyId").toString()); |
| | | Integer templateCode = Integer.parseInt( messageJsonParam.get("templateCode").toString()); |
| | | |
| | | //获取公司微信配置参数 |
| | | BusParameterSettings xcxAppId = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_APPID, companyId); |
| | | BusParameterSettings xcxSecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.MINIPROGRAM_SECRET, companyId); |
| | | BusParameterSettings gzhAppid = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.GZH_APPID, companyId); |
| | | //获取消息模板 |
| | | ShopWxtemplateMsg template = shopWxtemplateMsgDao.selectByCode(TemplateNameConstance.GZH_YYTX,companyId); |
| | | ShopWxtemplateMsg template = shopWxtemplateMsgDao.selectByCode(templateCode,companyId); |
| | | //校验参数 |
| | | if(xcxAppId==null||xcxSecret==null||gzhAppid==null||template==null){ |
| | | LogUtil.error("小程序消息推送配置缺失xcxAppId="+xcxAppId+";xcxSecret="+xcxSecret+";gzhAppid="+gzhAppid+";template="+template); |
| | | return; |
| | | } |
| | | |
| | | //获取模板动态构建类 |
| | | TemplateMessageBulder templateMessageBulder = (TemplateMessageBulder) GlueFactory.getInstance().loadInstance(template.getTemplateClass()); |
| | | //为模板动态类装备必要的参数 |
| | | Map<String, Object> bulderParam = new HashedMap(); |
| | | bulderParam.put("xcxAppId", xcxAppId.getParamValue()); |
| | | bulderParam.put("gzhAppid", gzhAppid.getParamValue()); |
| | | bulderParam.put("template_id", template.getUuid()); |
| | | bulderParam.put("messageJsonParam", messageJsonParam); |