yujian
2019-12-19 626d711cb15896055c13fe344eb7fcc824589715
fanli/src/main/java/com/yeshi/fanli/util/jd/JDApiUtil.java
@@ -114,7 +114,7 @@
    * 
    * @return
    */
   public static String convertLink(String materialId, String couponUrl, String positionId, String ext1) {
   public static String convertLink1(String materialId, String couponUrl, String positionId, String ext1) {
      JSONObject json = new JSONObject();
      json.put("materialId", materialId);
      json.put("siteId", APP_ID);
@@ -142,23 +142,37 @@
      return resultJson.optJSONObject("data").optString("clickURL");
   }
   /**
    * 转链接-短连接
    *
    * @param materialId
    * @param couponUrl
    * @param positionId
    * @param ext1
    * @return
    */
   public static String convertShortLink(String materialId, String couponUrl, String positionId, String ext1) {
      String url = convertLink(materialId, couponUrl, positionId, ext1);
      // 暂时注释
      // if (!StringUtil.isNullOrEmpty(url)) {
      // url = HttpUtil.getShortLink(url);
      // }
      return url;
   public static String convertLinkWithSubUnionId(String materialId, String couponUrl, String positionId,
         String subUnionId) {
      JSONObject json = new JSONObject();
      json.put("materialId", materialId);
      json.put("siteId", APP_ID);
      json.put("positionId", positionId);
      if (!StringUtil.isNullOrEmpty(couponUrl))
         json.put("couponUrl", couponUrl);
      if (!StringUtil.isNullOrEmpty(subUnionId))
         json.put("subUnionId", subUnionId);
      //1:长链, 2 :短链 ,3: 长链+短链
      json.put("chainType", 3);
      JSONObject root = new JSONObject();
      root.put("promotionCodeReq", json);
      String result = baseRequest2("jd.union.open.promotion.bysubunionid.get", null, root);
      JSONObject resultJson = JSONObject.fromObject(result);
      result = resultJson.optJSONObject("jd_union_open_promotion_bysubunionid_get_response").optString("result");
      System.out.println(result);
      if (result == null) {
         return null;
      }
      resultJson = JSONObject.fromObject(result);
      return resultJson.optJSONObject("data").optString("shortURL");
   }
   public static JDGoods queryGoodsDetail(Long skuId) {
      List<Long> skuIdList = new ArrayList<>();
@@ -417,18 +431,20 @@
               }
            };
            Collections.sort(couponInfoList, cm);
//            if (couponInfoList.size() > 0) {
//               // 设置券信息为最接近的一个
//               for (int i = couponInfoList.size() - 1; i >= 0; i--) {
//                  if (couponInfoList.get(i).getQuota().compareTo(goods.getPrice()) <= 0) {
//                     goods.setCouponInfo(couponInfoList.get(i));
//                     break;
//                  }
//               }
//               if (goods.getCouponInfo() == null)
//                  goods.setCouponInfo(couponInfoList.get(0));
//            }
//
            // if (couponInfoList.size() > 0) {
            // // 设置券信息为最接近的一个
            // for (int i = couponInfoList.size() - 1; i >= 0; i--) {
            // if
            // (couponInfoList.get(i).getQuota().compareTo(goods.getPrice())
            // <= 0) {
            // goods.setCouponInfo(couponInfoList.get(i));
            // break;
            // }
            // }
            // if (goods.getCouponInfo() == null)
            // goods.setCouponInfo(couponInfoList.get(0));
            // }
            //
            goods.setCouponInfoList(couponInfoList);
         }
@@ -679,4 +695,14 @@
      return null;
   }
   public static void test() {
      JSONObject json = new JSONObject();
      json.put("materialId", "https://item.jd.com/32376790478.html");
      json.put("ext1", "437032");
      JSONObject root = new JSONObject();
      root.put("promotionCodeReq", json);
      String result = baseRequest2("jd.union.open.promotion.bysubunionid.get", null, root);
      System.out.println(result);
   }
}