admin
2020-07-29 c338aa60df58bee9f4c25afedf94fe6930a119c1
fanli/src/main/java/com/yeshi/fanli/aspect/SignValidateAspect.java
@@ -1,6 +1,5 @@
package com.yeshi.fanli.aspect;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
@@ -11,6 +10,7 @@
import javax.servlet.http.HttpServletRequest;
import com.yeshi.fanli.util.SystemInfoUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@@ -27,13 +27,14 @@
import com.yeshi.fanli.util.ThreadUtil;
import net.sf.json.JSONObject;
import org.yeshi.utils.SystemUtil;
//客户端接口签名验证
@Component
@Aspect
@Order(2)
public class SignValidateAspect {
   public static final String EDP = "execution(* com.yeshi.fanli.controller.client.v1.*.*(..))";
   public static final String EDP = "execution(* com.yeshi.fanli.controller.client.*.*.*(..))";
   public static String KEY = "";
@@ -42,7 +43,7 @@
   }
   @Around(EDP)
   public Object testAround(ProceedingJoinPoint joinPoint) throws IOException {
   public Object testAround(ProceedingJoinPoint joinPoint) throws Throwable {
      Object[] args = joinPoint.getArgs();
      PrintWriter out = null;
      ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder
@@ -95,6 +96,9 @@
            return null;
         }
         if(acceptData!=null)
            acceptData.setSystem(SystemInfoUtil.getSystem(acceptData));
         final String url = request.getRequestURI();
         @SuppressWarnings("unchecked")
         final Map<String, Object> params = request.getParameterMap();
@@ -125,7 +129,10 @@
         } catch (Throwable e) {
            LogHelper.errorDetailInfo(e, getHttpServletParams(request), request.getRequestURI().toString());
            out.print(JsonUtil.loadFalseResult(90009, "服务器内部错误"));
            if (!Constant.IS_TEST)
               out.print(JsonUtil.loadFalseResult(90009, "服务器内部错误"));
            else
               throw e;
         }
         return obj;
      } else {
@@ -134,7 +141,7 @@
         data.put("msg", "签名错误");
         out.print(data);
         out.close();
         LogHelper.error("签名错误:" + getHttpServletParams(request));
         LogHelper.error("签名错误:" + request.getRequestURI() + "-" + getHttpServletParams(request));
         return null;
      }
   }
@@ -193,9 +200,9 @@
      while (its.hasNext()) {
         String key = its.next();
         if (key.equalsIgnoreCase("callback")) {
            fromWEB = true;
         }
         // if (key.equalsIgnoreCase("callback")) {
         // fromWEB = true;
         // }
         if (key.equalsIgnoreCase("sign") || key.equalsIgnoreCase("callback") || key.equalsIgnoreCase("_")) {
            continue;
@@ -221,4 +228,25 @@
      }
   }
   public static boolean signIsRight(JSONObject json) {
      List<String> list = new ArrayList<>();
      for (Iterator<String> its = json.keySet().iterator(); its.hasNext();) {
         String key = its.next();
         if (!key.equalsIgnoreCase("sign"))
            list.add(key + "=" + json.optString(key));
      }
      Collections.sort(list);
      String str = "";
      for (String st : list) {
         str += st + "&";
      }
      String sign = StringUtil.Md5(str + KEY);
      if (sign.equalsIgnoreCase(json.optString("sign"))) {
         return true;
      } else {
         return false;
      }
   }
}