yujian
2020-01-18 f4a0f2acc63d7785eab108419a4e16f5f688cb95
fanli/src/main/java/com/yeshi/fanli/util/pinduoduo/PinDuoDuoApiUtil.java
@@ -21,6 +21,8 @@
import com.yeshi.fanli.dto.pdd.PDDOrderResult;
import com.yeshi.fanli.dto.pdd.PDDPromotionUrl;
import com.yeshi.fanli.dto.pdd.PDDSearchFilter;
import com.yeshi.fanli.dto.pdd.PDDShopDetail;
import com.yeshi.fanli.dto.pdd.PDDShopResult;
import com.yeshi.fanli.entity.pdd.PDDOrder;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@@ -98,7 +100,8 @@
         map.put("keyword", sf.getKw());
      if (sf.getGoodsIdList() != null)
         map.put("goods_id_list", "[" + StringUtil.concat(sf.getGoodsIdList(), ",") + "]");
      if (sf.getMerchantType() != null)
         map.put("merchant_type", sf.getMerchantType() + "");
      map.put("pid", PID_FANLI);
      String result = baseRequest(map);
      JSONObject json = JSONObject.fromObject(result);
@@ -119,6 +122,17 @@
      List<PDDGoodsDetail> goodsList = gson.fromJson(array.toString(), type);
      int totalCount = root.optInt("total_count");
      return new PDDGoodsResult(totalCount, goodsList);
   }
   public static List<PDDGoodsDetail> listGoodsDetail(List<Long> goodsIds) {
      PDDSearchFilter filter = new PDDSearchFilter();
      Long[] ids = new Long[goodsIds.size()];
      goodsIds.toArray(ids);
      filter.setGoodsIdList(ids);
      PDDGoodsResult result = searchGoods(filter);
      if (result != null)
         return result.getGoodsList();
      return null;
   }
   /**
@@ -264,6 +278,7 @@
      map.put("p_id", pid);
      map.put("multi_group", "true");
      map.put("generate_weapp_webview", "true");
      // map.put("generate_weiboapp_webview", "true");
      JSONArray array = new JSONArray();
      array.add(goodsId);
@@ -284,6 +299,39 @@
         }.getType();
         Gson gson = new GsonBuilder().disableHtmlEscaping().create();
         return gson.fromJson(resultArray.optJSONObject(0).toString(), type);
      }
      return null;
   }
   /**
    * 微信小程序转链 @Title: convertWXMP @Description: @param goodsId @param
    * pid @param customParams @return PDDPromotionUrl 返回类型 @throws
    */
   public static String convertWXMP(Long goodsId, String pid, String customParams) {
      Map<String, String> map = new HashMap<>();
      map.put("type", "pdd.ddk.goods.promotion.url.generate");
      map.put("p_id", pid);
      map.put("multi_group", "true");
      map.put("generate_we_app", "true");
      JSONArray array = new JSONArray();
      array.add(goodsId);
      map.put("goods_id_list", array.toString());
      if (!StringUtil.isNullOrEmpty(customParams)) {
         map.put("custom_parameters", customParams);
      }
      String result = baseRequest(map);
      JSONObject root = JSONObject.fromObject(result);
      JSONObject json = root.optJSONObject("goods_promotion_url_generate_response");
      if (json == null) {
         return null;
      }
      JSONArray resultArray = json.optJSONArray("goods_promotion_url_list");
      if (resultArray != null && resultArray.size() > 0) {
         JSONObject weApp = resultArray.optJSONObject(0).optJSONObject("we_app_info");
         if (weApp != null)
            return weApp.optString("page_path");
      }
      return null;
   }
@@ -432,4 +480,39 @@
      return null;
   }
   /**
    * 获取商品详情
    *
    * @param goodsId
    */
   public static PDDShopResult getShopList(Integer page, Long catId) {
      JSONArray arrayType = new JSONArray();
      arrayType.add(3);
      Map<String, String> map = new HashMap<>();
      map.put("type", "pdd.ddk.merchant.list.get");
      if (catId != null)
         map.put("cat_id", catId + "");
      if (page != null)
         map.put("page_number", page + "");
      if (page != null)
         map.put("page_number", page + "");
      map.put("merchant_type_list", arrayType.toString());
      String result = baseRequest(map);
      JSONObject resultJson = JSONObject.fromObject(result);
      JSONObject root = resultJson.optJSONObject("merchant_list_response");
      if (root != null) {
         int totalCount = root.optInt("total");
         JSONArray array = root.optJSONArray("mall_search_info_vo_list");
         Type type = new TypeToken<List<PDDShopDetail>>() {
         }.getType();
         List<PDDShopDetail> listShop = new Gson().fromJson(array.toString(), type);
         return new PDDShopResult(totalCount, listShop);
      }
      return null;
   }
}