From 271ae63c20fcbe28d29c47f1881138ff6551a2a1 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 10 六月 2020 19:26:26 +0800
Subject: [PATCH] 唯品会订单bug修复,APP端佣金比例展示错误bug修复

---
 fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeBaseUtil.java |   93 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 88 insertions(+), 5 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeBaseUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeBaseUtil.java
index eb562d1..80c2c1c 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeBaseUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeBaseUtil.java
@@ -10,6 +10,7 @@
 import com.yeshi.fanli.exception.taobao.TaoKeApiException;
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.log.TaoKeLogHelper;
+import com.yeshi.fanli.util.EmergencyUtil;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.TaoBaoHttpUtil;
 import com.yeshi.fanli.util.TimeUtil;
@@ -49,16 +50,80 @@
 		String result = TaoBaoHttpUtil.taoKeGet(params);
 		JSONObject data = JSONObject.fromObject(result);
 		if (data != null) {
-			if (data.optJSONObject("error_response") != null
-					&& data.optJSONObject("error_response").optInt("code") == 7) {
+			if (data.optJSONObject("error_response") != null && data.optJSONObject("error_response").optInt("code") == 7
+					&& "accesscontrol.limited-by-app-access-count"
+							.equalsIgnoreCase(data.optJSONObject("error_response").optString("sub_code"))) {
 				reportAppInvalid(app.getAppKey());
 				TaoKeLogHelper.error(params, result);
+				try {
+					EmergencyUtil.baoJin("monitor-error-tb-app-limit-" + params.get("app_key"),
+							"娣樺疂APPKey璇锋眰闄愬埗銆�" + params.get("app_key") + "銆�", new String[] { "18581318252" });
+				} catch (Exception e1) {
+				}
 				throw new TaoKeApiException(TaoKeApiException.CODE_APPKEY_LIMIT, "娣樺疂璇锋眰闄愬埗:" + result, params);
 			} else if (data.optJSONObject("error_response") != null) {
 				throw new TaoKeApiException(TaoKeApiException.CODE_API_ERROR, result, params);
 			}
 		} else
 			throw new TaoKeApiException(TaoKeApiException.CODE_OTHER, ":" + result, params);
+		reValid(app.getAppKey());
+		return data;
+	}
+	
+	
+	/**
+	 * 鏈嶅姟鍟嗚姹�
+	 * @Title: baseScRequest
+	 * @Description: 
+	 * @param param
+	 * @param session
+	 * @return
+	 * @throws TaoKeApiException 
+	 * JSONObject 杩斿洖绫诲瀷
+	 * @throws
+	 */
+	public static JSONObject baseScRequest(Map<String, String> param,TaoKeAppInfo app, String session,String targetAppKey) throws TaoKeApiException {
+		// 澶嶅埗params
+		Map<String, String> params = new HashMap<>();
+		if (param != null) {
+			Iterator<String> its = param.keySet().iterator();
+			while (its.hasNext()) {
+				String key = its.next();
+				params.put(key, param.get(key));
+			}
+		}
+
+		if (app == null)
+			throw new TaoKeApiException(TaoKeApiException.CODE_NO_USE, "鏃燼ppkey鍙敤");
+		// 绛惧悕
+		params.put("app_key", app.getAppKey());
+		params.put("sign_method", "md5");
+		params.put("v", "2.0");
+		params.put("timestamp", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
+		params.put("format", "json");
+		params.put("session", session);
+//		params.put("target_app_key", targetAppKey);
+		params.put("sign", getSign(params, "md5", app).toUpperCase());
+		String result = TaoBaoHttpUtil.taoKeGet(params);
+		JSONObject data = JSONObject.fromObject(result);
+		if (data != null) {
+			if (data.optJSONObject("error_response") != null && data.optJSONObject("error_response").optInt("code") == 7
+					&& "accesscontrol.limited-by-app-access-count"
+							.equalsIgnoreCase(data.optJSONObject("error_response").optString("sub_code"))) {
+				reportAppInvalid(app.getAppKey());
+				TaoKeLogHelper.error(params, result);
+				try {
+					EmergencyUtil.baoJin("monitor-error-tb-app-limit-" + params.get("app_key"),
+							"娣樺疂APPKey璇锋眰闄愬埗銆�" + params.get("app_key") + "銆�", new String[] { "18581318252" });
+				} catch (Exception e1) {
+				}
+				throw new TaoKeApiException(TaoKeApiException.CODE_APPKEY_LIMIT, "娣樺疂璇锋眰闄愬埗:" + result, params);
+			} else if (data.optJSONObject("error_response") != null) {
+				throw new TaoKeApiException(TaoKeApiException.CODE_API_ERROR, result, params);
+			}
+		} else
+			throw new TaoKeApiException(TaoKeApiException.CODE_OTHER, ":" + result, params);
+//		reValid(app.getAppKey());
 		return data;
 	}
 
@@ -82,13 +147,15 @@
 		params.put("v", "2.0");
 		params.put("timestamp", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
 		params.put("format", "json");
-		params.put("adzone_id", app.getAdzoneId());
+		if (!StringUtil.isNullOrEmpty(app.getAdzoneId()))
+			params.put("adzone_id", app.getAdzoneId());
 		params.put("sign", getSign(params, "md5", app).toUpperCase());
 		String result = TaoBaoHttpUtil.taoKeGet(params);
 		JSONObject data = JSONObject.fromObject(result);
 		if (data != null) {
-			if (data.optJSONObject("error_response") != null
-					&& data.optJSONObject("error_response").optInt("code") == 7) {
+			if (data.optJSONObject("error_response") != null && data.optJSONObject("error_response").optInt("code") == 7
+					&& "accesscontrol.limited-by-app-access-count"
+							.equalsIgnoreCase(data.optJSONObject("error_response").optString("sub_code"))) {
 				reportAppInvalid(app.getAppKey());
 				throw new TaoKeApiException(TaoKeApiException.CODE_APPKEY_LIMIT, "娣樺疂璇锋眰闄愬埗:" + result, params);
 			} else if (data.optJSONObject("error_response") != null) {
@@ -96,6 +163,7 @@
 			}
 		} else
 			throw new TaoKeApiException(TaoKeApiException.CODE_OTHER, ":" + result, params);
+		reValid(app.getAppKey());
 		return data;
 	}
 
@@ -255,6 +323,8 @@
 	 * @param appkey
 	 */
 	static void reportAppInvalid(String appkey) {
+		if (invalidMap == null)
+			return;
 		// 閿欒涓夋鍚庡啀鐪熸涓婃姤
 		if (invalidMap.get(appkey) == null)
 			invalidMap.put(appkey, 1);
@@ -268,6 +338,19 @@
 		lastTime = 0;
 	}
 
+	/**
+	 * APPKey鎭㈠鍙敤
+	 * 
+	 * @param appKey
+	 */
+	static void reValid(String appKey) {
+		if (invalidMap == null)
+			return;
+		Integer count = invalidMap.get(appKey);
+		if (count != null && count > 0)
+			invalidMap.put(appKey, count - 1);
+	}
+
 	public static void setAppValid() {
 		HttpUtil.get("http://193.112.35.168:8091/tb/taoke/setappcanuse");
 	}

--
Gitblit v1.8.0