admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/util/taobao/TaoKeBaseUtil.java
@@ -1,358 +1,362 @@
package com.yeshi.fanli.util.taobao;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.taobao.api.internal.util.StringUtils;
import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
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;
import org.yeshi.utils.HttpUtil;
import net.sf.json.JSONObject;
public class TaoKeBaseUtil {
   private static TaoKeAppInfo taoKeAppInfo = null;
   private static long lastTime = 0;
   public static JSONObject baseRequest(Map<String, String> param, boolean needAdzoneId) 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));
         }
      }
      // 获取有效的APPKey
      TaoKeAppInfo app = getAvailableTaoKeAppInfo();
      if (app == null)
         throw new TaoKeApiException(TaoKeApiException.CODE_NO_USE, "无appkey可用");
      // 签名
      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");
      if (needAdzoneId)
         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
               && "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, "无appkey可用");
      // 签名
      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;
   }
   public static JSONObject baseRequest(Map<String, String> param, TaoKeAppInfo app) 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));
         }
      }
      // 获取有效的APPKey
      if (app == null)
         throw new TaoKeApiException(TaoKeApiException.CODE_NO_USE, "无appkey可用");
      // 签名
      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");
      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
               && "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) {
            throw new TaoKeApiException(TaoKeApiException.CODE_API_ERROR, result, params);
         }
      } else
         throw new TaoKeApiException(TaoKeApiException.CODE_OTHER, ":" + result, params);
      reValid(app.getAppKey());
      return data;
   }
   /**
    * 重复3次请求,降低出错概率
    *
    * @param params
    * @return
    */
   public static String baseRequestForThreeTimes(Map<String, String> params, boolean needAdzoneId) {
      JSONObject data = null;
      int count = 0;
      String result = null;
      while (data == null && count < 2) {
         count++;
         try {
            data = baseRequest(params, needAdzoneId);
         } catch (TaoKeApiException e) {
            // 记录现场
            TaoKeLogHelper.error(e.getParams(), e.getMsg());
            if (e.getCode() == TaoKeApiException.CODE_API_ERROR) {
               result = e.getMsg();
            }
         }
      }
      if (!StringUtil.isNullOrEmpty(result)) {
         try {
            data = JSONObject.fromObject(result);
         } catch (Exception e) {
         }
      }
      if (data != null)
         return data.toString();
      else
         return new JSONObject().toString();
   }
   public static String baseRequestForThreeTimes(Map<String, String> params, TaoKeAppInfo app) {
      JSONObject data = null;
      int count = 0;
      while (data == null && count < 3) {
         count++;
         try {
            data = baseRequest(params, app);
         } catch (TaoKeApiException e) {
            // 记录现场
            TaoKeLogHelper.error(e.getParams(), e.getMsg());
         }
      }
      if (data != null)
         return data.toString();
      else
         return new JSONObject().toString();
   }
   /**
    * 获取签名参数
    *
    * @param params
    * @param signMethod
    * @param app
    * @return
    */
   public static String getSign(Map<String, String> params, String signMethod, TaoKeAppInfo app) {
      // 第一步:检查参数是否已经排序
      String[] keys = params.keySet().toArray(new String[0]);
      Arrays.sort(keys);
      // 第二步:把所有参数名和参数值串在一起
      StringBuilder query = new StringBuilder();
      if ("md5".equals(signMethod)) {
         query.append(app.getAppSecret());
      }
      for (String key : keys) {
         String value = params.get(key);
         if (StringUtils.areNotEmpty(key, value)) {
            query.append(key).append(value);
         }
      }
      query.append(app.getAppSecret());
      return StringUtil.Md5(query.toString());
   }
   static TaoKeAppInfo getAvailableTaoKeAppInfo() {
      if (System.currentTimeMillis() - lastTime > 1000 * 20L)
         taoKeAppInfo = null;
      if (taoKeAppInfo == null) {
         System.out.println("请求。。。。。");
         String result = null;
         try {
            result = HttpUtil.get("http://193.112.35.168:8091/tb/taoke/getcanuseapp");
         } catch (Exception e) {
         }
         // 接口请求失败,默认设置成影视大全IOS的媒体信息
         if (StringUtil.isNullOrEmpty(result)) {
            taoKeAppInfo = new TaoKeAppInfo();
            taoKeAppInfo.setAdzoneId("381938426");
            taoKeAppInfo.setAppKey("24838852");
            taoKeAppInfo.setAppSecret("bc8265e2bf8d8115329d652f9d3d4cd8");
            taoKeAppInfo.setPid("mm_124933865_43788020_381938426");
            lastTime = System.currentTimeMillis();
            return taoKeAppInfo;
         }
         JSONObject data = JSONObject.fromObject(result);
         if (data.optInt("code") == 0) {
            TaoKeAppInfo info = new TaoKeAppInfo();
            info.setAppKey(data.optJSONObject("data").optString("appkey"));
            info.setAppSecret(data.optJSONObject("data").optString("appsecret"));
            info.setPid(data.optJSONObject("data").optString("pid"));
            String[] sts = info.getPid().split("_");
            info.setAdzoneId(sts[sts.length - 1]);
            taoKeAppInfo = info;
            lastTime = System.currentTimeMillis();
         } else {// 防止所有的失效
            taoKeAppInfo = new TaoKeAppInfo();
            taoKeAppInfo.setAdzoneId("381938426");
            taoKeAppInfo.setAppKey("24838852");
            taoKeAppInfo.setAppSecret("bc8265e2bf8d8115329d652f9d3d4cd8");
            taoKeAppInfo.setPid("mm_124933865_43788020_381938426");
            return taoKeAppInfo;
         }
      }
      return taoKeAppInfo;
   }
   static void filterTaoKeResponse(String result, TaoKeAppInfo app) {
      if (!StringUtil.isNullOrEmpty(result)) {
         try {
            JSONObject data = JSONObject.fromObject(result);
            if (data != null) {
               if (data.optJSONObject("error_response") != null
                     && data.optJSONObject("error_response").optInt("code") == 7) {
                  reportAppInvalid(app.getAppKey());
               }
            } else
               LogHelper.test(result);
         } catch (Exception e) {
            try {
               LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
               e1.printStackTrace();
            }
         }
      }
   }
   static Map<String, Integer> invalidMap = new HashMap<>();
   /**
    * 报告该APPKey不能用
    *
    * @param appkey
    */
   static void reportAppInvalid(String appkey) {
      if (invalidMap == null)
         return;
      // 错误三次后再真正上报
      if (invalidMap.get(appkey) == null)
         invalidMap.put(appkey, 1);
      else
         invalidMap.put(appkey, invalidMap.get(appkey) + 1);
      if (invalidMap.get(appkey) < 4)
         return;
      invalidMap.put(appkey, 0);
      HttpUtil.get("http://193.112.35.168:8091/tb/taoke/reportappcannotuse?appkey=" + appkey);
      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");
   }
}
package com.yeshi.fanli.util.taobao;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.google.gson.Gson;
import com.taobao.api.internal.util.StringUtils;
import com.yeshi.common.entity.taobao.TaoKeAppInfo;
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 org.yeshi.utils.TimeUtil;
import org.yeshi.utils.HttpUtil;
import net.sf.json.JSONObject;
public class TaoKeBaseUtil {
   private static TaoKeAppInfo taoKeAppInfo = null;
   private static long lastTime = 0;
   public static JSONObject baseRequest(Map<String, String> param, boolean needAdzoneId) 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));
         }
      }
      // 获取有效的APPKey
      TaoKeAppInfo app = getAvailableTaoKeAppInfo();
      if (app == null)
         throw new TaoKeApiException(TaoKeApiException.CODE_NO_USE, "无appkey可用");
      // 签名
      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");
      if (needAdzoneId)
         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
               && "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, "无appkey可用");
      // 签名
      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;
   }
   public static JSONObject baseRequest(Map<String, String> param, TaoKeAppInfo app) 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));
         }
      }
      // 获取有效的APPKey
      if (app == null)
         throw new TaoKeApiException(TaoKeApiException.CODE_NO_USE, "无appkey可用");
      // 签名
      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");
      if (!StringUtil.isNullOrEmpty(app.getAdzoneId()))
         params.put("adzone_id", app.getAdzoneId());
      params.put("sign", getSign(params, "md5", app).toUpperCase());
      System.out.println(new Gson().toJson(params));
      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());
            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;
   }
   /**
    * 重复3次请求,降低出错概率
    *
    * @param params
    * @return
    */
   public static String baseRequestForThreeTimes(Map<String, String> params, boolean needAdzoneId) {
      JSONObject data = null;
      int count = 0;
      String result = null;
      while (data == null && count < 2) {
         count++;
         try {
            data = baseRequest(params, needAdzoneId);
         } catch (TaoKeApiException e) {
            // 记录现场
            TaoKeLogHelper.error(e.getParams(), e.getMsg());
            if (e.getCode() == TaoKeApiException.CODE_API_ERROR) {
               result = e.getMsg();
            }
         }
      }
      if (!StringUtil.isNullOrEmpty(result)) {
         try {
            data = JSONObject.fromObject(result);
         } catch (Exception e) {
         }
      }
      if (data != null)
         return data.toString();
      else
         return new JSONObject().toString();
   }
   public static String baseRequestForThreeTimes(Map<String, String> params, TaoKeAppInfo app) {
      JSONObject data = null;
      int count = 0;
      while (data == null && count < 3) {
         count++;
         try {
            data = baseRequest(params, app);
         } catch (TaoKeApiException e) {
            // 记录现场
            TaoKeLogHelper.error(e.getParams(), e.getMsg());
         }
      }
      if (data != null)
         return data.toString();
      else
         return new JSONObject().toString();
   }
   /**
    * 获取签名参数
    *
    * @param params
    * @param signMethod
    * @param app
    * @return
    */
   public static String getSign(Map<String, String> params, String signMethod, TaoKeAppInfo app) {
      // 第一步:检查参数是否已经排序
      String[] keys = params.keySet().toArray(new String[0]);
      Arrays.sort(keys);
      // 第二步:把所有参数名和参数值串在一起
      StringBuilder query = new StringBuilder();
      if ("md5".equals(signMethod)) {
         query.append(app.getAppSecret());
      }
      for (String key : keys) {
         String value = params.get(key);
         if (StringUtils.areNotEmpty(key, value)) {
            query.append(key).append(value);
         }
      }
      query.append(app.getAppSecret());
      return StringUtil.Md5(query.toString());
   }
   static TaoKeAppInfo getAvailableTaoKeAppInfo() {
      if (System.currentTimeMillis() - lastTime > 1000 * 20L)
         taoKeAppInfo = null;
      if (taoKeAppInfo == null) {
         System.out.println("请求。。。。。");
         String result = null;
//         try {
//            result = HttpUtil.get("http://193.112.35.168:8091/tb/taoke/getcanuseapp");
//         } catch (Exception e) {
//         }
         // 接口请求失败,默认设置成影视大全IOS的媒体信息
         if (StringUtil.isNullOrEmpty(result)) {
            taoKeAppInfo = new TaoKeAppInfo();
            taoKeAppInfo.setAdzoneId("381938426");
            taoKeAppInfo.setAppKey("24838852");
            taoKeAppInfo.setAppSecret("bc8265e2bf8d8115329d652f9d3d4cd8");
            taoKeAppInfo.setPid("mm_124933865_43788020_381938426");
            lastTime = System.currentTimeMillis();
            return taoKeAppInfo;
         }
         JSONObject data = JSONObject.fromObject(result);
         if (data.optInt("code") == 0) {
            TaoKeAppInfo info = new TaoKeAppInfo();
            info.setAppKey(data.optJSONObject("data").optString("appkey"));
            info.setAppSecret(data.optJSONObject("data").optString("appsecret"));
            info.setPid(data.optJSONObject("data").optString("pid"));
            String[] sts = info.getPid().split("_");
            info.setAdzoneId(sts[sts.length - 1]);
            taoKeAppInfo = info;
            lastTime = System.currentTimeMillis();
         } else {// 防止所有的失效
            taoKeAppInfo = new TaoKeAppInfo();
            taoKeAppInfo.setAdzoneId("381938426");
            taoKeAppInfo.setAppKey("24838852");
            taoKeAppInfo.setAppSecret("bc8265e2bf8d8115329d652f9d3d4cd8");
            taoKeAppInfo.setPid("mm_124933865_43788020_381938426");
            return taoKeAppInfo;
         }
      }
      return taoKeAppInfo;
   }
   static void filterTaoKeResponse(String result, TaoKeAppInfo app) {
      if (!StringUtil.isNullOrEmpty(result)) {
         try {
            JSONObject data = JSONObject.fromObject(result);
            if (data != null) {
               if (data.optJSONObject("error_response") != null
                     && data.optJSONObject("error_response").optInt("code") == 7) {
                  reportAppInvalid(app.getAppKey());
               }
            } else
               LogHelper.test(result);
         } catch (Exception e) {
            try {
               LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
               e1.printStackTrace();
            }
         }
      }
   }
   static Map<String, Integer> invalidMap = new HashMap<>();
   /**
    * 报告该APPKey不能用
    *
    * @param appkey
    */
   static void reportAppInvalid(String appkey) {
      if (invalidMap == null)
         return;
      // 错误三次后再真正上报
      if (invalidMap.get(appkey) == null)
         invalidMap.put(appkey, 1);
      else
         invalidMap.put(appkey, invalidMap.get(appkey) + 1);
      if (invalidMap.get(appkey) < 4)
         return;
      invalidMap.put(appkey, 0);
      HttpUtil.get("http://193.112.35.168:8091/tb/taoke/reportappcannotuse?appkey=" + appkey);
      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");
   }
}