yujian
2020-05-09 7e7db2fa55a9a3af46d4fd8ede0dee147f101d64
fanli/src/main/java/com/yeshi/fanli/aspect/SignValidateAspect.java
@@ -33,7 +33,7 @@
@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 +42,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
@@ -114,7 +114,7 @@
            // 记录大于2s的请求
            if (responseTime >= 2000) {
               ThreadUtil.run(new Runnable() {
                  @Override
                  public void run() {
                     LogHelper.requestTime(url, params, responseTime);
@@ -124,12 +124,11 @@
            }
         } catch (Throwable e) {
            try {
               LogHelper.errorDetailInfo(e, getHttpServletParams(request), request.getRequestURI().toString());
            } catch (Exception e1) {
               e1.printStackTrace();
            }
            out.print(JsonUtil.loadFalseResult(90009, "服务器内部错误"));
            LogHelper.errorDetailInfo(e, getHttpServletParams(request), request.getRequestURI().toString());
            if (!Constant.IS_TEST)
               out.print(JsonUtil.loadFalseResult(90009, "服务器内部错误"));
            else
               throw e;
         }
         return obj;
      } else {
@@ -138,7 +137,7 @@
         data.put("msg", "签名错误");
         out.print(data);
         out.close();
         LogHelper.error("签名错误:" + getHttpServletParams(request));
         LogHelper.error("签名错误:" + request.getRequestURI() + "-" + getHttpServletParams(request));
         return null;
      }
   }
@@ -197,9 +196,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;
@@ -225,4 +224,24 @@
      }
   }
   public static boolean signIsRight(JSONObject json) {
      List<String> list = new ArrayList<>();
      for (Iterator<String> its = json.keySet().iterator(); its.hasNext();) {
         String key = its.next();
         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;
      }
   }
}