全部
常见问题
产品动态
精选推荐
功能建议

分析中 已回复 待规划 {{opt.name}}
分析中 已回复 待规划
实战获取1688选品API接口:从数据采集到智能选品决策

管理 管理 编辑 删除

1688作为阿里巴巴旗下的B2B批发平台,拥有海量的货源数据,是跨境电商卖家、国内电商运营者、供应链采购人员的核心选品渠道。本文将深入讲解如何通过1688开放平台API接口,实现从关键词搜索 → 商品详情获取 → 数据清洗 → 智能选品评分的完整实战链路。



一、1688选品API接口体系

1.1 核心接口介绍

1688开放平台提供了丰富的商品数据接口,选品场景下最常用的接口包括:



接口名称功能描述适用场景
alibaba.product.search关键词搜索商品列表选品发现、市场趋势分析
alibaba.product.get获取单个商品全量详情深度分析、铺货上架
alibaba.product.rank.search获取热销榜/新品榜爆款挖掘、趋势预判
alibaba.image.search以图搜货(拍立淘)反向寻源、同款比价
item_search_shop店铺商品列表查询供应商监控、店铺分析
本文以 alibaba.product.search 和 alibaba.product.get 为核心,详细介绍选品场景的接口调用实战。

1.2 选品数据维度



┌─────────────────────────────────────────┐
│         1688选品核心数据维度              │
├─────────────────────────────────────────┤
│  价格体系:批发价、阶梯价、代发价、建议零售价 │
│  交易数据:30天成交笔数、成交件数、复购率    │
│  供应能力:起订量(MOQ)、库存深度、发货速度   │
│  商品质量:评价数、好评率、退款率           │
│  店铺资质:诚信通年限、实力商家、源头工厂    │
│  物流信息:发货地、运费模板、48小时发货     │
│  商品属性:SKU规格、材质、认证信息          │
│  图片视频:主图、详情图、视频、白底图       │
└─────────────────────────────────────────┘


二、准备工作

2.1 注册1688开放平台开发者账号

  1. 访问 1688开放平台 注册企业开发者账号
  2. 完成企业实名认证(提交营业执照、法人身份证、对公账户信息,审核1-3个工作日)
  3. 创建应用,选择"自用型"或"第三方型"
  4. 申请所需接口权限(商品搜索、商品详情等)
  5. 获取以下凭证:
凭证说明
App Key应用唯一标识
App Secret应用密钥,用于签名(绝密,仅服务端存储)
Access Token用户授权令牌(OAuth2.0)

2.2 申请接口权限


接口所需权限申请条件
alibaba.product.search商品搜索API基础权限,企业认证后申请
alibaba.product.get商品详情API基础权限,企业认证后申请
alibaba.product.rank.search榜单查询API需额外审核
alibaba.image.search图片搜索API需额外审核

2.3 Maven依赖配置


<dependencies>
    <!-- HTTP请求 -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.5.14</version>
    </dependency>

    <!-- JSON解析 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>2.0.43</version>
    </dependency>

    <!-- MD5加密 -->
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.16.0</version>
    </dependency>

    <!-- 日志 -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>2.0.9</version>
    </dependency>
</dependencies>


三、核心代码实现

3.1 签名工具类(MD5算法)

1688 API签名规则:所有请求参数(不含sign、file字段,空值剔除),按参数名ASCII升序排列,拼接为 app_secret+key1value1key2value2...+app_secret,最后进行MD5加密并转大写。特别注意:时间戳必须使用毫秒级(13位)

java


import org.apache.commons.codec.digest.DigestUtils;

import java.util.Map;
import java.util.TreeMap;

/**
 * 1688开放平台API签名工具类
 * 签名规则:app_secret + 按key升序拼接(key+value) + app_secret → MD5 → 大写
 */
public class AlibabaSignUtil {

    /**
     * 生成1688 API签名
     * @param params 请求参数(不含sign)
     * @param appSecret 应用密钥
     * @return 大写MD5签名
     */
    public static String generateSign(Map<String, String> params, String appSecret) {
        // 1. 剔除sign和空值参数,按key ASCII升序排列
        TreeMap<String, String> sortedParams = new TreeMap<>();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (!"sign".equals(key) && !"file".equals(key)
                && value != null && !value.trim().isEmpty()) {
                sortedParams.put(key, value);
            }
        }

        // 2. 按key升序拼接 key+value(无分隔符)
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, String> entry : sortedParams.entrySet()) {
            sb.append(entry.getKey()).append(entry.getValue());
        }

        // 3. 首尾拼接app_secret
        String toSign = appSecret + sb.toString() + appSecret;

        // 4. MD5加密,转大写
        return DigestUtils.md5Hex(toSign).toUpperCase();
    }
}

3.2 1688 API基础客户端


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * 1688 API基础客户端
 */
public class AlibabaApiClient {

    // 1688开放平台网关
    private static final String GATEWAY = "https://gw.open.1688.com/openapi/param2/2/portals.open/";

    private final String appKey;
    private final String appSecret;
    private final String accessToken;

    public AlibabaApiClient(String appKey, String appSecret, String accessToken) {
        this.appKey = appKey;
        this.appSecret = appSecret;
        this.accessToken = accessToken;
    }

    /**
     * 执行API请求
     * @param apiName 接口名称(如 api.listOfferDetail)
     * @param bizParams 业务参数
     * @return JSON响应
     */
    public JSONObject execute(String apiName, Map<String, String> bizParams) {
        try {
            // 构建系统参数
            Map<String, String> params = new HashMap<>();
            params.put("app_key", appKey);
            params.put("timestamp", String.valueOf(System.currentTimeMillis())); // 毫秒级时间戳
            params.put("format", "json");
            params.put("v", "1.0");
            params.put("sign_method", "md5");

            // 添加access_token(需要授权的接口)
            if (accessToken != null && !accessToken.isEmpty()) {
                params.put("access_token", accessToken);
            }

            // 添加业务参数
            for (Map.Entry<String, String> entry : bizParams.entrySet()) {
                params.put(entry.getKey(), entry.getValue());
            }

            // 生成签名
            String sign = AlibabaSignUtil.generateSign(params, appSecret);
            params.put("sign", sign);

            // 构建请求URL
            String url = buildUrl(GATEWAY + apiName, params);

            // 发送GET请求
            try (CloseableHttpClient client = HttpClients.createDefault()) {
                HttpGet httpGet = new HttpGet(url);
                httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)");
                httpGet.setHeader("Accept", "application/json");

                String response = EntityUtils.toString(
                    client.execute(httpGet).getEntity(), "UTF-8");

                return JSON.parseObject(response);
            }
        } catch (Exception e) {
            throw new RuntimeException("API请求失败: " + e.getMessage(), e);
        }
    }

    /**
     * 构建带参数的URL
     */
    private String buildUrl(String baseUrl, Map<String, String> params) {
        StringBuilder url = new StringBuilder(baseUrl);
        url.append("?");
        for (Map.Entry<String, String> entry : params.entrySet()) {
            try {
                url.append(entry.getKey())
                   .append("=")
                   .append(URLEncoder.encode(entry.getValue(), "UTF-8"))
                   .append("&");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException("URL编码失败", e);
            }
        }
        // 移除末尾的&
        return url.substring(0, url.length() - 1);
    }
}

3.3 选品搜索服务类


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 1688选品搜索服务
 */
public class AlibabaSelectionService {

    private final AlibabaApiClient apiClient;

    public AlibabaSelectionService(AlibabaApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * 关键词搜索商品(核心选品接口)
     * @param keyword 搜索关键词
     * @param page 页码(从1开始)
     * @param pageSize 每页数量(最大50)
     * @param sortType 排序方式
     * @param priceStart 起始价格
     * @param priceEnd 结束价格
     * @return 商品列表
     */
    public SearchResult searchByKeyword(String keyword, int page, int pageSize,
                                        String sortType, Double priceStart, Double priceEnd) {
        Map<String, String> bizParams = new HashMap<>();
        bizParams.put("keywords", keyword);
        bizParams.put("pageNum", String.valueOf(page));
        bizParams.put("pageSize", String.valueOf(pageSize));

        if (sortType != null) {
            bizParams.put("sortType", sortType); // price_asc/price_desc/sale/comment
        }
        if (priceStart != null) {
            bizParams.put("priceStart", String.valueOf(priceStart));
        }
        if (priceEnd != null) {
            bizParams.put("priceEnd", String.valueOf(priceEnd));
        }

        JSONObject response = apiClient.execute("api.listOfferDetail", bizParams);

        return parseSearchResult(response);
    }

    /**
     * 获取商品全量详情
     * @param productId 商品ID(offerId)
     * @return 商品详情
     */
    public ProductDetail getProductDetail(String productId) {
        Map<String, String> bizParams = new HashMap<>();
        bizParams.put("offerId", productId);

        JSONObject response = apiClient.execute("api.getOfferDetail", bizParams);

        if (response.containsKey("result")) {
            JSONObject result = response.getJSONObject("result");
            return parseProductDetail(result);
        }

        throw new RuntimeException("获取商品详情失败: " + response);
    }

    /**
     * 获取热销榜单(爆款挖掘)
     * @param categoryId 类目ID
     * @param rankType 榜单类型:hot=热销榜, new=新品榜
     * @return 榜单商品列表
     */
    public List<ProductBrief> getRankList(String categoryId, String rankType) {
        Map<String, String> bizParams = new HashMap<>();
        bizParams.put("categoryId", categoryId);
        bizParams.put("rankType", rankType);
        bizParams.put("pageSize", "50");

        JSONObject response = apiClient.execute("api.rankList", bizParams);

        List<ProductBrief> products = new ArrayList<>();
        if (response.containsKey("result")) {
            JSONArray items = response.getJSONObject("result").getJSONArray("items");
            for (int i = 0; i < items.size(); i++) {
                products.add(parseProductBrief(items.getJSONObject(i)));
            }
        }
        return products;
    }

    /**
     * 以图搜货(反向寻源)
     * @param imageUrl 图片URL
     * @return 相似商品列表
     */
    public List<ProductBrief> searchByImage(String imageUrl) {
        Map<String, String> bizParams = new HashMap<>();
        bizParams.put("imageUrl", imageUrl);
        bizParams.put("pageSize", "20");

        JSONObject response = apiClient.execute("api.imageSearch", bizParams);

        List<ProductBrief> products = new ArrayList<>();
        if (response.containsKey("result")) {
            JSONArray items = response.getJSONObject("result").getJSONArray("items");
            for (int i = 0; i < items.size(); i++) {
                products.add(parseProductBrief(items.getJSONObject(i)));
            }
        }
        return products;
    }

    /**
     * 解析搜索结果
     */
    private SearchResult parseSearchResult(JSONObject response) {
        SearchResult result = new SearchResult();

        if (!response.containsKey("result") || response.get("result") == null) {
            result.setSuccess(false);
            result.setErrorMessage(response.getString("message"));
            return result;
        }

        JSONObject resultObj = response.getJSONObject("result");
        result.setSuccess(true);
        result.setTotalCount(resultObj.getIntValue("totalCount"));
        result.setCurrentPage(resultObj.getIntValue("currentPage"));

        JSONArray items = resultObj.getJSONArray("items");
        List<ProductBrief> products = new ArrayList<>();

        for (int i = 0; i < items.size(); i++) {
            products.add(parseProductBrief(items.getJSONObject(i)));
        }
        result.setProducts(products);

        return result;
    }

    /**
     * 解析商品简要信息
     */
    private ProductBrief parseProductBrief(JSONObject json) {
        ProductBrief product = new ProductBrief();
        product.setProductId(json.getString("offerId"));
        product.setTitle(json.getString("subject"));
        product.setPrice(json.getDouble("price"));
        product.setOriginalPrice(json.getDouble("originalPrice"));
        product.setImageUrl(json.getString("imageUrl"));
        product.setDetailUrl(json.getString("detailUrl"));
        product.setTradeCount(json.getIntValue("tradeCount"));
        product.setQuantityBegin(json.getIntValue("quantityBegin"));
        product.setLocation(json.getString("location"));
        product.setCompanyName(json.getString("companyName"));
        product.setIsPowerMerchant(json.getBooleanValue("isPowerMerchant"));
        product.setIsFactory(json.getBooleanValue("isFactory"));
        product.setCreditLevel(json.getIntValue("creditLevel"));
        return product;
    }

    /**
     * 解析商品详情
     */
    private ProductDetail parseProductDetail(JSONObject json) {
        ProductDetail detail = new ProductDetail();
        detail.setProductId(json.getString("offerId"));
        detail.setTitle(json.getString("subject"));
        detail.setPrice(json.getDouble("price"));
        detail.setOriginalPrice(json.getDouble("originalPrice"));
        detail.setDescription(json.getString("description"));
        detail.setTradeCount(json.getIntValue("tradeCount"));
        detail.setQuantityBegin(json.getIntValue("quantityBegin"));
        detail.setLocation(json.getString("location"));
        detail.setCompanyName(json.getString("companyName"));
        detail.setIsPowerMerchant(json.getBooleanValue("isPowerMerchant"));
        detail.setIsFactory(json.getBooleanValue("isFactory"));
        detail.setCreditLevel(json.getIntValue("creditLevel"));

        // 解析SKU信息
        if (json.containsKey("skuList")) {
            JSONArray skus = json.getJSONArray("skuList");
            List<SkuInfo> skuList = new ArrayList<>();
            for (int i = 0; i < skus.size(); i++) {
                JSONObject skuJson = skus.getJSONObject(i);
                SkuInfo sku = new SkuInfo();
                sku.setSkuId(skuJson.getString("skuId"));
                sku.setProperties(skuJson.getString("spec"));
                sku.setPrice(skuJson.getDouble("price"));
                sku.setAmountOnSale(skuJson.getIntValue("amountOnSale"));
                skuList.add(sku);
            }
            detail.setSkus(skuList);
        }

        // 解析图片信息
        if (json.containsKey("imageList")) {
            JSONArray images = json.getJSONArray("imageList");
            List<String> imageList = new ArrayList<>();
            for (int i = 0; i < images.size(); i++) {
                imageList.add(images.getString(i));
            }
            detail.setImageList(imageList);
        }

        return detail;
    }
}

3.4 选品评分模型



import java.util.List;

/**
 * 智能选品评分模型
 */
public class SelectionScorer {

    /**
     * 计算商品选品得分
     * @param product 商品详情
     * @param marketPrice 市场售价(用于计算利润空间)
     * @return 选品得分(0-100)
     */
    public static double calculateScore(ProductDetail product, double marketPrice) {
        double score = 0.0;

        // 1. 利润空间评分(权重30%)
        double profitMargin = (marketPrice - product.getPrice()) / marketPrice;
        score += Math.min(profitMargin * 100, 30); // 最高30分

        // 2. 销量热度评分(权重25%)
        int tradeCount = product.getTradeCount();
        if (tradeCount > 1000) score += 25;
        else if (tradeCount > 500) score += 20;
        else if (tradeCount > 100) score += 15;
        else if (tradeCount > 50) score += 10;
        else score += 5;

        // 3. 供应能力评分(权重20%)
        int moq = product.getQuantityBegin();
        if (moq == 1) score += 20; // 一件代发最优
        else if (moq <= 10) score += 15;
        else if (moq <= 50) score += 10;
        else if (moq <= 100) score += 5;
        else score += 2;

        // 4. 店铺资质评分(权重15%)
        if (product.getIsFactory()) score += 8; // 源头工厂
        if (product.getIsPowerMerchant()) score += 5; // 实力商家
        if (product.getCreditLevel() >= 3) score += 2; // 高信用等级

        // 5. 竞争友好度评分(权重10%)
        // 基于同款商品数量和价格分散度计算
        score += 10; // 简化处理,实际需结合市场分析

        return Math.min(score, 100);
    }

    /**
     * 选品建议
     */
    public static String getSelectionAdvice(double score) {
        if (score >= 80) return "🟢 强烈推荐 - 立即上架";
        else if (score >= 60) return "🟡 推荐 - 小批量测试";
        else if (score >= 40) return "🟠 谨慎 - 持续观察";
        else return "🔴 不推荐 - 放弃";
    }
}

3.5 实体类定义

java


import java.util.List;

/**
 * 搜索结果封装
 */
public class SearchResult {
    private boolean success;
    private String errorMessage;
    private int totalCount;
    private int currentPage;
    private List<ProductBrief> products;

    // Getters and Setters
    public boolean isSuccess() { return success; }
    public void setSuccess(boolean success) { this.success = success; }
    public String getErrorMessage() { return errorMessage; }
    public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
    public int getTotalCount() { return totalCount; }
    public void setTotalCount(int totalCount) { this.totalCount = totalCount; }
    public int getCurrentPage() { return currentPage; }
    public void setCurrentPage(int currentPage) { this.currentPage = currentPage; }
    public List<ProductBrief> getProducts() { return products; }
    public void setProducts(List<ProductBrief> products) { this.products = products; }
}

/**
 * 商品简要信息
 */
public class ProductBrief {
    private String productId;       // 商品ID
    private String title;           // 商品标题
    private Double price;           // 批发价
    private Double originalPrice;   // 原价
    private String imageUrl;        // 主图URL
    private String detailUrl;       // 详情页URL
    private Integer tradeCount;     // 成交笔数
    private Integer quantityBegin;  // 起订量
    private String location;        // 发货地
    private String companyName;     // 公司名称
    private Boolean isPowerMerchant; // 是否实力商家
    private Boolean isFactory;      // 是否源头工厂
    private Integer creditLevel;    // 诚信通等级

    // Getters and Setters
    public String getProductId() { return productId; }
    public void setProductId(String productId) { this.productId = productId; }
    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }
    public Double getPrice() { return price; }
    public void setPrice(Double price) { this.price = price; }
    public Double getOriginalPrice() { return originalPrice; }
    public void setOriginalPrice(Double originalPrice) { this.originalPrice = originalPrice; }
    public String getImageUrl() { return imageUrl; }
    public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; }
    public String getDetailUrl() { return detailUrl; }
    public void setDetailUrl(String detailUrl) { this.detailUrl = detailUrl; }
    public Integer getTradeCount() { return tradeCount; }
    public void setTradeCount(Integer tradeCount) { this.tradeCount = tradeCount; }
    public Integer getQuantityBegin() { return quantityBegin; }
    public void setQuantityBegin(Integer quantityBegin) { this.quantityBegin = quantityBegin; }
    public String getLocation() { return location; }
    public void setLocation(String location) { this.location = location; }
    public String getCompanyName() { return companyName; }
    public void setCompanyName(String companyName) { this.companyName = companyName; }
    public Boolean getIsPowerMerchant() { return isPowerMerchant; }
    public void setIsPowerMerchant(Boolean isPowerMerchant) { this.isPowerMerchant = isPowerMerchant; }
    public Boolean getIsFactory() { return isFactory; }
    public void setIsFactory(Boolean isFactory) { this.isFactory = isFactory; }
    public Integer getCreditLevel() { return creditLevel; }
    public void setCreditLevel(Integer creditLevel) { this.creditLevel = creditLevel; }

    @Override
    public String toString() {
        return "ProductBrief{" +
            "productId='" + productId + '\'' +
            ", title='" + title + '\'' +
            ", price=" + price +
            ", tradeCount=" + tradeCount +
            ", companyName='" + companyName + '\'' +
            '}';
    }
}

/**
 * 商品详情
 */
public class ProductDetail extends ProductBrief {
    private String description;     // 商品描述
    private List<SkuInfo> skus;     // SKU列表
    private List<String> imageList; // 图片列表
    private String videoUrl;        // 视频URL
    private String deliveryTime;    // 发货时间
    private String refundPolicy;    // 退款政策

    // Getters and Setters
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    public List<SkuInfo> getSkus() { return skus; }
    public void setSkus(List<SkuInfo> skus) { this.skus = skus; }
    public List<String> getImageList() { return imageList; }
    public void setImageList(List<String> imageList) { this.imageList = imageList; }
    public String getVideoUrl() { return videoUrl; }
    public void setVideoUrl(String videoUrl) { this.videoUrl = videoUrl; }
    public String getDeliveryTime() { return deliveryTime; }
    public void setDeliveryTime(String deliveryTime) { this.deliveryTime = deliveryTime; }
    public String getRefundPolicy() { return refundPolicy; }
    public void setRefundPolicy(String refundPolicy) { this.refundPolicy = refundPolicy; }
}

/**
 * SKU信息
 */
public class SkuInfo {
    private String skuId;           // SKU ID
    private String properties;    // 规格属性(颜色:黑色;尺码:M)
    private Double price;           // SKU价格
    private Integer amountOnSale;   // 可售数量

    // Getters and Setters
    public String getSkuId() { return skuId; }
    public void setSkuId(String skuId) { this.skuId = skuId; }
    public String getProperties() { return properties; }
    public void setProperties(String properties) { this.properties = properties; }
    public Double getPrice() { return price; }
    public void setPrice(Double price) { this.price = price; }
    public Integer getAmountOnSale() { return amountOnSale; }
    public void setAmountOnSale(Integer amountOnSale) { this.amountOnSale = amountOnSale; }
}

3.6 主程序入口

java


public class AlibabaSelectionDemo {

    public static void main(String[] args) {
        // 配置信息(请替换为实际值)
        String appKey = "your_app_key";
        String appSecret = "your_app_secret";
        String accessToken = "your_access_token";
        String keyword = "手机支架"; // 搜索关键词

        try {
            // 初始化服务
            AlibabaApiClient apiClient = new AlibabaApiClient(appKey, appSecret, accessToken);
            AlibabaSelectionService selectionService = new AlibabaSelectionService(apiClient);

            System.out.println("【1688智能选品系统】");
            System.out.println("搜索关键词: " + keyword);
            System.out.println("=".repeat(70));

            // Step 1: 关键词搜索
            System.out.println("\n【Step 1】关键词搜索...");
            SearchResult searchResult = selectionService.searchByKeyword(
                keyword, 1, 20, "sale", 5.0, 50.0);

            if (!searchResult.isSuccess()) {
                System.err.println("搜索失败: " + searchResult.getErrorMessage());
                return;
            }

            System.out.println("找到 " + searchResult.getTotalCount() + " 个商品");
            System.out.println("当前页: " + searchResult.getCurrentPage());
            System.out.println("-".repeat(70));

            // Step 2: 获取商品详情并评分
            System.out.println("\n【Step 2】获取详情并智能评分...");
            System.out.println("-".repeat(70));

            int count = 0;
            for (ProductBrief brief : searchResult.getProducts()) {
                if (count++ >= 5) break; // 只分析前5个

                System.out.println("\n商品 " + count + ": " + brief.getTitle());
                System.out.println("  价格: ¥" + brief.getPrice());
                System.out.println("  销量: " + brief.getTradeCount() + "笔");
                System.out.println("  起订量: " + brief.getQuantityBegin() + "件");
                System.out.println("  供应商: " + brief.getCompanyName());
                System.out.println("  实力商家: " + (brief.getIsPowerMerchant() ? "是" : "否"));
                System.out.println("  源头工厂: " + (brief.getIsFactory() ? "是" : "否"));

                // 获取详情
                try {
                    ProductDetail detail = selectionService.getProductDetail(brief.getProductId());

                    // 智能评分(假设市场售价=批发价*2.5)
                    double marketPrice = brief.getPrice() * 2.5;
                    double score = SelectionScorer.calculateScore(detail, marketPrice);

                    System.out.println("  【选品得分】" + String.format("%.1f", score) + "/100");
                    System.out.println("  【选品建议】" + SelectionScorer.getSelectionAdvice(score));

                } catch (Exception e) {
                    System.out.println("  【详情获取失败】" + e.getMessage());
                }

                Thread.sleep(500); // 控制频率
            }

            // Step 3: 热销榜单(爆款挖掘)
            System.out.println("\n" + "=".repeat(70));
            System.out.println("【Step 3】热销榜单(爆款挖掘)...");
            System.out.println("-".repeat(70));

            List<ProductBrief> hotProducts = selectionService.getRankList("7", "hot");
            System.out.println("热销榜TOP5:");
            for (int i = 0; i < Math.min(5, hotProducts.size()); i++) {
                ProductBrief p = hotProducts.get(i);
                System.out.println("  " + (i+1) + ". " + p.getTitle()
                    + " | ¥" + p.getPrice()
                    + " | 销量:" + p.getTradeCount()
                    + " | " + p.getCompanyName());
            }

        } catch (Exception e) {
            System.err.println("程序执行异常: " + e.getMessage());
            e.printStackTrace();
        }
    }
}


四、接口返回数据结构

4.1 搜索接口返回示例

JSON


{
    "result": {
        "totalCount": 1250,
        "currentPage": 1,
        "pageSize": 20,
        "items": [
            {
                "offerId": "610947572360",
                "subject": "手机支架桌面懒人支架可折叠",
                "price": 15.80,
                "originalPrice": 25.00,
                "imageUrl": "https://cbu01.alicdn.com/xxx.jpg",
                "detailUrl": "https://detail.1688.com/offer/610947572360.html",
                "tradeCount": 5000,
                "quantityBegin": 10,
                "location": "广东深圳",
                "companyName": "深圳市某某电子有限公司",
                "isPowerMerchant": true,
                "isFactory": true,
                "creditLevel": 5
            }
        ]
    }
}

4.2 商品详情返回示例

JSON


{
    "result": {
        "offerId": "610947572360",
        "subject": "手机支架桌面懒人支架可折叠",
        "price": 15.80,
        "originalPrice": 25.00,
        "description": "商品详细描述...",
        "tradeCount": 5000,
        "quantityBegin": 10,
        "location": "广东深圳",
        "companyName": "深圳市某某电子有限公司",
        "isPowerMerchant": true,
        "isFactory": true,
        "creditLevel": 5,
        "skuList": [
            {
                "skuId": "1234567890",
                "spec": "颜色:黑色;材质:铝合金",
                "price": 15.80,
                "amountOnSale": 1000
            },
            {
                "skuId": "1234567891",
                "spec": "颜色:银色;材质:铝合金",
                "price": 16.80,
                "amountOnSale": 800
            }
        ],
        "imageList": [
            "https://cbu01.alicdn.com/1.jpg",
            "https://cbu01.alicdn.com/2.jpg",
            "https://cbu01.alicdn.com/3.jpg"
        ]
    }
}


五、选品评分模型详解

5.1 评分维度与权重

表格


评分维度权重计算逻辑满分
利润空间30%(市场售价-批发价)/市场售价 × 10030分
销量热度25%根据30天成交笔数分级评分25分
供应能力20%起订量越低得分越高(一件代发最优)20分
店铺资质15%源头工厂+实力商家+高信用等级15分
竞争友好度10%基于同款数量和价格分散度10分

5.2 评分结果解读

表格


得分区间等级建议动作
80-100🟢 强烈推荐立即联系供应商,首批备货测试
60-79🟡 推荐小批量采购(50-100件),验证市场
40-59🟠 谨慎持续观察,等待数据积累
<40🔴 不推荐放弃,寻找其他品类


六、常见问题与解决方案

表格


问题原因解决方案
Invalid signature签名算法错误或时间戳格式不对确认使用毫秒级时间戳(13位),参数按ASCII升序排列
Insufficient permissions未申请接口权限在开放平台申请对应API权限
Rate limit exceeded超出调用频率限制(个人≤100次/秒)增加请求间隔,或申请企业认证提升配额
Item not found商品ID错误或商品已下架核对offerId,确认商品状态
Access token expiredToken有效期通常为3600秒实现Token自动刷新机制
IP not in whitelist未配置IP白名单在开放平台添加服务器IP到白名单


七、进阶优化建议

7.1 数据缓存策略

java


public class SelectionCache {
    // 搜索结果缓存10分钟
    private static final LoadingCache<String, SearchResult> searchCache =
        Caffeine.newBuilder()
            .maximumSize(1000)
            .expireAfterWrite(10, TimeUnit.MINUTES)
            .build(key -> selectionService.searchByKeyword(...));

    // 商品详情缓存30分钟(详情变动较少)
    private static final LoadingCache<String, ProductDetail> detailCache =
        Caffeine.newBuilder()
            .maximumSize(5000)
            .expireAfterWrite(30, TimeUnit.MINUTES)
            .build(key -> selectionService.getProductDetail(key));
}

7.2 批量选品流程

java


public class BatchSelectionService {

    /**
     * 批量选品:从关键词到评分报告
     */
    public SelectionReport batchSelect(String keyword, int targetCount) {
        SelectionReport report = new SelectionReport();
        report.setKeyword(keyword);

        int page = 1;
        while (report.getQualifiedProducts().size() < targetCount && page <= 10) {
            SearchResult result = selectionService.searchByKeyword(keyword, page, 50, "sale", null, null);

            for (ProductBrief brief : result.getProducts()) {
                ProductDetail detail = selectionService.getProductDetail(brief.getProductId());
                double score = SelectionScorer.calculateScore(detail, detail.getPrice() * 2.5);

                if (score >= 60) {
                    report.addQualifiedProduct(detail, score);
                }
            }
            page++;
        }

        return report;
    }
}

7.3 供应商评估体系

java


public class SupplierEvaluator {

    /**
     * 评估供应商综合资质
     */
    public static double evaluateSupplier(ProductDetail product) {
        double score = 0.0;

        // 诚信通年限(权重30%)
        int creditLevel = product.getCreditLevel();
        score += Math.min(creditLevel * 6, 30);

        // 实力商家(权重25%)
        if (product.getIsPowerMerchant()) score += 25;

        // 源头工厂(权重25%)
        if (product.getIsFactory()) score += 25;

        // 交易数据(权重20%)
        int tradeCount = product.getTradeCount();
        if (tradeCount > 10000) score += 20;
        else if (tradeCount > 5000) score += 15;
        else if (tradeCount > 1000) score += 10;
        else score += 5;

        return score;
    }
}

如遇任何疑问或有进一步的需求,请随时与我私信或者评论联系。

{{voteData.voteSum}} 人已参与
支持
反对
请登录后查看

123c001fa85d 最后编辑于2026-07-18 12:01:40

快捷回复
回复
回复
回复({{post_count}}) {{!is_user ? '我的回复' :'全部回复'}}
排序 默认正序 回复倒序 点赞倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level || item.bbs_level }}

作者 管理员 企业

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推荐': '推荐'}}
{{item.is_suggest == 1? '取消推荐': '推荐'}} 【已收集】
{{item.floor}}# 沙发 板凳 地板 {{item.floor}}# 【已收集】
{{item.user_info.title || '暂无简介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打赏
已打赏¥{{item.reward_price}}
{{item.like_count}}
分享
{{item.showReply ? '取消回复' : '回复'}}
删除
回复
回复

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回复 {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打赏
已打赏¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回复' : '回复'}}
删除
回复
回复
收起 展开更多
查看更多
打赏
已打赏¥{{reward_price}}
36
{{like_count}}
{{collect_count}}
添加回复 ({{post_count}})

相关推荐

快速安全登录

使用微信扫码登录
回复
回复
问题:
问题自动获取的帖子内容,不准确时需要手动修改. [获取答案]
答案:
提交
bug 需求 取 消 确 定
打赏金额
当前余额:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
请输入 0.1-{{reward_max_price}} 范围内的数值
打赏成功
¥{{price}}
完成 确认打赏

微信登录/注册

切换手机号登录

{{ bind_phone ? '绑定手机' : '手机登录'}}

{{codeText}}
切换微信登录/注册
暂不绑定
CRMEB客服
CRMEB咨询热线 400-8888-794

扫码领取产品资料

功能清单
思维导图
安装教程
CRMEB开源商城下载 源码下载 CRMEB帮助文档 帮助文档
返回顶部 返回顶部
CRMEB客服