|  | @ -2,10 +2,8 @@ package com.yihu.jw.door.util;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | import com.alibaba.fastjson.JSON;
 |  | import com.alibaba.fastjson.JSON;
 | 
												
													
														
															|  | import com.alibaba.fastjson.JSONObject;
 |  | import com.alibaba.fastjson.JSONObject;
 | 
												
													
														
															|  | import com.netflix.discovery.converters.Auto;
 |  | 
 | 
												
													
														
															|  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 |  | 
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
 |  | import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.wx.WxAccessTokenDO;
 |  | import com.yihu.jw.entity.base.wx.WxAccessTokenDO;
 | 
												
													
														
															|  | import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
 |  | import com.yihu.jw.entity.base.wx.WxTemplateConfigDO;
 | 
												
											
												
													
														
															|  | @ -60,8 +58,10 @@ public class MessageUtil {
 | 
												
													
														
															|  |     private BaseDoctorDao baseDoctorDao;
 |  |     private BaseDoctorDao baseDoctorDao;
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private BasePatientDao basePatientDao;
 |  |     private BasePatientDao basePatientDao;
 | 
												
													
														
															|  | 
 |  |     @Value("${server.server_url}")
 | 
												
													
														
															|  | 
 |  |     private String server_url;
 | 
												
													
														
															|  |     //发送微信模板消息
 |  |     //发送微信模板消息
 | 
												
													
														
															|  |     public static String sendMessageUrl = "http://172.16.100.37:8090/hospitalPortal-sms/sms/sendMessage";
 |  | 
 | 
												
													
														
															|  | 
 |  |     private  String sendMessageUrl = "http://172.16.100.37:8090/hospitalPortal-sms/sms/sendMessage";
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      * @param wxId
 |  |      * @param wxId
 | 
												
											
												
													
														
															|  | @ -134,8 +134,28 @@ public class MessageUtil {
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     //推送模板消息
 |  |     //推送模板消息
 | 
												
													
														
															|  |     public void putTemplateWxMessage(String wechatId, String templateName, String scene, String openId, String first,String patientId, String doctorId, Integer type,JSONObject josn,String ...keywords) {
 |  | 
 | 
												
													
														
															|  | 
 |  |     public void putTemplateWxMessage(WxTemplateConfigDO newConfig,String openId,Integer type,JSONObject json){
 | 
												
													
														
															|  |         try {
 |  |         try {
 | 
												
													
														
															|  | 
 |  |             WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(newConfig.getWechatId());
 | 
												
													
														
															|  | 
 |  |             if (wxAccessTokenDO == null) {
 | 
												
													
														
															|  | 
 |  |                 logger.info("wx_access_token表获取为空,wechatId" + newConfig.getWechatId());
 | 
												
													
														
															|  | 
 |  |                 return;
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             newConfig = setTemPlateUrl(newConfig,type,openId,json);
 | 
												
													
														
															|  | 
 |  |             //发起微信消息模板推送
 | 
												
													
														
															|  | 
 |  |             logger.info("微信模板消息推送前");
 | 
												
													
														
															|  | 
 |  |             weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(), openId, newConfig);
 | 
												
													
														
															|  | 
 |  |             logger.info("微信模板消息推送后");
 | 
												
													
														
															|  | 
 |  |         }catch (Exception e){
 | 
												
													
														
															|  | 
 |  |             logger.info("微信模板推送异常");
 | 
												
													
														
															|  | 
 |  |             e.printStackTrace();
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     //推送模板消息
 | 
												
													
														
															|  | 
 |  |     public void putTemplateWxMessage(String wechatId, String templateName, String scene, String openId, String first,String url, String remark, Integer type,JSONObject josn,String ...keywords) {
 | 
												
													
														
															|  | 
 |  |         try {
 | 
												
													
														
															|  | 
 |  |             System.out.println(wechatId);
 | 
												
													
														
															|  |             WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId);
 |  |             WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId);
 | 
												
													
														
															|  |             if (wxAccessTokenDO == null) {
 |  |             if (wxAccessTokenDO == null) {
 | 
												
													
														
															|  |                 logger.info("wx_access_token表获取为空,wechatId" + wechatId);
 |  |                 logger.info("wx_access_token表获取为空,wechatId" + wechatId);
 | 
												
											
												
													
														
															|  | @ -147,47 +167,16 @@ public class MessageUtil {
 | 
												
													
														
															|  |                 return;
 |  |                 return;
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |             logger.info("微信模板推送前");
 |  |             logger.info("微信模板推送前");
 | 
												
													
														
															|  |             String firstStr = newConfig.getFirst();
 |  | 
 | 
												
													
														
															|  |             if (StringUtils.isNoneBlank(first)){
 |  |             if (StringUtils.isNoneBlank(first)){
 | 
												
													
														
															|  |                 newConfig.setFirst(first);
 |  |                 newConfig.setFirst(first);
 | 
												
													
														
															|  |                 firstStr = first;
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             if (type==30){//反馈通知
 |  | 
 | 
												
													
														
															|  |                 if (scene.equals("smyyyjjd")){
 |  | 
 | 
												
													
														
															|  |                     BasePatientDO patient = basePatientDao.findById(patientId);
 |  | 
 | 
												
													
														
															|  |                     BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doctorId);
 |  | 
 | 
												
													
														
															|  |                     firstStr = firstStr.replace("key1",(patient.getName()==null?"":patient.getName()));
 |  | 
 | 
												
													
														
															|  |                     firstStr = firstStr.replace("key2", null != baseDoctorDO.getName() ? baseDoctorDO.getName() : "");
 |  | 
 | 
												
													
														
															|  |                     newConfig.setFirst(firstStr);
 |  | 
 | 
												
													
														
															|  |                     newConfig.setKeyword1(DateUtil.dateToStrShort(new Date()));
 |  | 
 | 
												
													
														
															|  |                     newConfig.setKeyword2("上门服务已接单");
 |  | 
 | 
												
													
														
															|  |                 }
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |                 //url + json.getString("url") + "?openid=" + openid + "&consult=" + json.getString("consult")
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             if (type==31){ //上门服务医生评分
 |  | 
 | 
												
													
														
															|  |                 firstStr = firstStr.replace("key1", DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm"));
 |  | 
 | 
												
													
														
															|  |                 newConfig.setFirst(firstStr);
 |  | 
 | 
												
													
														
															|  |                 newConfig.setKeyword1(DateUtil.dateToStrShort(new Date()));
 |  | 
 | 
												
													
														
															|  |                 newConfig.setKeyword2("服务医生评分");
 |  | 
 | 
												
													
														
															|  |                 //url:url + json.getString("url")+"?openid=" + openid + "&id=" + json.getString("id")+ "&finish=" + finish)
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  |             if(type==32){
 |  | 
 | 
												
													
														
															|  |                 newConfig.setKeyword1(DateUtil.dateToStrShort(new Date()));
 |  | 
 | 
												
													
														
															|  |                 newConfig.setKeyword2("服务项目变更确认");
 |  | 
 | 
												
													
														
															|  |                 //url1 + json.getString("url")+"?openid=" + openid + "&consult=" + json.getString("consult") + "&status=" + json.getInt("status")
 |  | 
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |             if(type==34){
 |  | 
 | 
												
													
														
															|  |                 //temp.setUrl(url + json.getString("url") + "?openid=" + openid + "&orderId=" + json.get("orderId")+ "&authorizeImage=" + json.getString("authorizeImage"));
 |  | 
 | 
												
													
														
															|  | 
 |  |             if (StringUtils.isNoneBlank(url)){
 | 
												
													
														
															|  | 
 |  |                 newConfig.setUrl(url);
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  |             if (type==19){
 |  | 
 | 
												
													
														
															|  | //                String urlStr= newConfig.getUrl();
 |  | 
 | 
												
													
														
															|  | //                boolean status = urlStr.contains("openid=");
 |  | 
 | 
												
													
														
															|  | //                if(!status){
 |  | 
 | 
												
													
														
															|  | //                    urlStr=json.getString("url")+"?openid=" + openid;
 |  | 
 | 
												
													
														
															|  | //                }
 |  | 
 | 
												
													
														
															|  | //                temp.setUrl(url + urlStr );
 |  | 
 | 
												
													
														
															|  | 
 |  |             if (StringUtils.isNoneBlank(remark)){
 | 
												
													
														
															|  | 
 |  |                 newConfig.setRemark(remark);
 | 
												
													
														
															|  |             }
 |  |             }
 | 
												
													
														
															|  | 
 |  |             newConfig = setTemPlateUrl(newConfig,type,openId,josn);
 | 
												
													
														
															|  |             int keyLength = keywords.length;
 |  |             int keyLength = keywords.length;
 | 
												
													
														
															|  |             if (keyLength >= 1) {
 |  |             if (keyLength >= 1) {
 | 
												
													
														
															|  |                if(StringUtils.isNoneBlank(keywords[0])){
 |  |                if(StringUtils.isNoneBlank(keywords[0])){
 | 
												
											
												
													
														
															|  | @ -233,6 +222,40 @@ public class MessageUtil {
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public WxTemplateConfigDO setTemPlateUrl(WxTemplateConfigDO wxTemplateConfigDO,Integer type,String openid,JSONObject json){
 | 
												
													
														
															|  | 
 |  |         String url = server_url + "wx/html/";
 | 
												
													
														
															|  | 
 |  |         if (type==30){//反馈通知 测试 TPbq9m0SAiVfRhXtXq17SDmYIfrJ8Whp2NpSrq9wlfI
 | 
												
													
														
															|  | 
 |  |             if(json.containsKey("consult")) {
 | 
												
													
														
															|  | 
 |  |                 wxTemplateConfigDO.setUrl(url + wxTemplateConfigDO.getUrl() + "?openid=" + openid + "&consult=" + json.getString("consult"));
 | 
												
													
														
															|  | 
 |  |             }else if (json.containsKey("id")){
 | 
												
													
														
															|  | 
 |  |                 wxTemplateConfigDO.setUrl(url + wxTemplateConfigDO.getUrl() + "?openid=" + openid + "&id=" + json.getString("id"));
 | 
												
													
														
															|  | 
 |  |             }else if(json.containsKey("relationCode")){
 | 
												
													
														
															|  | 
 |  |                 wxTemplateConfigDO.setUrl(url + wxTemplateConfigDO.getUrl() + "?openid=" + openid );
 | 
												
													
														
															|  | 
 |  |             }else if(json.containsKey("resultCode")){
 | 
												
													
														
															|  | 
 |  |                 wxTemplateConfigDO.setUrl(url + wxTemplateConfigDO.getUrl() + "?resultCode=" + json.getString("resultCode"));
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if (type==31){ //上门服务医生评分   //TPbq9m0SAiVfRhXtXq17SDmYIfrJ8Whp2NpSrq9wlfI
 | 
												
													
														
															|  | 
 |  |             wxTemplateConfigDO.setUrl(url + wxTemplateConfigDO.getUrl()+"?openid=" + openid + "&id=" + json.getString("id")+ "&finish=" + json.getString("finish"));
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if(type==32){  //TPbq9m0SAiVfRhXtXq17SDmYIfrJ8Whp2NpSrq9wlfI
 | 
												
													
														
															|  | 
 |  |             String url1 = server_url + "wx/common/";
 | 
												
													
														
															|  | 
 |  |             wxTemplateConfigDO.setUrl(url1 + wxTemplateConfigDO.getUrl()+"?openid=" + openid + "&consult=" + json.getString("consult") + "&status=" + json.getInteger("status"));
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if(type==34){ //TPbq9m0SAiVfRhXtXq17SDmYIfrJ8Whp2NpSrq9wlfI
 | 
												
													
														
															|  | 
 |  |             wxTemplateConfigDO.setUrl(url + wxTemplateConfigDO.getUrl() + "?openid=" + openid + "&orderId=" + json.get("orderId")+ "&authorizeImage=" + json.getString("authorizeImage"));
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         if (type==19){  //zSR9w5AjfZFLc_g8AxGBvDKZASoKAeXQuGnvPAQzvps
 | 
												
													
														
															|  | 
 |  |             String urlStr= wxTemplateConfigDO.getUrl();
 | 
												
													
														
															|  | 
 |  |             boolean status = urlStr.contains("openid=");
 | 
												
													
														
															|  | 
 |  |             if(!status){
 | 
												
													
														
															|  | 
 |  |                 urlStr=json.getString("url")+"?openid=" + openid;
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             wxTemplateConfigDO.setUrl(url + urlStr );
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         return wxTemplateConfigDO;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     /**
 |  |     /**
 | 
												
													
														
															|  |      *
 |  |      *
 | 
												
													
														
															|  |      */
 |  |      */
 | 
												
											
												
													
														
															|  | @ -349,9 +372,7 @@ public class MessageUtil {
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public static void main(String[] args){
 |  |     public static void main(String[] args){
 | 
												
													
														
															|  |         try {
 |  |         try {
 | 
												
													
														
															|  |             for (int i=0;i<10;i++){
 |  | 
 | 
												
													
														
															|  |                 System.out.println(UUID.randomUUID().toString().replace("-",""));
 |  | 
 | 
												
													
														
															|  |             }
 |  | 
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         }catch (Exception e){
 |  |         }catch (Exception e){
 | 
												
													
														
															|  |             e.printStackTrace();
 |  |             e.printStackTrace();
 | 
												
													
														
															|  |         }
 |  |         }
 |