| 
					
				 | 
			
			
				@ -1,8 +1,12 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.gateway.filter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.netflix.zuul.ZuulFilter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.netflix.zuul.context.RequestContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.netflix.zuul.http.HttpServletRequestWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.netflix.zuul.http.ServletInputStreamWrapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.gateway.AesEncryptUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.gateway.methlog.BaseLoginLogService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.gateway.methlog.BaseMethodLogService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.gateway.useragent.UserAgent; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -20,16 +24,20 @@ import org.springframework.security.oauth2.provider.OAuth2Authentication; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.security.oauth2.provider.token.TokenStore; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Component; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.StreamUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.multipart.MultipartFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.multipart.MultipartHttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.multipart.MultipartResolver; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.multipart.commons.CommonsMultipartResolver; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.ServletInputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Enumeration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Iterator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.InputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.net.URLEncoder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.nio.charset.Charset; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by progr1mmer on 2017/12/27. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -68,6 +76,7 @@ public class BasicZuulFilter extends ZuulFilter { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public boolean shouldFilter() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -89,9 +98,27 @@ public class BasicZuulFilter extends ZuulFilter { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logger.info("BasicZuulFilter:"+url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!(url.contains("/open/noLogin/notify")|| 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            url.contains("/open/noLogin/ylzReceiveNotify")|| 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            url.contains("/open/noLogin/receiveNotify")|| 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            url.contains("/open/noLogin/getSFExpressInfoNew")|| 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            url.contains("/open/noLogin/sfroutepushservice")|| 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            url.contains("/open/noLogin/ylzSettleRecord")|| 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                url.contains("/weixin"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.info("入参"+ctx.getRequestQueryParams()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                decrypt(ctx,request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logger.info("第一步"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //保存操作日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        baseMethodLogService.saveMethodLog(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //内部微服务有不需要认证的地址请在URL上追加/open/来进行过滤,如/api/v1.0/open/**,不要在此继续追加!!! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (url.contains("/auth/")//验证服务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                || url.contains("/base/wechat")//微信 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -111,6 +138,67 @@ public class BasicZuulFilter extends ZuulFilter { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return this.authenticate(ctx, request, url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void decrypt(RequestContext ctx,HttpServletRequest request) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String method = request.getMethod(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (method.equalsIgnoreCase("GET")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, List<String>> map = ctx.getRequestQueryParams(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String aes_decodedStr = AesEncryptUtils.decrypt(map.get("object").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject object = JSONObject.parseObject(aes_decodedStr); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for(String str:object.keySet()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<String> arrayList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String value = object.getString(str); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                arrayList.add(value); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put(str,arrayList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.remove("object"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ctx.setRequestQueryParams(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.info("解密后的参数"+ctx.getRequestQueryParams()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if ("POST".equals(method) || "PUT".equals(method)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            InputStream in = request.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String body = StreamUtils.copyToString(in, Charset.forName("UTF-8")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 如果body为空初始化为空json 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (StringUtils.isEmpty(body)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                body = "{}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.info("body" + body); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 获取请求参数name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String jsonString = request.getParameter("object"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            logger.info("canshu"+jsonString); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (jsonString != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                body=""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String jsonobject = AesEncryptUtils.decrypt(jsonString); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logger.info("解密:" + jsonobject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject jsonObject = JSONObject.parseObject(jsonobject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                for(String str:jsonObject.keySet()){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String value = jsonObject.getString(str); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    body+=str+"="+ URLEncoder.encode(value)+"&"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String newBody = body.substring(0,body.length()-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                logger.info("newBody" + newBody); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                final byte[] reqBodyBytes = newBody.getBytes(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                // 重写上下文的HttpServletRequestWrapper 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ctx.setRequest(new HttpServletRequestWrapper(request) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    public ServletInputStream getInputStream() throws IOException { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        return new ServletInputStreamWrapper(reqBodyBytes); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    public int getContentLength() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        return reqBodyBytes.length; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    public long getContentLengthLong() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        return reqBodyBytes.length; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 验证token 权限地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param ctx 
			 |