| | |
| | | import org.apache.commons.httpclient.HttpClient; |
| | | import org.apache.commons.httpclient.HttpException; |
| | | import org.apache.commons.httpclient.methods.GetMethod; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | | import org.jsoup.nodes.Element; |
| | |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | | public class DaTaoKeApiUtil { |
| | | |
| | | final static String API_CHARSET = "ISO-8859-1"; |
| | | |
| | | final static String API_KEY = "a083abb893"; |
| | | final static String API_KEY_2 = "b7a5ea2cd9"; |
| | | |
| | |
| | | final static String[] APP_SECRETS = new String[] { APP_KEY_SECRET, APP_KEY_SECRET_2 }; |
| | | |
| | | static Gson gson = null; |
| | | |
| | | static { |
| | | gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() { |
| | | @Override |
| | |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | private static String baseGet(String url, Map<String, String> params) { |
| | | HttpClient client = new HttpClient(); |
| | | try { |
| | | Iterator<String> keys = params.keySet().iterator(); |
| | | String key; |
| | | for (url = url + "?"; keys.hasNext(); url = url + String.format("%s=%s&", key, URLEncoder.encode((String) params.get(key), "UTF-8"))) { |
| | | key = keys.next(); |
| | | } |
| | | |
| | | GetMethod method = new GetMethod(url); |
| | | client.executeMethod(method); |
| | | InputStream inputStream = method.getResponseBodyAsStream(); |
| | | String result = IOUtils.toString(inputStream, API_CHARSET); |
| | | return result; |
| | | } catch (Exception var7) { |
| | | var7.printStackTrace(); |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | |
| | | private static String request(String url) { |
| | | String result = null; |
| | |
| | | params.put("pageId", pageId); |
| | | } |
| | | params.put("sign", getSign(params, app.getAppSecret())); |
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-goods-list", params, new HashMap<>()); |
| | | String result = baseGet("https://openapi.dataoke.com/api/goods/get-goods-list", params); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | JSONObject dataJson = json.optJSONObject("data"); |
| | | if (dataJson != null) { |
| | |
| | | params.put("pageId", pageId); |
| | | |
| | | params.put("sign", getSign(params, app.getAppSecret())); |
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-stale-goods-by-time", params, |
| | | new HashMap<>()); |
| | | String result = baseGet("https://openapi.dataoke.com/api/goods/get-stale-goods-by-time", params); |
| | | System.out.println(result); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | JSONObject dataJson = json.optJSONObject("data"); |
| | |
| | | params.put("pageId", pageId); |
| | | |
| | | params.put("sign", getSign(params, app.getAppSecret())); |
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/pull-goods-by-time", params, |
| | | new HashMap<>()); |
| | | String result = baseGet("https://openapi.dataoke.com/api/goods/pull-goods-by-time", params); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | JSONObject dataJson = json.optJSONObject("data"); |
| | | if (dataJson != null) { |
| | |
| | | params.put("pageId", pageId); |
| | | |
| | | params.put("sign", getSign(params, app.getAppSecret())); |
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-newest-goods", params, new HashMap<>()); |
| | | String result = baseGet("https://openapi.dataoke.com/api/goods/get-newest-goods", params); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | JSONObject dataJson = json.optJSONObject("data"); |
| | | if (dataJson != null) { |
| | |
| | | params.put("appKey", app.getAppKey()); |
| | | params.put("id", id + ""); |
| | | params.put("sign", getSign(params, app.getAppSecret())); |
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-goods-details", params, |
| | | new HashMap<>()); |
| | | String result = baseGet("https://openapi.dataoke.com/api/goods/get-goods-details", params); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | JSONObject dataJson = json.optJSONObject("data"); |
| | | if (dataJson != null) { |
| | |
| | | params.put("appKey", app.getAppKey()); |
| | | params.put("goodsId", goodsId + ""); |
| | | params.put("sign", getSign(params, app.getAppSecret())); |
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-goods-details", params, |
| | | new HashMap<>()); |
| | | String result = baseGet("https://openapi.dataoke.com/api/goods/get-goods-details", params); |
| | | System.out.println(result); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | JSONObject dataJson = json.optJSONObject("data"); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | return HttpUtil.get(url, 10000); |
| | | String result = HttpUtil.get(url, 10000); |
| | | |
| | | try { |
| | | if (result != null) |
| | | return new String(result.getBytes("ISO-8859-1"), "UTF-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static DaTaoKeGoodsResult search(String key, List<Integer> cidList, BigDecimal priceLowerLimit, |
| | |
| | | } |
| | | |
| | | params.put("sign", getSign(params, app.getAppSecret())); |
| | | String result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-goods-list", params, new HashMap<>()); |
| | | String result = baseGet("https://openapi.dataoke.com/api/goods/get-goods-list", params); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | JSONObject dataJson = json.optJSONObject("data"); |
| | | if (dataJson != null) { |
| | |
| | | int userType = 0; |
| | | List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>(); |
| | | |
| | | String result = HttpUtil.get("http://www.dataoke.com/brandGoods?id=" + brandId + "&page=1"); |
| | | String result = baseGet("http://www.dataoke.com/brandGoods?id=" + brandId + "&page=1", new HashMap<>()); |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | JSONArray arrayGoods = json.optJSONArray("goods"); |
| | | |
| | |
| | | // 做2次请求 |
| | | String result = null; |
| | | try { |
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-ranking-list", params, new HashMap<>()); |
| | | result = baseGet("https://openapi.dataoke.com/api/goods/get-ranking-list", params); |
| | | } catch (Exception e) { |
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/goods/get-ranking-list", params, new HashMap<>()); |
| | | result = baseGet("https://openapi.dataoke.com/api/goods/get-ranking-list", params); |
| | | } |
| | | |
| | | try { |
| | | |
| | | // System.out.println("GBK:"+new String(result.getBytes("GBK"),"UTF-8")); |
| | | // System.out.println("ISO-8859-1:"+new String(result.getBytes("ISO-8859-1"),"UTF-8")); |
| | | // System.out.println("GB2312:"+new String(result.getBytes("GB2312"),"UTF-8")); |
| | | |
| | | result = new String(result.getBytes("ISO-8859-1"), "UTF-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | if (json != null) { |
| | | JSONArray array = json.optJSONArray("data"); |
| | |
| | | |
| | | String result = null; |
| | | try { |
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/category/get-top100", params, new HashMap<>()); |
| | | result = baseGet("https://openapi.dataoke.com/api/category/get-top100", params); |
| | | } catch (Exception e) { |
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/category/get-top100", params, new HashMap<>()); |
| | | result = baseGet("https://openapi.dataoke.com/api/category/get-top100", params); |
| | | } |
| | | |
| | | String hotWords = null; |
| | |
| | | |
| | | /** |
| | | * 高效转链 |
| | | * |
| | | * @param auctionId |
| | | * @param pid void 返回类型 |
| | | * @throws |
| | | * @Title: convertLink |
| | | * @Description: |
| | | * @param auctionId |
| | | * @param pid |
| | | * void 返回类型 |
| | | * @throws |
| | | */ |
| | | public static String convertLink(Long auctionId, String pid) { |
| | | TaoKeAppInfo app = APP_KEYS[0]; |
| | |
| | | |
| | | String result = null; |
| | | try { |
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/tb-service/get-privilege-link", params, |
| | | new HashMap<>()); |
| | | result = baseGet("https://openapi.dataoke.com/api/tb-service/get-privilege-link", params); |
| | | } catch (Exception e) { |
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/tb-service/get-privilege-link", params, |
| | | new HashMap<>()); |
| | | result = baseGet("https://openapi.dataoke.com/api/tb-service/get-privilege-link", params); |
| | | } |
| | | |
| | | System.out.println(result); |
| | |
| | | |
| | | /** |
| | | * 朋友圈 |
| | | * |
| | | * @param pageId |
| | | * @return |
| | | */ |
| | |
| | | |
| | | String result = null; |
| | | try { |
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/goods/friends-circle-list", params, new HashMap<>()); |
| | | result = baseGet("https://openapi.dataoke.com/api/goods/friends-circle-list", params); |
| | | } catch (Exception e) { |
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/goods/friends-circle-list", params, new HashMap<>()); |
| | | result = baseGet("https://openapi.dataoke.com/api/goods/friends-circle-list", params); |
| | | } |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | JSONObject dataJson = json.optJSONObject("data"); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 9.9包邮精选 |
| | | * |
| | | * @param pageId |
| | | * @return |
| | | */ |
| | |
| | | |
| | | String result = null; |
| | | try { |
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/goods/nine/op-goods-list", params, new HashMap<>()); |
| | | result = baseGet("https://openapi.dataoke.com/api/goods/nine/op-goods-list", params); |
| | | } catch (Exception e) { |
| | | result = HttpUtil.get("https://openapi.dataoke.com/api/goods/nine/op-goods-list", params, new HashMap<>()); |
| | | result = baseGet("https://openapi.dataoke.com/api/goods/nine/op-goods-list", params); |
| | | } |
| | | JSONObject json = JSONObject.fromObject(result); |
| | | JSONObject dataJson = json.optJSONObject("data"); |