一、唯品会开放平台
1、平台地址
2、SDK下载
SDK下载
(2) 导入SDK:
导入SDK
(3)Maven依赖
vip
vop
1
system
${project.basedir}/lib/vop-sdk.jar
二、在线测试
在线测试
生成的测试代码
三、代码编写
package com.hrz.third.api.vip;
import com.hrz.common.utils.HttpUtils;
import com.hrz.third.entity.request.vip.VipProductRequest;
import com.vip.osp.sdk.exception.OspException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import vipapis.puma.ChannelPumaServiceHelper.ChannelPumaServiceClient;
import vipapis.puma.ProductQueryResponse;
import vipapis.puma.SortAttr;
import java.util.*;
/**
* @作 者: 侯建军
* @日 期: 2018/12/27 18:09:16
* @描 述:
*/
@RefreshScope
@Service
@Slf4j
public class VipTemplate {
/**
* 1、创建唯品会客户端
*
* @return
*/
public ChannelPumaServiceClient createClient() {
vipapis.puma.ChannelPumaServiceHelper.ChannelPumaServiceClient client = new vipapis.puma.ChannelPumaServiceHelper.ChannelPumaServiceClient();
com.vip.osp.sdk.context.InvocationContext invocationContext = com.vip.osp.sdk.context.InvocationContext.Factory.getInstance();
//
invocationContext.setAppKey("自已申请");
invocationContext.setAppSecret("自已申请");
invocationContext.setAccessToken("自已申请");
invocationContext.setAppURL("https://gw.vipapis.com/");
invocationContext.setLanguage("zh");
return client;
}
/**
* 2、获取唯品会商品信息
*
* @param vipProductRequest
* @return
*/
public ProductQueryResponse getPumaProducts(VipProductRequest vipProductRequest) {
ChannelPumaServiceClient client = createClient();
//创建商品查询对象
vipapis.puma.ProductQueryRequest request = new vipapis.puma.ProductQueryRequest();
//创建分页对象
vipapis.puma.Pagination pagination = new vipapis.puma.Pagination();
pagination.setPage(vipProductRequest.getPage()); //当前页
pagination.setSize(vipProductRequest.getPageSize()); //页大小(最大100)
pagination.setTotal(100); //总记录
request.setPagination(pagination); //
//创建商品id列表,商品ID列表,最多100个
if (null != vipProductRequest.getProductIds()) {
request.setProduct_ids(vipProductRequest.getProductIds());
}
//对应的品牌库中的品牌ID,最多10个---可以为空
if (null != vipProductRequest.getBrandSns()) {
request.setBrand_sns(vipProductRequest.getBrandSns());
}
//三级分类ID,最多10个---可以为空
if (null != vipProductRequest.getCategoryLevel3Ids()) {
request.setThird_level_category_ids(vipProductRequest.getCategoryLevel3Ids());
}
//查询类型,可同时支持多个1、商品运营信息 2、SPU信息3、价格信息4、推广页信息5、库存信息
if (null != vipProductRequest.getIsOnSale()) {
request.setQuery_types(vipProductRequest.getQueryTypes());
}
//在售状态: 0、在售 1、不在售 不传值:在售与不在售商品都返回,可以为空
if (null != vipProductRequest.getIsOnSale()) {
request.setIs_on_sale(vipProductRequest.getIsOnSale());
}
// 商品名称,前后模糊,选填
if (null != vipProductRequest.getProductName()) {
request.setProduct_name(vipProductRequest.getProductName());
}
// 价格范围,(支持区间搜索,多个用OR连接),最多10个,可以为空
if (null != vipProductRequest.getPriceRanges()) {
request.setPrice_ranges(vipProductRequest.getPriceRanges());
}
///商品标签信息,如果需要过滤多个,请同时传多个:0、高佣商品标识 1、限时快抢商品标识 可以为空
if (null != vipProductRequest.getProductTags()) {
request.setProduct_tags(vipProductRequest.getProductTags());
}
// 排序规则,选填
if (null != vipProductRequest.getSortAttres()) {
// SortAttr
//属性编码:2、价格 4、折扣 5、近30天销售额 6、近30天销售量
// value11.setAttr_code(1);
//排序规则:1、升序 0、降序
// value11.setSort_rule(1);
request.setSort_attres(vipProductRequest.getSortAttres());
}
// 折扣范围,(支持区间搜索,多个用OR连接),输入1-10 数字,最多10个
if (null != vipProductRequest.getDiscountRanges()){
request.setDiscount_ranges(vipProductRequest.getDiscountRanges());
}
ProductQueryResponse productQueryResponse = null;
try {
productQueryResponse = client.getPumaProducts(request);
} catch (OspException e) {
e.printStackTrace();
log.info("vip template getPumaProducts 接口出错" + e);
}
return productQueryResponse;
}
}
四、单元测试
商品ID获取:
商品ID获取
615395299664413
@Autowired
private VipTemplate vipTemplate;
@Test
public void getPumaProducts() {
VipProductRequest vipProductRequest=new VipProductRequest();
Set set=new HashSet<>();
set.add(100093917);
vipProductRequest.setPage(1);
vipProductRequest.setPageSize(1);
vipProductRequest.setQueryTypes(set);
ProductQueryResponse response= vipTemplate.getPumaProducts(vipProductRequest);
//
log.info(response.getMarketing_products().size()+"唯品会");
}
测试结果:
测试结果