微店商品详情API返回值说明(JSON格式)
以下是一个典型的微店商品详情API返回的JSON数据结构说明。由于微店官方API可能会随时间更新,以下结构基于常见电商API设计模式,具体字段请以实际API文档为准。
基本响应结构
{ |
"code": 200, |
"message": "success", |
"data": { |
// 商品详情数据 |
} |
} |
响应字段说明
字段 | 类型 | 说明 |
---|
code | int | 状态码,200表示成功 |
message | string | 状态描述信息 |
data | object | 商品详情数据对象 |
商品详情数据对象 (data)
{ |
"item_id": "123456789", |
"title": "商品标题", |
"sub_title": "商品副标题", |
"price": 99.9, |
"original_price": 199.9, |
"stock": 100, |
"sales": 50, |
"status": 1, |
"images": [ |
"http://img.weidian.com/item/1.jpg", |
"http://img.weidian.com/item/2.jpg" |
], |
"description": "商品详细描述HTML", |
"sku_list": [ |
{ |
"sku_id": "sku123", |
"specs": ["颜色:红色", "尺寸:M"], |
"price": 99.9, |
"stock": 20 |
} |
], |
"category": { |
"id": "cate123", |
"name": "服装" |
}, |
"shop": { |
"shop_id": "shop456", |
"name": "微店名称", |
"logo": "http://img.weidian.com/shop/logo.jpg" |
}, |
"postage": 10.0, |
"is_free_postage": false, |
"created_at": "2023-01-01T12:00:00Z", |
"updated_at": "2023-01-10T15:30:00Z" |
} |
商品详情字段说明
字段 | 类型 | 说明 |
---|
item_id | string | 商品唯一ID |
title | string | 商品标题 |
sub_title | string | 商品副标题 |
price | float | 当前价格 |
original_price | float | 原价 |
stock | int | 总库存 |
sales | int | 销量 |
status | int | 商品状态(1:在售, 0:下架等) |
images | array | 商品图片URL数组 |
description | string | 商品详细描述(通常是HTML格式) |
sku_list | array | SKU列表 |
category | object | 商品分类信息 |
shop | object | 店铺信息 |
postage | float | 运费 |
is_free_postage | boolean | 是否包邮 |
created_at | string | 创建时间(ISO8601格式) |
updated_at | string | 更新时间(ISO8601格式) |
SKU对象说明
{ |
"sku_id": "sku123", |
"specs": ["颜色:红色", "尺寸:M"], |
"price": 99.9, |
"stock": 20, |
"barcode": "691234567890", |
"image": "http://img.weidian.com/sku/1.jpg" |
} |
SKU字段说明
字段 | 类型 | 说明 |
---|
sku_id | string | SKU唯一ID |
specs | array | 规格属性数组 |
price | float | 该SKU价格 |
stock | int | 该SKU库存 |
barcode | string | 商品条码(可选) |
image | string | SKU特有图片(可选) |
Python采集示例代码
import requests |
import json |
|
def get_weidian_item_detail(item_id, access_token): |
url = f"https://api.weidian.com/api/item/get?item_id={item_id}&access_token={access_token}" |
|
headers = { |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", |
"Content-Type": "application/json" |
} |
|
try: |
response = requests.get(url, headers=headers) |
response.raise_for_status() |
|
data = response.json() |
|
if data.get("code") == 200: |
return data["data"] |
else: |
print(f"API请求失败: {data.get('message')}") |
return None |
|
except requests.exceptions.RequestException as e: |
print(f"请求异常: {str(e)}") |
return None |
|
# 使用示例 |
item_detail = get_weidian_item_detail("123456789", "your_access_token") |
if item_detail: |
print(json.dumps(item_detail, indent=2, ensure_ascii=False)) |