admin
2019-07-31 f253c6f0ce5e708850f8e3c84a6a9008fc37df5f
fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java
@@ -6,6 +6,7 @@
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -41,9 +42,9 @@
   public static String SECRET_KEY = "fb49bc6ecac5458ba5394fc2969d7c56";
   private static String SERVER_URL = "https://router.jd.com/api";
   public static Long POSITION_FANLI = 1834339426L;
   public static Long POSITION_SHARE = 1834289924L;
   public static Long POSITION_COUPON = 1859510742L;
   public static long POSITION_FANLI = 1834339426L;
   public static long POSITION_SHARE = 1834289924L;
   public static long POSITION_COUPON = 1859510742L;
   // 订单查询类型
   public static int ORDER_TYPE_CREATETIME = 1;// 下单时间
@@ -131,7 +132,6 @@
      return result;
   }
   private static String baseRequest2(String method, String accessToken, JSONObject params) {
      Map<String, String> baseMap = new HashMap<String, String>();
      baseMap.put("param_json", params.toString());
@@ -182,6 +182,7 @@
   
   /**
    * 转链接-短连接
    *
    * @param materialId
    * @param couponUrl
    * @param positionId
@@ -195,7 +196,6 @@
      }
      return url;
   }
   
   public static JDGoods queryGoodsDetail(Long skuId) {
      List<Long> skuIdList = new ArrayList<>();
@@ -215,6 +215,7 @@
   
   /**
    * 关键词商品查询接口【申请】
    *
    * @param skuIdList
    * @return
    */
@@ -288,7 +289,6 @@
      JSONObject jsonDTO = new JSONObject();
      jsonDTO.put("goodsReqDTO", json);
      
      String result = baseRequest2("jd.union.open.goods.query", null, jsonDTO);
      System.out.println(result);
      JSONObject resultJson = JSONObject.fromObject(result);
@@ -318,9 +318,6 @@
      return searchResult;
   }
   
   private static JDGoods parseJDGoods(JSONObject json) {
      JDGoods goods = new JDGoods();
      
@@ -348,7 +345,6 @@
      goods.setSkuName(json.optString("skuName"));
      goods.setIsHot(json.optInt("isHot"));
      
      // 价格信息
      Object priceInfo = json.get("priceInfo");
      JSONObject priceInfoJson = JSONObject.fromObject(priceInfo);
@@ -362,7 +358,6 @@
      jdshopInfo.setShopName(shopInfoJson.optString("shopName"));
      goods.setShopInfo(jdshopInfo);
      
      // 分类信息
      Object category = json.get("categoryInfo");
      JSONObject categoryJson = JSONObject.fromObject(category);
@@ -374,7 +369,6 @@
      categoryInfo.setCid3(categoryJson.optLong("cid3"));
      categoryInfo.setCid3Name(categoryJson.optString("cid3Name"));
      goods.setCategoryInfo(categoryInfo);
      
      // 图片信息
      List<String> imageList = new ArrayList<String>();
@@ -407,8 +401,6 @@
            goods.setPinGouInfo(jdPinGouInfo);
         }
      }
      
      // 券信息
      Object coupon = json.get("couponInfo");
@@ -458,14 +450,12 @@
         }
      }
      return goods;
   }
   /**
    * 获取推广商品信息接口
    *
    * @param skuIdList
    * @return
    */
@@ -494,7 +484,6 @@
      JDGoods goods = new JDGoods();
      goods.setPrice(StringUtil.isNullOrEmpty(json.optString("wlUnitPrice"))
            ? new BigDecimal(json.optString("unitPrice")) : new BigDecimal(json.optString("wlUnitPrice")));
      
      BigDecimal commisionRatioWl = new BigDecimal(json.optString("commisionRatioWl"));
      if (commisionRatioWl.compareTo(new BigDecimal(0)) > 0) {
@@ -546,7 +535,6 @@
      return goods;
   }
   
   public static JDSearchResult getJingFenGoods(int pageIndex, int eliteId) {
      JDSearchResult searchResult = new JDSearchResult();
      List<JDGoods> list = new ArrayList<>();
@@ -559,7 +547,6 @@
      
      JSONObject jsonDTO = new JSONObject();
      jsonDTO.put("goodsReq", json);
      
      String result = baseRequest2("jd.union.open.goods.jingfen.query", null, jsonDTO);
      System.out.println(result);
@@ -590,7 +577,6 @@
      return searchResult;
   }
   
   public static JDSearchResult getGoodsClass() {
      JDSearchResult searchResult = new JDSearchResult();
      List<JDGoods> list = new ArrayList<>();
@@ -600,7 +586,6 @@
      
      JSONObject jsonDTO = new JSONObject();
      jsonDTO.put("req", json);
      
      String result = baseRequest2("jd.union.open.category.goods.get", null, jsonDTO);
      System.out.println(result);
@@ -631,7 +616,6 @@
      return searchResult;
   }
   
   public static JDGoods getGoodsDetail(Long skuId) {
      List<Long> skuIdList = new ArrayList<>();
      skuIdList.add(skuId);
@@ -641,16 +625,33 @@
      return null;
   }
   public static JDOrderResult getOrder(int page, int pageSize, String time, int type) {
   /**
    * 获取订单列表
    *
    * @param page
    * @param pageSize
    * @param time
    * @param type
    *            时间类型 1-下单时间 2-完成时间 3-更新时间
    * @return
    */
   public static JDOrderResult getOrderList(int page, int pageSize, Date time, int type) {
      JSONObject json = new JSONObject();
      JSONObject orderReq = new JSONObject();
      orderReq.put("pageNo", page);
      orderReq.put("pageSize", pageSize);
      orderReq.put("type", type);
      orderReq.put("time", time);
      orderReq.put("time", TimeUtil.getGernalTime(time.getTime(), "yyyyMMddHH"));
      json.put("orderReq", orderReq);
      String result = baseRequest("jd.union.open.order.query", null, json);
      String result = baseRequest2("jd.union.open.order.query", null, json);
      try {
         System.out.println(new String(result.getBytes("GBK"), "UTF-8"));
         System.out.println(new String(result.getBytes("ISO-8859-1"), "UTF-8"));
      } catch (UnsupportedEncodingException e) {
         e.printStackTrace();
      }
      JSONObject root = JSONObject.fromObject(result).optJSONObject("jd_union_open_order_query_response");
      if (root.optInt("code") == 0) {
         boolean hasMore = root.optBoolean("hasMore");