| 
					
				 | 
			
			
				@ -132,22 +132,17 @@ public class MessageUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void putTemplateWxMessage(String wechatId,String templateName,String scene,String openId,String first,String remark,String url,String ...keywords){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            WxAccessTokenDO wxAccessTokenDO = getWxAccessTokenById(wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (wxAccessTokenDO==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logger.info("wx_access_token表获取为空,wechatId"+wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            WxTemplateConfigDO newConfig = new WxTemplateConfigDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sql="select w.* from base.wx_template_config w where w.wechat_id='"+wechatId+"' and w.template_name='"+templateName+"' and w.scene='"+scene+"' and w.status=1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<WxTemplateConfigDO> configList =  jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(WxTemplateConfigDO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            WxTemplateConfigDO config =null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (configList.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                config = configList.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            WxTemplateConfigDO newConfig = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId, templateName, scene, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (newConfig==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logger.info("微信模板不存在!请确认wechatId:"+wechatId+",templateName:"+templateName+",scene:"+scene); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BeanUtils.copyProperties(config, newConfig); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (StringUtils.isNoneBlank(url)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newConfig.setUrl(url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -184,71 +179,6 @@ public class MessageUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public WxAccessTokenDO getWxAccessTokenById(String wechatId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //根据wechatCode查找出appid和appSecret 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sql ="select * from base.wx_wechat w where w.id = '"+wechatId+"' and w.status!=-1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<WxWechatDO> wxWechatList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(WxWechatDO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            WxWechatDO wxWechat=null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (wxWechatList.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                wxWechat = wxWechatList.get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql="select * from base.wx_access_token w where w.wechat_id ='"+wechatId+"' order by w.add_timestamp desc "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<WxAccessTokenDO> wxAccessTokens =  jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(WxAccessTokenDO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(wxWechat==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_wxWechat_is_no_exist, ExceptionCode.common_error_params_code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(wxAccessTokens!=null&&wxAccessTokens.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                for (WxAccessTokenDO accessToken : wxAccessTokens) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ((System.currentTimeMillis() - accessToken.getAddTimestamp()) < (accessToken.getExpiresIn() * 500)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        return accessToken; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        sql="DELETE  from  base.wx_access_token where wechat_id='"+accessToken.getWechatId()+"' and access_token='"+accessToken.getAccessToken()+"'"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        jdbcTemplate.execute(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String token_url = "https://api.weixin.qq.com/cgi-bin/token"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String appId=""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String appSecret=""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            appId = wxWechat.getAppId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            appSecret = wxWechat.getAppSecret(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (org.springframework.util.StringUtils.isEmpty(appId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appId_is_null, ExceptionCode.common_error_params_code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (org.springframework.util.StringUtils.isEmpty(appSecret)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_appSecret_is_null, ExceptionCode.common_error_params_code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, Object> params = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("grant_type", "client_credential"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("appid", appId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("secret", appSecret); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String result = HttpUtils.doGet(token_url, params).getContent(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.info("--------------wechat token return:"+result+"---------------"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            org.json.JSONObject json = new org.json.JSONObject(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (json.has("access_token")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String token = json.get("access_token").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String expires_in = json.get("expires_in").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                WxAccessTokenDO newaccessToken = new WxAccessTokenDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setAccessToken(token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setExpiresIn(Long.parseLong(expires_in)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setAddTimestamp(System.currentTimeMillis()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setCode(UUID.randomUUID().toString().replace("-","")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setWechatId(wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                wxAccessTokenDao.save(newaccessToken); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return newaccessToken; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -285,25 +215,6 @@ public class MessageUtil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<SystemMessageDO> findSystemMesage(String relationCode,String type){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        StringBuilder sql =new StringBuilder("select * from base.base_system_message where 1=1 "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNoneBlank(relationCode)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql.append(" and relation_code='"+relationCode+"' "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtils.isNoneBlank(type)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sql.append(" and type in ('").append(type.replace(",","','")).append("') "); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<SystemMessageDO> list = jdbcTemplate.query(sql.toString(),new BeanPropertyRowMapper<>(SystemMessageDO.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public  void test(){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql="select w.* from base.wx_template_config w where w.wechat_id='xm_ykyy_wx' and w.template_name='template_evaluate_notice' and w.scene='fwqjtx' and w.status=1"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String,Object>> config =  jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus("xm_ykyy_wx", "template_pay_notice_jz", "mzxxtx", 1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        System.out.println("!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public static void main(String[] args){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (int i=0;i<10;i++){ 
			 |