| | |
| | | package com.yeshi.fanli.util.jd;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.math.BigDecimal;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | |
| | | return searchResult;
|
| | | }
|
| | |
|
| | | public static JDGoods getGoodsDetail(Long skuId) {
|
| | | JDSearchFilter sf = new JDSearchFilter();
|
| | | sf.setKey(skuId + "");
|
| | | sf.setPageNo(1);
|
| | | sf.setPageSize(20);
|
| | | JDSearchResult result = searchByKey(sf);
|
| | | if (result != null && result.getGoodsList() != null && result.getGoodsList().size() > 0)
|
| | | return result.getGoodsList().get(0);
|
| | | return null;
|
| | | }
|
| | |
|
| | | private static JDGoods parseGoods(String data) {
|
| | | JDGoods goods = new JDGoods();
|
| | | JSONObject json = JSONObject.fromObject(data);
|
| | |
| | | goods.setOwner("g");
|
| | | else
|
| | | goods.setOwner("p");
|
| | | goods.setMaterialUrl("http://img14.360buyimg.com/n1/"+json.optString("materialUrl"));
|
| | | goods.setMaterialUrl("http://img14.360buyimg.com/n1/" + json.optString("materialUrl"));
|
| | | JDCommissionInfo commission = new JDCommissionInfo();
|
| | | commission.setCommission(new BigDecimal(json.optString("wlCommission")));
|
| | | commission.setCommissionShare(new BigDecimal(json.optString("wlCommissionRatio")));
|
| | |
| | | return goods;
|
| | | }
|
| | |
|
| | | public static List<String> suggestSearch(String key) {
|
| | | List<String> list = new ArrayList<>();
|
| | | if (StringUtil.isNullOrEmpty(key))
|
| | | return list;
|
| | | String url = null;
|
| | | try {
|
| | | url = String.format(
|
| | | "https://wq.jd.com/bases/searchdropdown/getdropdown?terminal=m&zip=1&key=%s&newjson=1&_=%s&sceneval=2",
|
| | | URLEncoder.encode(key, "UTF-8"), System.currentTimeMillis() + "");
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | if (url == null)
|
| | | return list;
|
| | | try {
|
| | | String result = HttpUtil.get(url);
|
| | | result = result.replace("callback(", "").replace(")", "");
|
| | | JSONArray array = JSONArray.fromObject(result);
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | String sk = array.optJSONObject(i).optString("key");
|
| | | if (!StringUtil.isNullOrEmpty(sk))
|
| | | list.add(sk);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | }
|