微店商品详情API接口系列,API接口请求如下

微店商品详情API接口

微店(Weidian)提供了一系列的API接口用于获取商品信息,以下是主要的商品相关API接口及其使用方法。

1. 获取商品详情接口

请求URL

bash 复制代码
https://v2.weidian.com/item/get

请求方式

复制代码
POST

请求参数

参数名 类型 必填 描述
access_token string 是 授权后获得的access_token
item_id string 是 商品ID
fields string 否 需要返回的字段,多个字段用逗号分隔

请求示例

python 复制代码
python
import requests
import json
 
def get_weidian_item_detail(access_token, item_id):
    url = "https://v2.weidian.com/item/get"
    headers = {
        "Content-Type": "application/json"
    }
    data = {
        "access_token": access_token,
        "item_id": item_id,
        "fields": "item_id,title,price,stock,images,desc,skus"
    }
    
    response = requests.post(url, headers=headers, data=json.dumps(data))
    return response.json()
 
# 使用示例
# access_token = "your_access_token"  # 替换为实际的access_token
# item_id = "123456789"  # 替换为实际商品ID
# detail = get_weidian_item_detail(access_token, item_id)
# print(json.dumps(detail, indent=2, ensure_ascii=False))

返回数据示例,API接口测试

json 复制代码
json
{
  "status": {
    "status_code": 0,
    "status_reason": ""
  },
  "data": {
    "item_id": "123456789",
    "title": "商品标题",
    "price": "99.00",
    "original_price": "199.00",
    "stock": 100,
    "images": [
      "https://wd.image.weidian.com/123456789/1.jpg",
      "https://wd.image.weidian.com/123456789/2.jpg"
    ],
    "desc": "商品描述HTML内容",
    "skus": [
      {
        "sku_id": "sku123",
        "title": "红色-XL",
        "price": "99.00",
        "stock": 50,
        "props": [
          {"name": "颜色", "value": "红色"},
          {"name": "尺寸", "value": "XL"}
        ]
      },
      {
        "sku_id": "sku456",
        "title": "蓝色-L",
        "price": "89.00",
        "stock": 30,
        "props": [
          {"name": "颜色", "value": "蓝色"},
          {"name": "尺寸", "value": "L"}
        ]
      }
    ],
    "category": {
      "id": "cat123",
      "name": "服装"
    },
    "postage": "10.00",
    "is_virtual": false,
    "created_time": 1634567890,
    "updated_time": 1634567890
  }
}

2. 获取商品列表接口

请求URL

bash 复制代码
https://v2.weidian.com/item/list

请求方式

复制代码
POST

请求参数

参数名 类型 必填 描述
access_token string 是 授权后获得的access_token
page_num int 否 页码,默认1
page_size int 否 每页数量,默认20,最大100
status int 否 商品状态:0全部 1出售中 2已售罄 3仓库中

请求示例

ini 复制代码
python
def get_weidian_item_list(access_token, page_num=1, page_size=20, status=0):
    url = "https://v2.weidian.com/item/list"
    headers = {
        "Content-Type": "application/json"
    }
    data = {
        "access_token": access_token,
        "page_num": page_num,
        "page_size": page_size,
        "status": status
    }
    
    response = requests.post(url, headers=headers, data=json.dumps(data))
    return response.json()
 
# 使用示例
# item_list = get_weidian_item_list(access_token)
# print(json.dumps(item_list, indent=2, ensure_ascii=False))

3. 获取商品SKU信息接口

请求URL

bash 复制代码
https://v2.weidian.com/item/sku/get

请求方式

复制代码
POST

请求参数

参数名 类型 必填 描述
access_token string 是 授权后获得的access_token
item_id string 是 商品ID

请求示例

ini 复制代码
python
def get_weidian_item_skus(access_token, item_id):
    url = "https://v2.weidian.com/item/sku/get"
    headers = {
        "Content-Type": "application/json"
    }
    data = {
        "access_token": access_token,
        "item_id": item_id
    }
    
    response = requests.post(url, headers=headers, data=json.dumps(data))
    return response.json()
 
# 使用示例
# skus = get_weidian_item_skus(access_token, item_id)
# print(json.dumps(skus, indent=2, ensure_ascii=False))

4. 获取商品评价接口

请求URL

bash 复制代码
https://v2.weidian.com/item/rate/list

请求方式

复制代码
POST

请求参数

参数名 类型 必填 描述
access_token string 是 授权后获得的access_token
item_id string 是 商品ID
page_num int 否 页码,默认1
page_size int 否 每页数量,默认20,最大100

请求示例

ini 复制代码
python
def get_weidian_item_rates(access_token, item_id, page_num=1, page_size=20):
    url = "https://v2.weidian.com/item/rate/list"
    headers = {
        "Content-Type": "application/json"
    }
    data = {
        "access_token": access_token,
        "item_id": item_id,
        "page_num": page_num,
        "page_size": page_size
    }
    
    response = requests.post(url, headers=headers, data=json.dumps(data))
    return response.json()
 
# 使用示例
# rates = get_weidian_item_rates(access_token, item_id)
# print(json.dumps(rates, indent=2, ensure_ascii=False))

认证与授权

在使用微店API前,需要先获取access_token:

  1. 获取授权URL:

    bash 复制代码
    https://v2.weidian.com/oauth2/authorize

    参数:

    • client_id: 应用ID
    • response_type: code
    • redirect_uri: 回调地址
    • state: 自定义参数
  2. 获取access_token:

    kotlin 复制代码
    python
    def get_weidian_access_token(client_id, client_secret, code):
        url = "https://v2.weidian.com/oauth2/access_token"
        data = {
            "client_id": client_id,
            "client_secret": client_secret,
            "grant_type": "authorization_code",
            "code": code
        }
        response = requests.post(url, data=data)
        return response.json()
相关推荐
高频因子挖掘机2 小时前
500只股票 × 多年日线:数据获取与本地存储如何分工?
后端·github·api
高频因子挖掘机3 小时前
别急着搭数据平台:量化策略开发如何用最小闭环验证想法
后端·github·api
张张123y3 小时前
# 后端第七课:FastAPI 实战入门(用刚学的 Python 写第一个 API 接口)
开发语言·python·mysql·api·fastapi
高频因子挖掘机11 小时前
实时行情与分钟 K 线如何协同?Python 量化系统的数据管道设计实践
后端·github·api
高频因子挖掘机12 小时前
跨市场回测为什么会出现隐蔽的数据错误?从标的映射到历史一致性
后端·github·api
FITA阿泽要努力1 天前
如何调用 LLM 接口
python·api·agent
DevOpenClub1 天前
营销物料如何批量生成又能回溯:二维码、截图和图片压缩任务设计
自动化·api·二维码
高频因子挖掘机1 天前
量化回测应该保存不复权数据吗?从数据口径到收益计算的工程实践
后端·github·api
高频因子挖掘机1 天前
实时行情为什么不应该逐只股票请求?批量查询与标的池管理实践
后端·github·api
余槐i2 天前
Ollama 长文档问答后半段全空:context 默认值与静默截断的代价
性能优化·大模型·api·rag·ollama