| | |
| | | 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;
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | |
| | | 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) {
|
| | |
| | | }
|
| | | } else
|
| | | throw new TaoKeApiException(TaoKeApiException.CODE_OTHER, ":" + result, params);
|
| | | reValid(app.getAppKey());
|
| | | return data;
|
| | | }
|
| | |
|
| | |
| | | data = JSONObject.fromObject(result);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | |
| | |
|
| | | }
|
| | |
|
| | | if (data != null)
|
| | |
| | | } catch (Exception e) {
|
| | | }
|
| | |
|
| | | // 接口请求失败,默认设置成返利券Android的媒体信息
|
| | | // 接口请求失败,默认设置成影视大全IOS的媒体信息
|
| | | if (StringUtil.isNullOrEmpty(result)) {
|
| | | taoKeAppInfo = new TaoKeAppInfo();
|
| | | taoKeAppInfo.setAdzoneId("10647300249");
|
| | | taoKeAppInfo.setAppKey("24980167");
|
| | | taoKeAppInfo.setAppSecret("e0a2e05deabf5ce039b52e5b492d5382");
|
| | | taoKeAppInfo.setPid("mm_124933865_56750082_10647300249");
|
| | | taoKeAppInfo.setAdzoneId("381938426");
|
| | | taoKeAppInfo.setAppKey("24838852");
|
| | | taoKeAppInfo.setAppSecret("bc8265e2bf8d8115329d652f9d3d4cd8");
|
| | | taoKeAppInfo.setPid("mm_124933865_43788020_381938426");
|
| | | lastTime = System.currentTimeMillis();
|
| | | return taoKeAppInfo;
|
| | | }
|
| | |
| | | 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 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");
|
| | | }
|