淘宝客获取促销价格API的示例

来源:互联网 发布:小偷公司知乎 编辑:程序博客网 时间:2024/05/01 23:55

因为淘宝客商品获取接口中的价格是正常价格 ,但很多商品实际是按促销价销售的 ,下面是如何获取促销价格的代码(需要事先通过淘宝客推广商品接口查到商品 ID后,以商品ID作为查询参数 ):

 

public static String getPromotionPrice(String url,String appkey,String secret,long proId,String channel,HttpServletRequest request) throws ApiException, HttpException, IOException
 {
      String promPrice = "";
      url = ServiceLocator.getSysConfigService().getStringValueByParmName("tbkUrl");
      appkey =  ServiceLocator.getSysConfigService().getStringValueByParmName("tbkAppkey");
      secret =  ServiceLocator.getSysConfigService().getStringValueByParmName("tbkSecret");   
      //taobao.ump.promotion.get
     UmpPromotionGetRequest req=new UmpPromotionGetRequest();
     req.setItemId(proId);
     if(channel!=null&&channel.trim().length()>0)
     {
          req.setChannelKey(channel);
     }
     TaobaoClient client=new DefaultTaobaoClient(url, appkey, secret);
   

      //获取折扣可以不使用sessionKey
     UmpPromotionGetResponse response = client.execute(req , null);
     PromotionDisplayTop top = response.getPromotions();
   //商品优惠详情查询,可查询商品设置的详细优惠。包括限时折扣,满就送等官方优惠以及第三方优惠。 
   //下面是从列表查一个符合当前日期范围的促销价格   

List<PromotionInItem> list = top.getPromotionInItem();
   for(int i=0;i<list.size();i++)
  {
   PromotionInItem item = list.get(i);
   Date startDt = item.getStartTime();
   Date endDt = item.getEndTime();
   Date currentDate = new Date(System.currentTimeMillis());
   if(currentDate.after(startDt)&&currentDate.before(endDt))
   {
    promPrice = item.getItemPromoPrice();
    //System.out.print(item.getItemPromoPrice());
    break;
   }
   }
     return promPrice;
 }
 

本人最近上线了淘宝导购网站-托众导购网,地址http://www.tuozhong.com ,欢迎 大家到网站购物(直连淘宝天猫商城 ),注册后认领订单可以换取集分宝,推荐的会员购物后也可返集分宝 。

原创粉丝点击