From 744594ef1a2f530fc3e86ea9dc48b62247f79420 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 19 五月 2020 17:13:23 +0800
Subject: [PATCH] 饿了么绘图,添加口碑

---
 fanli/src/main/java/com/yeshi/fanli/aspect/SignValidateAspect.java |   95 +++++++++++++++++++++++++++++++++++------------
 1 files changed, 70 insertions(+), 25 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/aspect/SignValidateAspect.java b/fanli/src/main/java/com/yeshi/fanli/aspect/SignValidateAspect.java
index 5b4b345..90f930e 100644
--- a/fanli/src/main/java/com/yeshi/fanli/aspect/SignValidateAspect.java
+++ b/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;
@@ -24,6 +23,7 @@
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.ThreadUtil;
 
 import net.sf.json.JSONObject;
 
@@ -32,7 +32,7 @@
 @Aspect
 @Order(2)
 public class SignValidateAspect {
-	public static final String EDP = "execution(* com.yeshi.fanli.controller.client.*.*(..))";
+	public static final String EDP = "execution(* com.yeshi.fanli.controller.client.*.*.*(..))";
 
 	public static String KEY = "";
 
@@ -41,7 +41,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
@@ -54,6 +54,8 @@
 		for (Object obj : args) {
 			if (obj instanceof AcceptData) {
 				acceptData = (AcceptData) obj;
+			} else if (obj instanceof HttpServletRequest) {
+				request = (HttpServletRequest) obj;
 			}
 		}
 		boolean isRight = true;
@@ -66,8 +68,8 @@
 
 		if ((acceptData.getPlatform() != null && acceptData.getPlatform().equalsIgnoreCase("android")
 				&& acceptData.getVersion() != null && Integer.parseInt(acceptData.getVersion()) > 21)
-				|| (acceptData.getPlatform()!=null&&acceptData.getPlatform().equalsIgnoreCase("ios") && acceptData.getVersion() != null
-						&& Integer.parseInt(acceptData.getVersion()) > 24)) {
+				|| (acceptData.getPlatform() != null && acceptData.getPlatform().equalsIgnoreCase("ios")
+						&& acceptData.getVersion() != null && Integer.parseInt(acceptData.getVersion()) > 24)) {
 			isRight = signIsRight(request);
 		} else if (acceptData.getPackages().startsWith("com.haicaojie")) {
 			isRight = signIsRight(request);
@@ -83,27 +85,49 @@
 		// 绛惧悕鏄惁姝g‘
 		if (isRight) {
 			// 鍒ゆ柇绛惧悕瓒呮椂
-			// if (Math.abs((Long.parseLong(acceptData.getTime()) -
-			// System.currentTimeMillis())) > 1000 * 60 * 10) {
-			// JSONObject data = new JSONObject();
-			// data.put("code", -2);
-			// data.put("msg", "鏃堕棿閿欒");
-			// out.print(data);
-			// out.close();
-			// return null;
-			// }
-			//uid
+			if (Math.abs((Long.parseLong(acceptData.getTime()) - System.currentTimeMillis())) > 1000 * 60 * 10) {
+				JSONObject data = new JSONObject();
+				data.put("code", -2);
+				data.put("msg", "鏃堕棿閿欒");
+				out.print(data);
+				out.close();
+				return null;
+			}
+
+			final String url = request.getRequestURI();
+			@SuppressWarnings("unchecked")
+			final Map<String, Object> params = request.getParameterMap();
+			ThreadUtil.run(new Runnable() {
+				@Override
+				public void run() {
+					// 璁板綍璇锋眰鏃ュ織
+					LogHelper.requestInfo(url, params);
+				}
+			});
 
 			Object obj = null;
 			try {
+				long startTime = System.currentTimeMillis();
 				obj = joinPoint.proceed(args);
-			} catch (Throwable e) {
-				e.printStackTrace();
-				try {
-					LogHelper.errorDetailInfo(e, getHttpServletParams(request), request.getRequestURI().toString());
-				} catch (Exception e1) {
-					e1.printStackTrace();
+				final long responseTime = System.currentTimeMillis() - startTime;
+				// 璁板綍澶т簬2s鐨勮姹�
+				if (responseTime >= 2000) {
+					ThreadUtil.run(new Runnable() {
+
+						@Override
+						public void run() {
+							LogHelper.requestTime(url, params, responseTime);
+						}
+					});
+
 				}
+
+			} catch (Throwable e) {
+				LogHelper.errorDetailInfo(e, getHttpServletParams(request), request.getRequestURI().toString());
+				if (!Constant.IS_TEST)
+					out.print(JsonUtil.loadFalseResult(90009, "鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�"));
+				else
+					throw e;
 			}
 			return obj;
 		} else {
@@ -112,7 +136,7 @@
 			data.put("msg", "绛惧悕閿欒");
 			out.print(data);
 			out.close();
-			LogHelper.error("绛惧悕閿欒:" + getHttpServletParams(request));
+			LogHelper.error("绛惧悕閿欒:" + request.getRequestURI() + "-" + getHttpServletParams(request));
 			return null;
 		}
 	}
@@ -171,9 +195,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;
@@ -199,4 +223,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;
+		}
+
+	}
+
 }

--
Gitblit v1.8.0