微店商品详情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()
相关推荐
崔庆才丨静觅4 小时前
Veo API:0 门槛量产商业级视频!2026 视频流量密码,创作者/商家必藏
后端·google·api
aigcapi1 天前
2026 GPT/Gemini API接入优选指南+平台榜单:破解“GPT API哪个平台好”核心难题
人工智能·gpt·api
编程武士2 天前
API优先战略:数字时代架构设计的核心基石
架构·api
崔庆才丨静觅2 天前
0代码生成4K高清图!ACE Data Platform × SeeDream 专属方案:小白/商家闭眼冲
人工智能·api
程序员佳佳3 天前
【万字硬核】从零构建企业级AI中台:基于Vector Engine整合GPT-5.2、Sora2与Veo3的落地实践指南
人工智能·gpt·chatgpt·ai作画·aigc·api·ai编程
崔庆才丨静觅3 天前
惊了!1句话生成带货短视频!ACE Data Platform × SeeDance 让普通人也能当“视频导演”
api
星光不问赶路人3 天前
Nginx 的 location 路径匹配语法详解
nginx·api
小和尚敲代码4 天前
八字变十字国学api根据日期得到十字加入刻柱干支的api调用
api·十字·八字·国学·刻柱
新诺韦尔API4 天前
手机三要素验证不通过的原因?
大数据·智能手机·api
天远云服5 天前
拒绝性能瓶颈:使用Go协程高效清洗天远多头借贷行业风险数据
大数据·api