在跨境电商、供应链管理和 ERP 系统集成的实际业务中,获取 1688 商品的包装、运费和尺寸信息,是一个绕不开的核心需求。无论是做采购成本核算、物流方案规划,还是仓库货架空间计算,都离不开这些基础数据。这篇文章就系统地梳理一下,如何通过官方 API 和第三方方案来拿到这些数据,并且附上完整的代码实现,方便大家直接上手。

一、接口体系概览
很多人一开始会以为 1688 有独立的包装、运费、尺寸接口,但实际上这些数据并没有一个单独的 API 来提供。它们分散在商品详情类接口的不同字段里,需要根据具体的业务场景来选择接入方案。下面这张表基本能帮你理清思路:
表格
| 接口类型 | 核心接口 | 包装/运费/尺寸相关字段 | 数据覆盖度 |
| 官方开放平台 | alibaba.product.get | shippingInfo 中的重量、尺寸、运费模板 | 基础信息 |
| 第三方聚合 API | 1688.item_get | weight、packing、packingSize、grossWeight、post_fee | 完整包装规格 + 运费 |
物流订单 APIalibaba.trade.getLogisticsInfos.buyerView | 物流单号、承运商、收发件信息 | 订单级物流跟踪 |
","rows":4,"cols":4,"id":"RsMSE"}">
二、官方开放平台:商品包装信息获取
2.1 接入准备
使用官方接口的第一步当然是注册企业开发者账号并创建应用。
然后拿到 App Key 和 App Secret,申请 alibaba.product.get 接口的权限,最后通过 OAuth2.0 获取 Access Token。
2.2 核心请求参数
表格
| 参数名 | 类型 | 必选 | 说明 | 示例值 |
app_key | String | 是 | 应用唯一标识 | 12345678 |
method | String | 是 | 接口方法名 | com.alibaba.product.alibaba.product.get |
timestamp | String | 是 | 时间戳 | 2026-06-17 10:00:00 |
v | String | 是 | API 版本 | 2.0 |
sign | String | 是 | MD5 签名 | 见下方生成逻辑 |
productId | Long | 是 | 1688 商品 ID | 619899292404 |
fields | String | 否 | 指定返回字段 | shippingInfo,saleInfo,attributes |
","rows":8,"cols":5,"id":"cmA V8"}">
2.3 签名生成算法
1688 官方 API 用的是 MD5 签名,规则其实不复杂:
plain
有一点要注意:参数值必须进行 URL 编码,而且参数要按照 key 的升序排列。
2.4 完整调用代码(Python)
Python
str:n \"\"\"n 生成 1688 官方 API 的 MD5 签名n \"\"\"n # 过滤空值并排序n sorted_params = sorted(n [(k, v) for k, v in params.items() if v is not None and k != \"sign\"],n key=lambda x: x[0]n )n n # 拼接签名字符串n sign_str = self.app_secretn for key, value in sorted_params:n encoded_value = urllib.parse.quote(str(value), safe='')n sign_str += f\"{key}{encoded_value}\"n sign_str += self.app_secretn n # MD5 加密并转大写n return hashlib.md5(sign_str.encode('utf-8')).hexdigest().upper()n n def get_product_shipping_info(self, product_id: str, fields: str = None) -> Dict:n \"\"\"n 获取商品包装、运费、尺寸信息n n :param product_id: 1688 商品 IDn :param fields: 指定返回字段,如 \"shippingInfo,saleInfo,attributes\"n :return: 解析后的包装信息n \"\"\"n timestamp = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime())n n params = {n \"app_key\": self.app_key,n \"method\": \"com.alibaba.product.alibaba.product.get\",n \"timestamp\": timestamp,n \"v\": \"2.0\",n \"format\": \"json\",n \"sign_method\": \"md5\",n \"access_token\": self.access_token,n \"productId\": product_id,n }n n if fields:n params[\"fields\"] = fieldsn n # 生成签名n params[\"sign\"] = self._generate_sign(params)n n try:n response = requests.post(self.GATEWAY_URL, data=params, timeout=30)n response.raise_for_status()n data = response.json()n n # 解析包装相关字段n return self._parse_shipping_data(data, product_id)n n except requests.exceptions.RequestException as e:n return {n \"success\": False,n \"error\": f\"请求异常: {str(e)}\",n \"product_id\": product_idn }n n def _parse_shipping_data(self, raw_data: dict, product_id: str) -> Dict:n \"\"\"n 从官方 API 返回数据中解析包装、运费、尺寸信息n \"\"\"n product_info = raw_data.get(\"productinfo\", {})n shipping = product_info.get(\"shippingInfo\", {})n sale_info = product_info.get(\"saleInfo\", {})n attributes = product_info.get(\"attributes\", [])n n # 从 attributes 中提取包装相关属性n packaging_attrs = {}n for attr in attributes:n attr_name = attr.get(\"attributeName\", \"\")n if any(kw in attr_name for kw in [\"包装\", \"重量\", \"体积\", \"尺寸\", \"运费\"]):n packaging_attrs[attr_name] = attr.get(\"value\")n n return {n \"success\": True,n \"source\": \"official_api\",n \"product_id\": product_id,n \"product_title\": product_info.get(\"subject\"),n n # 核心包装/尺寸字段n \"unit_weight_kg\": shipping.get(\"unitWeight\"), # 单位重量(千克)n \"package_size_cm\": shipping.get(\"packageSize\"), # 包装尺寸(长x宽x高)n \"volume_cm3\": shipping.get(\"volume\"), # 体积(立方厘米)n n # 运费相关n \"freight_template_id\": shipping.get(\"freightTemplateID\"), # 运费模板 IDn \"send_goods_address\": shipping.get(\"sendGoodsAddress\"), # 发货地址n n # 销售信息n \"min_order_quantity\": sale_info.get(\"minOrderQuantity\"), # 最小起订量n \"unit\": sale_info.get(\"unit\"), # 计量单位n \"price_ranges\": sale_info.get(\"priceRanges\"), # 阶梯价格n n # 扩展属性n \"packaging_attributes\": packaging_attrs,n \"raw_data\": raw_datan }n# ==================== 使用示例 ====================nif __name__ == \"__main__\":n api = Official1688API(n app_key=\"your_app_key\",n app_secret=\"your_app_secret\",n access_token=\"your_access_token\"n )n n result = api.get_product_shipping_info(n product_id=\"619899292404\",n fields=\"productID,subject,shippingInfo,saleInfo,attributes\"n )n n print(json.dumps(result, ensure_ascii=False, indent=2))","id":"Q18Fm"}">
2.5 官方 API 返回字段说明
表格
| 字段路径 | 含义 | 示例值 | 应用场景 |
shippingInfo.unitWeight | 单位重量(kg) | 1.5 | 计算单品运费、仓储规划 |
shippingInfo.packageSize | 包装尺寸(cm) | 10x20x50 | 物流计费、货架规划 |
shippingInfo.volume | 体积(立方厘米) | 10000 | 体积重计算 |
shippingInfo.freightTemplateID | 运费模板 ID | 11754104 | 查询运费规则 |
shippingInfo.sendGoodsAddress | 发货地址 | {\"province\":\"浙江\",\"city\":\"杭州\"} | 计算运输距离 |
saleInfo.priceRanges | 阶梯价格 | [{\"startQuantity\":3,\"price\":8.0}] | 采购成本核算 |
","rows":7,"cols":4,"id":"Wcn05"}">
注意:官方 API 返回的包装字段比较基础,详细的包装方式(比如独立包装、彩盒、纸箱等)通常需要从 attributes 或者 description 字段里进一步解析。
三、第三方聚合 API:完整包装规格获取
官方 API 对包装信息的支持确实比较有限,所以在实际开发中,更推荐用第三方聚合 API。这些服务通常已经整合了完整的包装规格、运费和尺寸数据,用起来顺手很多。
3.1 常见第三方 API 字段映射
表格
| 通用含义 | AliPrice | VV-Tool | 其他常见命名 |
| 商品净重 | weight | unitWeight | item_weight、netWeight |
| 商品毛重 | grossWeight | - | gross_weight、totalWeight |
| 包装方式 | packing | - | packagingType、packageStyle |
| 单品包装尺寸 | packingSize | packageSize | item_size、unitSize |
| 外箱尺寸 | cartonSize | - | outerCartonSize、boxSize |
| 每箱数量 | cartonQty | - | quantityPerCarton |
| 体积 | - | volume | cubicVolume |
| 邮费 | post_fee | - | shipping_fee |
| 快递费 | express_fee | - | express_fee |
| EMS 费用 | ems_fee | - | ems_fee |
","rows":11,"cols":4,"id":"CA4Fx"}">
3.2 第三方 API 封装代码
Python
Dict:n \"\"\"n 获取完整的包装、运费、尺寸信息n \"\"\"n try:n if self.provider == \"aliprice\":n data = self._call_aliprice(product_id)n elif self.provider == \"vv_tool\":n data = self._call_vv_tool(product_id)n else:n data = self._call_generic(product_id)n n return self._normalize_packaging_data(data, product_id)n n except Exception as e:n return {n \"success\": False,n \"error\": str(e),n \"product_id\": product_idn }n n def _call_aliprice(self, product_id: str) -> dict:n \"\"\"调用 AliPrice API\"\"\"n headers = {n \"Authorization\": f\"Bearer {self.api_key}\",n \"Content-Type\": \"application/json\"n }n payload = {n \"offerId\": product_id,n \"includePackaging\": True,n \"includeSku\": Truen }n response = requests.post(n self.endpoints[\"aliprice\"],n headers=headers,n json=payload,n timeout=30n )n response.raise_for_status()n return response.json()n n def _call_vv_tool(self, product_id: str) -> dict:n \"\"\"调用 VV-Tool API\"\"\"n headers = {\"Authorization\": f\"Bearer {self.api_key}\"}n params = {\"productId\": product_id}n response = requests.get(n self.endpoints[\"vv_tool\"],n headers=headers,n params=params,n timeout=30n )n response.raise_for_status()n return response.json()n n def _normalize_packaging_data(self, raw_data: dict, product_id: str) -> Dict:n \"\"\"n 标准化不同来源的包装数据n \"\"\"n # 适配不同响应结构n item = raw_data.get(\"item\", raw_data)n n # 提取重量(统一转换为 kg)n net_weight = self._extract_weight(item.get(\"weight\") or item.get(\"unitWeight\"))n gross_weight = self._extract_weight(item.get(\"grossWeight\"))n n # 提取尺寸n unit_size = item.get(\"packingSize\") or item.get(\"packageSize\")n carton_size = item.get(\"cartonSize\")n n # 提取运费n post_fee = item.get(\"post_fee\", 0)n express_fee = item.get(\"express_fee\", 0)n ems_fee = item.get(\"ems_fee\", 0)n n # 计算物流指标n logistics = {}n if carton_size and gross_weight:n logistics = self._calculate_logistics_metrics(carton_size, gross_weight)n n return {n \"success\": True,n \"source\": f\"third_party_{self.provider}\",n \"product_id\": product_id,n \"title\": item.get(\"title\"),n n # 重量信息n \"net_weight_kg\": net_weight,n \"gross_weight_kg\": gross_weight,n n # 尺寸信息n \"unit_package_size\": unit_size, # 单品包装尺寸,如 \"10*20*5cm\"n \"carton_dimensions\": carton_size, # 外箱尺寸,如 \"50*40*30cm\"n \"volume_cm3\": item.get(\"volume\"),n n # 包装方式n \"packing_type\": item.get(\"packing\") or item.get(\"packagingType\"),n \"quantity_per_carton\": item.get(\"cartonQty\"),n n # 运费信息n \"shipping_fees\": {n \"post_fee\": post_fee, # 普通邮费n \"express_fee\": express_fee, # 快递费n \"ems_fee\": ems_fee, # EMS 费用n \"shipping_to\": item.get(\"shipping_to\") # 发货至n },n n # 物流分析n \"logistics_analysis\": logistics,n n \"raw_data\": raw_datan }n n @staticmethodn def _extract_weight(weight_val) -> Optional[float]:n \"\"\"从字符串中提取数值型重量,统一为 kg\"\"\"n if not weight_val:n return Nonen if isinstance(weight_val, (int, float)):n return float(weight_val)n n # 处理字符串如 \"0.8kg\"、\"1.2KG\"、\"800g\"n match = re.search(r'(\\d+\\.?\\d*)', str(weight_val))n if not match:n return Nonen n value = float(match.group(1))n weight_str = str(weight_val).lower()n n if 'g' in weight_str and 'kg' not in weight_str:n value = value / 1000 # 克转千克n n return round(value, 3)n n @staticmethodn def _calculate_logistics_metrics(carton_size: str, actual_weight: float) -> Dict:n \"\"\"n 基于包装尺寸和重量计算物流指标n \"\"\"n try:n # 解析尺寸(格式:50*40*30cm 或 50x40x30)n dims = [float(x) for x in re.split(r'[xX*×]', carton_size.replace('cm', '').strip())]n if len(dims) != 3:n return {}n n length, width, height = dimsn n # 计算体积重(快递行业标准:体积重 = 长*宽*高 / 5000)n volume_weight = (length * width * height) / 5000n n # 计费重量 = max(体积重, 实际重量)n chargeable_weight = max(volume_weight, actual_weight)n n return {n \"carton_length_cm\": length,n \"carton_width_cm\": width,n \"carton_height_cm\": height,n \"carton_volume_m3\": round(length * width * height / 1000000, 4),n \"volume_weight_kg\": round(volume_weight, 2),n \"actual_weight_kg\": actual_weight,n \"chargeable_weight_kg\": round(chargeable_weight, 2),n \"dimensional_factor\": \"1:5000\",n \"suitable_shipping\": \"express\" if chargeable_weight < 20 else \"freight\",n \"stackable\": height < 60 # 高度小于60cm适合堆叠n }n except Exception:n return {}n# ==================== 使用示例 ====================nif __name__ == \"__main__\":n api = ThirdParty1688API(n api_key=\"your_third_party_key\",n provider=\"aliprice\"n )n n result = api.get_full_packaging_info(\"1234567890\")n n if result[\"success\"]:n print(f\"商品: {result['title']}\")n print(f\"净重: {result['net_weight_kg']} kg\")n print(f\"毛重: {result['gross_weight_kg']} kg\")n print(f\"包装方式: {result['packing_type']}\")n print(f\"单品尺寸: {result['unit_package_size']}\")n print(f\"外箱尺寸: {result['carton_dimensions']}\")n print(f\"邮费: ¥{result['shipping_fees']['post_fee']}\")n n logistics = result.get(\"logistics_analysis\", {})n if logistics:n print(f\"\\n物流分析:\")n print(f\" 体积重: {logistics['volume_weight_kg']} kg\")n print(f\" 计费重量: {logistics['chargeable_weight_kg']} kg\")n print(f\" 推荐运输方式: {'快递' if logistics['suitable_shipping'] == 'express' else '货运'}\")n else:n print(f\"获取失败: {result['error']}\")","id":"5yDpB"}">
四、物流订单 API:获取实际运费和物流跟踪
对于已经成交的订单,可以用 alibaba.trade.getLogisticsInfos.buyerView 这个接口拿到实际物流信息。
4.1 接口说明
表格
| 参数 | 类型 | 必选 | 说明 |
orderId | Long | 是 | 1688 订单号 |
fields | String | 否 | 指定返回字段:company.name,sender,receiver,sendgood |
webSite | String | 是 | 1688 或 alibaba |
access_token | String | 是 | 买家授权令牌 |
_aop_signature | String | 是 | 请求签名 |
","rows":6,"cols":4,"id":"wcV8I"}">
4.2 调用代码
Python
Dict:n \"\"\"n 获取订单物流详情n n :param order_id: 1688 订单号n :param fields: 返回字段,如 \"company.name,sender,receiver,sendgood\"n \"\"\"n from official_api import Official1688API # 复用签名方法n n timestamp = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime())n n params = {n \"app_key\": self.app_key,n \"method\": \"com.alibaba.logistics.alibaba.trade.getLogisticsInfos.buyerView\",n \"timestamp\": timestamp,n \"v\": \"1\",n \"format\": \"json\",n \"sign_method\": \"md5\",n \"access_token\": self.access_token,n \"orderId\": order_id,n \"webSite\": \"1688\"n }n n if fields:n params[\"fields\"] = fieldsn n # 生成签名(复用 Official1688API 的签名逻辑)n signer = Official1688API(self.app_key, self.app_secret, self.access_token)n params[\"sign\"] = signer._generate_sign(params)n n try:n response = requests.post(self.GATEWAY_URL, data=params, timeout=30)n response.raise_for_status()n data = response.json()n n if data.get(\"success\"):n return {n \"success\": True,n \"order_id\": order_id,n \"logistics_list\": data.get(\"result\", []),n \"raw_data\": datan }n else:n return {n \"success\": False,n \"error\": data.get(\"errorMessage\"),n \"error_code\": data.get(\"errorCode\")n }n n except requests.exceptions.RequestException as e:n return {n \"success\": False,n \"error\": f\"请求异常: {str(e)}\"n }","id":"mNV71"}">
4.3 返回字段说明
表格
| 字段 | 含义 | 示例值 |
logisticsId | 物流单号 | BX111841674232006 |
status | 物流状态 | SIGN(已签收) |
logisticsCompanyId | 物流公司 ID | 8 |
sendGoods | 发货商品明细 | 含商品名称、数量、单位 |
receiver | 收件人信息 | 地址、电话、姓名 |
sender | 发件人信息 | 地址、电话、姓名 |
","rows":7,"cols":3,"id":"M1ryc"}">
五、统一封装:智能运费计算引擎
最后,我们把上面这些能力整合一下,构建一个支持多数据源、可以自动计算运费的统一接口:
Python
Dict:n \"\"\"n 计算商品运费n n :param product_id: 1688 商品 IDn :param quantity: 购买数量n :param destination: 目的地(用于运费模板匹配)n \"\"\"n # 优先使用第三方 API(数据更完整)n if self.third_party:n packaging = self.third_party.get_full_packaging_info(product_id)n if packaging.get(\"success\"):n return self._calculate_from_third_party(packaging, quantity, destination)n n # 回退到官方 APIn if self.official:n shipping = self.official.get_product_shipping_info(product_id)n if shipping.get(\"success\"):n return self._calculate_from_official(shipping, quantity, destination)n n return {\"success\": False, \"error\": \"无可用数据源\"}n n def _calculate_from_third_party(self, data: dict, quantity: int, destination: str) -> Dict:n \"\"\"基于第三方 API 数据计算运费\"\"\"n fees = data.get(\"shipping_fees\", {})n logistics = data.get(\"logistics_analysis\", {})n n # 基础运费(取邮费或快递费)n base_fee = fees.get(\"express_fee\", 0) or fees.get(\"post_fee\", 0)n n # 按数量计算(假设阶梯运费)n total_fee = base_fee * max(1, quantity / (data.get(\"quantity_per_carton\") or 1))n n # 按重量计算(快递续重)n chargeable_weight = logistics.get(\"chargeable_weight_kg\", 0) * quantityn weight_fee = self._estimate_weight_fee(chargeable_weight)n n return {n \"success\": True,n \"product_id\": data[\"product_id\"],n \"quantity\": quantity,n \"destination\": destination,n \"freight_details\": {n \"base_fee\": round(base_fee, 2),n \"weight_fee\": round(weight_fee, 2),n \"estimated_total\": round(max(total_fee, weight_fee), 2)n },n \"packaging_info\": {n \"unit_weight\": data.get(\"net_weight_kg\"),n \"total_weight\": round(data.get(\"gross_weight_kg\", 0) * quantity, 2),n \"chargeable_weight\": round(chargeable_weight, 2)n }n }n n @staticmethodn def _estimate_weight_fee(weight_kg: float) -> float:n \"\"\"估算续重运费(简化模型)\"\"\"n if weight_kg <= 1:n return 8.0 # 首重n return 8.0 + (weight_kg - 1) * 4.0 # 续重 4元/kgn# ==================== 完整使用示例 ====================nif __name__ == \"__main__\":n # 初始化 API 客户端n official = Official1688API(n app_key=\"your_app_key\",n app_secret=\"your_app_secret\",n access_token=\"your_token\"n )n n third_party = ThirdParty1688API(n api_key=\"your_third_party_key\",n provider=\"aliprice\"n )n n # 创建运费计算器n calculator = SmartFreightCalculator(official, third_party)n n # 计算运费n result = calculator.calculate_freight(n product_id=\"1234567890\",n quantity=100,n destination=\"广东省深圳市\"n )n n print(json.dumps(result, ensure_ascii=False, indent=2))","id":"WF2Hr"}">
六、常见问题与解决方案
表格
| 问题现象 | 可能原因 | 解决方案 |
| 官方 API 返回包装信息为空 | 商家未填写或字段权限不足 | 使用第三方 API 或联系商家补充 |
| 重量单位不一致(kg/g) | 不同接口标准不同 | 统一转换为千克(kg)存储 |
| 尺寸格式不统一 | 商家录入习惯差异 | 正则解析并标准化为厘米 |
| 运费与实际不符 | 运费模板未匹配目的地 | 结合 freightTemplateID 查询详细运费规则 |
| API 调用频率受限 | 官方 API 限流(默认 1000 次/天) | 使用第三方 API 或申请提升额度 |
| 跨境包裹重量差异 | 1688 字段为预估重量 | 实际发货前称重校准 |
","rows":7,"cols":3,"id":"v9HRd"}">
七、最佳实践建议
数据标准化:建立包装信息标准库,把“彩盒”、“color box”、“纸盒”等不同叫法映射为统一编码。
多源校验:官方 API 和第三方 API 双重校验,确保数据的一致性。
缓存策略:包装信息变更频率不高,建议缓存 6-24 小时,能有效减少 API 调用成本。
异常兜底:如果商家没有填写包装信息,设置默认值或者标记为“需人工确认”。
合规注意:通过官方 API 或授权第三方获取数据,避免未经授权的爬虫操作带来的法律风险。
八、扩展应用场景
基于包装运费尺寸 API,可以构建不少有价值的应用:
智能运费计算:根据重量、尺寸、目的地自动选择最优物流方案。
仓储优化:基于包装尺寸计算货架空间需求,优化仓库布局。
采购决策:对比不同供应商的包装规格,选择物流成本最低的方案。
报关自动化:自动生成报关所需的重量、尺寸、包装类型数据。
碳足迹计算:基于重量和运输距离计算碳排放量。