| | |
| | | //淘宝客API接口 |
| | | public class TaoKeApiUtil { |
| | | |
| | | // 解析券的内容 |
| | | private static TaoBaoSearchResult parseCoupleContent(String content) { |
| | | TaoBaoSearchResult result = new TaoBaoSearchResult(); |
| | | JSONObject root = JSONObject.fromObject(content); |
| | | |
| | | root = root.optJSONObject("tbk_dg_item_coupon_get_response"); |
| | | if (root.optJSONObject("results") == null) |
| | | return null; |
| | | |
| | | JSONArray array = root.optJSONObject("results").optJSONArray("tbk_coupon"); |
| | | if (array != null) { |
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); |
| | | for (int i = 0; i < array.size(); i++) { |
| | | JSONObject item = array.optJSONObject(i); |
| | | TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief(); |
| | | goods.setPictUrl(item.optString("pict_url")); |
| | | goods.setAuctionId(item.optString("num_iid")); |
| | | goods.setAuctionUrl(item.optString("item_url")); |
| | | goods.setBiz30day(item.optInt("volume")); |
| | | goods.setCouponInfo(item.optString("coupon_info")); |
| | | List<BigDecimal> quanInfo = TaoBaoCouponUtil.getCouponInfo(goods.getCouponInfo()); |
| | | goods.setCouponAmount(quanInfo.get(1)); |
| | | goods.setCouponEffectiveEndTime(item.optString("coupon_end_time")); |
| | | goods.setCouponEffectiveStartTime(item.optString("coupon_start_time")); |
| | | goods.setCouponStartFee(quanInfo.get(0)); |
| | | goods.setCouponLeftCount(item.optInt("coupon_remain_count")); |
| | | goods.setCouponLink(item.optString("coupon_click_url")); |
| | | goods.setCouponTotalCount(item.optInt("coupon_total_count")); |
| | | goods.setDayLeft(-1); |
| | | if (item.optJSONObject("small_images") != null) { |
| | | JSONArray imgArray = item.optJSONObject("small_images").optJSONArray("string"); |
| | | if (imgArray != null) { |
| | | List<String> imgList = new ArrayList<>(); |
| | | for (int n = 0; n < imgArray.size(); n++) { |
| | | imgList.add(imgArray.optString(n)); |
| | | } |
| | | goods.setImgList(imgList); |
| | | } |
| | | } |
| | | |
| | | goods.setSellerId(item.optLong("seller_id")); |
| | | goods.setShopTitle(item.optString("shop_title")); |
| | | goods.setTitle(item.optString("title")); |
| | | |
| | | goods.setTkRate(new BigDecimal(item.optString("commission_rate"))); |
| | | goods.setTotalNum(1000); |
| | | goods.setUserType(item.optInt("user_type")); |
| | | goods.setUserTypeName(""); |
| | | goods.setZkPrice(new BigDecimal(item.optString("zk_final_price"))); |
| | | |
| | | if (goods.getZkPrice().compareTo(goods.getCouponStartFee()) >= 0 |
| | | && goods.getZkPrice().compareTo(goods.getCouponAmount()) > 0) { |
| | | BigDecimal finalPrice = goods.getZkPrice().subtract(goods.getCouponAmount()); |
| | | goods.setTkCommFee(finalPrice.multiply(goods.getTkRate()).divide(new BigDecimal(100))); |
| | | } else |
| | | goods.setTkCommFee(new BigDecimal(0)); |
| | | |
| | | goodsList.add(goods); |
| | | } |
| | | |
| | | result.setTaoBaoGoodsBriefs(goodsList); |
| | | |
| | | int totalCount = 1000;// root.optInt("total_results"); |
| | | PageEntity pe = new PageEntity(0, 0, totalCount); |
| | | result.setPageEntity(pe); |
| | | } |
| | | result.setNavList(new ArrayList<>()); |
| | | TaoBaoHead taoBaoHead = new TaoBaoHead(); |
| | | taoBaoHead.setDocsfound((int) result.getPageEntity().getTotalCount()); |
| | | result.setTaoBaoHead(taoBaoHead); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 获取商品详情,简版 |
| | | * |
| | |
| | | TaoBaoGoodsBrief goods = new TaoBaoGoodsBrief(); |
| | | goods.setAuctionId(item.optString("num_iid")); |
| | | goods.setAuctionUrl(item.optString("item_url")); |
| | | goods.setBiz30day(item.optInt("volume")); |
| | | if(item.containsKey("annual_vol")){ |
| | | goods.setBiz30day(item.optInt("annual_vol")/12); |
| | | }else { |
| | | goods.setBiz30day(item.optInt("volume")); |
| | | } |
| | | if (item.optJSONObject("small_images") != null) { |
| | | JSONArray imgArray = item.optJSONObject("small_images").optJSONArray("string"); |
| | | if (imgArray != null) { |
| | |
| | | |
| | | goods.setAuctionId(item.optString("num_iid")); |
| | | goods.setAuctionUrl("https:" + item.optString("url")); |
| | | goods.setBiz30day(item.optInt("volume")); |
| | | if(item.containsKey("annual_vol")){ |
| | | goods.setBiz30day(item.optInt("annual_vol")/100); |
| | | }else { |
| | | goods.setBiz30day(item.optInt("volume")); |
| | | } |
| | | goods.setCouponInfo(item.optString("coupon_info")); |
| | | |
| | | if (goods.getCouponInfo() != null) |
| | |
| | | |
| | | goods.setAuctionId(item.optString("item_id")); |
| | | goods.setAuctionUrl("https:" + item.optString("url")); |
| | | goods.setBiz30day(basicInfo.optInt("volume")); |
| | | |
| | | if(basicInfo.containsKey("annual_vol")){ |
| | | goods.setBiz30day(basicInfo.optInt("annual_vol")/12); |
| | | }else { |
| | | goods.setBiz30day(basicInfo.optInt("volume")); |
| | | } |
| | | if(pricePromotionInfo.optJSONObject("final_promotion_path_list")!=null&&pricePromotionInfo.optJSONObject("final_promotion_path_list").optJSONArray("final_promotion_path_map_data").size()>0) { |
| | | JSONArray array = pricePromotionInfo.optJSONObject("final_promotion_path_list").optJSONArray("final_promotion_path_map_data"); |
| | | JSONObject couponInfo = array.optJSONObject(0); |
| | |
| | | goods.setPictUrl(TbImgUtil.getTBSize320Img("https:" + item.optString("pict_url"))); |
| | | goods.setAuctionId(item.optString("item_id")); |
| | | goods.setAuctionUrl("https://item.taobao.com/item.htm?id=" + goods.getAuctionId()); |
| | | goods.setBiz30day(item.optInt("volume")); |
| | | if(item.containsKey("annual_vol")){ |
| | | goods.setBiz30day(item.optInt("annual_vol")/12); |
| | | }else { |
| | | goods.setBiz30day(item.optInt("volume")); |
| | | } |
| | | if (!StringUtil.isNullOrEmpty(item.optString("coupon_amount"))) { |
| | | goods.setCouponEffectiveEndTime(TimeUtil.getGernalTime(item.optLong("coupon_end_time"), "yyyy-MM-dd")); |
| | | goods.setCouponEffectiveStartTime(TimeUtil.getGernalTime(item.optLong("coupon_start_time"), "yyyy-MM-dd")); |