admin
2019-05-29 dd24286b6da752433ba5b2360929a04e5040936c
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;
@@ -59,6 +60,7 @@
         }
      } else
         throw new TaoKeApiException(TaoKeApiException.CODE_OTHER, ":" + result, params);
      reValid(app.getAppKey());
      return data;
   }
@@ -82,7 +84,8 @@
      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);
@@ -96,6 +99,7 @@
         }
      } else
         throw new TaoKeApiException(TaoKeApiException.CODE_OTHER, ":" + result, params);
      reValid(app.getAppKey());
      return data;
   }
@@ -118,6 +122,13 @@
            TaoKeLogHelper.error(e.getParams(), e.getMsg());
            if (e.getCode() == TaoKeApiException.CODE_API_ERROR) {
               result = e.getMsg();
            } else if (e.getCode() == TaoKeApiException.CODE_APPKEY_LIMIT) {
               try {
                  EmergencyUtil.baoJin("monitor-error-tb-app-limit-" + params.get("app_key"),
                        "淘宝APPKey请求限制【" + params.get("app_key") + "】", new String[] { "18581318252" });
               } catch (Exception e1) {
               }
            }
         }
      }
@@ -255,6 +266,8 @@
    * @param appkey
    */
   static void reportAppInvalid(String appkey) {
      if (invalidMap == null)
         return;
      // 错误三次后再真正上报
      if (invalidMap.get(appkey) == null)
         invalidMap.put(appkey, 1);
@@ -268,6 +281,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");
   }