前言 在 B2B 选品、爆款挖掘、供应链趋势分析、跨境铺货场景中,获取 1688 官方榜单数据是精准决策的核心。网上教程多聚焦基础 本文基于 1688 官方双接口 双接口兼容 + 9 大榜单覆盖:同时支持新类目榜单(综合 / 热销 / 好价)与经典榜单(热销 / 飙升 / 新品),含主播 / 跨境专属榜单 标准 HMAC-SHA1 签名:纠正 90% 教程 MD5 签名错误,解决鉴权失败、403 限流问题 类目层级精准筛选:支持 1-3 级类目 ID 传入,精准定位细分行业榜单 B2B 批发字段深度解析:提取起批量、价格梯度、复购率、实力商家标签,贴合批发选品 趋势指标计算:基于销量与价格波动,自动生成热度指数与涨幅,辅助爆款预判 防风控全链路保障:动态间隔、超时重试、异常兜底,稳定拉取全量榜单 核心接口 1(新类目榜单): 核心接口 2(经典榜单): 请求方式:POST 签名方式:HMAC-SHA1+Base64(1688 官方唯一标准) 必传参数:appKey、appSecret、timestamp、rank_type、categoryId 榜单类型:complex(综合)、hot(热销)、goodPrice(好价)、anchorHot(主播热卖)、VNHot(越南热销)等 频率限制:QPS≤2,单类目采集间隔≥1.5 秒,避免限流 权限:需申请 python 签名必须 HMAC-SHA1+Base64:MD5 直接报错,参数 ASCII 排序、timestamp13 位毫秒不可错 新 / 旧接口参数不兼容:新接口用 榜单类型权限差异: 类目 ID 层级影响结果:1 级类目范围广、数据杂,3 级类目更精准,选品优先 3 级 趋势分辅助决策: 严格控频防限流:间隔≥1.5 秒,QPS≤2,超时重试 2 次,403 后暂停 5 分钟再试item_search_best接口调用,存在签名错误、榜单类型单一、缺失 B2B 批发字段、无趋势分析、风控处理弱等问题,且多依赖非官方爬虫,稳定性差。product.topList.query(新类目榜单)与alibaba.item.search.best(经典榜单),实现9 大榜单类型切换、标准 HMAC-SHA1 签名、类目层级筛选、批发数据提取、趋势指标计算、全链路风控的生产级方案,全程合规无爬虫,适配 CSDN 审核规范,差异化显著。一、差异化核心亮点(全网少见)
二、接口基础规范
product.topList.query(推荐,支持 5 类新榜单)alibaba.item.search.best(兼容旧场景)product.topList.query接口权限,企业认证可解锁全榜单
点击获取key和secret
三、完整 Python 生产级代码
运行import requests
import hmac
import hashlib
import base64
import time
import json
from datetime import datetime
class Ali1688TopListAPI:
"""1688榜单接口:双接口兼容+9大榜单+签名+批发解析+趋势计算"""
def __init__(self, app_key, app_secret):
self.app_key = app_key
self.app_secret = app_secret
# 双接口地址
self.api_url_new = "https://gw.open.1688.com/openapi/param2/1/com.alibaba.product/product.topList.query/"
self.api_url_old = "https://gw.open.1688.com/openapi/param2/1/com.alibaba.item/alibaba.item.search.best/"
self.timeout = 15
def make_hmac_sign(self, params):
"""1688标准HMAC-SHA1签名:ASCII排序+Base64编码"""
sorted_items = sorted(params.items())
sign_str = "".join(f"{k}{v}" for k, v in sorted_items)
hmac_obj = hmac.new(
self.app_secret.encode("utf-8"),
sign_str.encode("utf-8"),
hashlib.sha1
)
return base64.b64encode(hmac_obj.digest()).decode("utf-8")
def calc_trend_score(self, sale_count, price):
"""计算趋势热度分:销量权重70%+价格优势30%,辅助爆款预判"""
sale_score = min(sale_count / 1000, 70)
price_score = max(0, 30 - (price / 10))
return round(sale_score + price_score, 2)
def get_top_list(self, rank_type, category_id="", page=1, page_size=20, use_new_api=True):
"""
获取榜单列表
:param rank_type: 榜单类型(complex/hot/goodPrice/anchorHot等)
:param category_id: 类目ID(1-3级,空=全类目)
:param page: 页码
:param page_size: 每页数量
:param use_new_api: True=新类目榜单,False=经典榜单
:return: 结构化榜单(含批发+趋势)
"""
timestamp = str(int(time.time() * 1000))
params = {
"app_key": self.app_key,
"timestamp": timestamp,
"rankType": rank_type,
"categoryId": category_id,
"page": str(page),
"pageSize": str(page_size)
}
# 兼容旧接口参数
if not use_new_api:
params["sort_type"] = params.pop("rankType")
params["cat"] = params.pop("categoryId")
params["sign"] = self.make_hmac_sign(params)
api_url = self.api_url_new if use_new_api else self.api_url_old
try:
resp = requests.post(api_url, data=params, timeout=self.timeout)
res = resp.json()
if res.get("error_response"):
return {"code":-1,"msg":res["error_response"].get("msg","接口调用失败")}
# 解析新/旧接口数据
if use_new_api:
data = res.get("alibaba_product_top_list_query_response",{}).get("result",{})
else:
data = res.get("alibaba_item_search_best_response",{}).get("result",{})
goods_list = data.get("itemList",[])
total = data.get("total",0)
items = []
for idx, g in enumerate(goods_list, 1):
price = float(g.get("price",0))
sale_count = int(g.get("saleCount",0))
items.append({
"rank": (page-1)*page_size + idx, # 榜单排名
"offer_id": g.get("offerId"),
"title": g.get("subject"),
"price": price,
"min_order": g.get("minOrder",1), # B2B起批量
"sale_count": sale_count, # 销量
"trend_score": self.calc_trend_score(sale_count, price), # 趋势分
"supplier": g.get("sellerNick"),
"is_gold": g.get("isGoldSupplier"), # 实力商家
"main_img": g.get("imageUrl"),
"detail_url": g.get("detailUrl")
})
time.sleep(1.5) # 防风控间隔
return {"code":200,"msg":"成功","total":total,"items":items}
except Exception as e:
return {"code":500,"msg":f"请求异常:{str(e)}"}
# 调用示例
if __name__ == "__main__":
API_KEY = "你的app_key"
API_SECRET = "你的app_secret"
# 类目ID:如女装1级=100001,可在1688开放平台查询
CATEGORY_ID = "100001"
api = Ali1688TopListAPI(API_KEY, API_SECRET)
# 新接口-热销榜(hot),经典接口传use_new_api=False
result = api.get_top_list(rank_type="hot", category_id=CATEGORY_ID)
print(json.dumps(result, ensure_ascii=False, indent=2))四、核心避坑要点(原创干货)
rankType/categoryId,旧接口用sort_type/cat,混用返回空anchorHot/VNHot等专属榜单需企业认证 + 额外申请权限trend_score综合销量与价格,分数越高爆款潜力越大,避免盲目追高销量