宅男在线永久免费观看网直播,亚洲欧洲日产国码无码久久99,野花社区在线观看视频,亚洲人交乣女bbw,一本一本久久a久久精品综合不卡

全部
常見問題
產(chǎn)品動態(tài)
精選推薦

微店商品詳情及關(guān)鍵字搜索的 API 接口接入、數(shù)據(jù)解析與技術(shù)實現(xiàn)

管理 管理 編輯 刪除

09101202505291415079599.png

微店獲得微店商品詳情 API

cf426202505291415078023.png

微店獲得微店關(guān)鍵字搜索 API

2. 核心 API 接口

商品詳情接口申請注冊測試

# 請求URL
https://api.weidian.com/item/detail

# 請求參數(shù)
{
    "appid": "YOUR_APPID",
    "timestamp": 1695974400,  # 當前時間戳
    "sign": "SIGNATURE",  # 簽名
    "item_id": "123456789"  # 商品ID
}


# 請求URL
https://api.weidian.com/item/search

# 請求參數(shù)
{
    "appid": "YOUR_APPID",
    "timestamp": 1695974400,
    "sign": "SIGNATURE",
    "keyword": "手機",  # 搜索關(guān)鍵詞
    "page": 1,  # 頁碼
    "page_size": 20  # 每頁數(shù)量
}


3. 簽名生成算法


import hashlib

def generate_sign(params, app_secret):
    """生成API簽名"""
    # 按參數(shù)名排序
    sorted_params = sorted(params.items(), key=lambda x: x[0])
    
    # 拼接參數(shù)字符串
    sign_str = ''.join([f"{k}{v}" for k, v in sorted_params])
    
    # 拼接AppSecret
    sign_str = app_secret + sign_str + app_secret
    
    # MD5加密
    return hashlib.md5(sign_str.encode('utf-8')).hexdigest().upper()


二、Python API 封裝實現(xiàn)


import requests
import time
import json
import hashlib

class WeidianAPI:
    def __init__(self, app_id, app_secret):
        self.app_id = app_id
        self.app_secret = app_secret
        self.base_url = "https://api.weidian.com"
    
    def _generate_sign(self, params):
        """生成API簽名"""
        sorted_params = sorted(params.items(), key=lambda x: x[0])
        sign_str = ''.join([f"{k}{v}" for k, v in sorted_params])
        sign_str = self.app_secret + sign_str + self.app_secret
        return hashlib.md5(sign_str.encode('utf-8')).hexdigest().upper()
    
    def _request(self, endpoint, params):
        """發(fā)送API請求"""
        # 添加公共參數(shù)
        common_params = {
            "appid": self.app_id,
            "timestamp": int(time.time())
        }
        all_params = {**common_params, **params}
        
        # 生成簽名
        all_params["sign"] = self._generate_sign(all_params)
        
        # 發(fā)送請求
        url = f"{self.base_url}{endpoint}"
        response = requests.post(url, json=all_params)
        
        return response.json()
    
    def get_item_detail(self, item_id):
        """獲取商品詳情"""
        endpoint = "/item/detail"
        params = {"item_id": item_id}
        return self._request(endpoint, params)
    # 假設(shè) API 接口地址,復(fù)制鏈接獲取測試 
    #API url=o0b.cn/ibrad  wechat id: TaoxiJd-api"
    def search_items(self, keyword, page=1, page_size=20):
        """關(guān)鍵字搜索商品"""
        endpoint = "/item/search"
        params = {
            "keyword": keyword,
            "page": page,
            "page_size": page_size
        }
        return self._request(endpoint, params)
    
    def parse_item_data(self, item_data):
        """解析商品數(shù)據(jù)"""
        if not item_data:
            return None
        
        return {
            "item_id": item_data.get("item_id"),
            "title": item_data.get("title"),
            "price": item_data.get("price"),
            "original_price": item_data.get("original_price"),
            "stock": item_data.get("stock"),
            "sales": item_data.get("sales"),
            "main_image": item_data.get("main_image"),
            "detail_images": item_data.get("detail_images", []),
            "category_id": item_data.get("category_id"),
            "description": item_data.get("description")
        }


# 使用示例
if __name__ == "__main__":
    app_id = "YOUR_APPID"
    app_secret = "YOUR_APPSECRET"
    api = WeidianAPI(app_id, app_secret)
    
    # 搜索商品
    search_result = api.search_items("手機")
    if search_result.get("code") == 0 and search_result.get("data"):
        items = search_result["data"].get("items", [])
        print(f"找到 {len(items)} 個商品")
        
        if items:
            # 獲取第一個商品詳情
            first_item = items[0]
            item_id = first_item["item_id"]
            detail = api.get_item_detail(item_id)
            
            if detail.get("code") == 0 and detail.get("data"):
                parsed_item = api.parse_item_data(detail["data"])
                print(f"商品標題: {parsed_item['title']}")
                print(f"價格: {parsed_item['price']}")
                print(f"銷量: {parsed_item['sales']}")


三、數(shù)據(jù)結(jié)構(gòu)與解析

1. 商品詳情數(shù)據(jù)結(jié)構(gòu)


{
    "code": 0,
    "message": "success",
    "data": {
        "item_id": "123456789",
        "title": "2023新款智能手機",
        "price": 2999.00,
        "original_price": 3299.00,
        "stock": 100,
        "sales": 567,
        "main_image": "https://img.weidian.com/item/123456.jpg",
        "detail_images": [
            "https://img.weidian.com/detail/123456_1.jpg",
            "https://img.weidian.com/detail/123456_2.jpg"
        ],
        "category_id": 1001,
        "description": "這款手機擁有...",
        "properties": [
            {"name": "顏色", "value": "黑色,白色,藍色"},
            {"name": "內(nèi)存", "value": "8GB+128GB,8GB+256GB"}
        ]
    }
}


2. 關(guān)鍵字搜索響應(yīng)

{
    "code": 0,
    "message": "success",
    "data": {
        "total": 1234,
        "page": 1,
        "page_size": 20,
        "items": [
            {
                "item_id": "123456789",
                "title": "2023新款智能手機",
                "price": 2999.00,
                "main_image": "https://img.weidian.com/item/123456.jpg",
                "sales": 567,
                "shop_id": "987654",
                "shop_name": "科技數(shù)碼專營店"
            },
            // 更多商品...
        ]
    }
}


四、高效搜索與數(shù)據(jù)處理

1. 分頁處理

def search_all_items(keyword):
    """搜索所有匹配的商品(處理分頁)"""
    all_items = []
    page = 1
    
    while True:
        result = api.search_items(keyword, page=page)
        if result.get("code") != 0 or not result.get("data"):
            break
        
        items = result["data"].get("items", [])
        if not items:
            break
        
        all_items.extend(items)
        
        # 判斷是否還有下一頁
        total = result["data"].get("total", 0)
        page_size = result["data"].get("page_size", 20)
        if page * page_size >= total:
            break
        
        page += 1
    
    return all_items


2. 并發(fā)請求優(yōu)化


from concurrent.futures import ThreadPoolExecutor

def batch_get_item_details(item_ids):
    """批量獲取商品詳情(并發(fā)優(yōu)化)"""
    with ThreadPoolExecutor(max_workers=10) as executor:
        results = list(executor.map(api.get_item_detail, item_ids))
    return results


五、數(shù)據(jù)存儲與應(yīng)用

1. 數(shù)據(jù)庫設(shè)計

-- 微店商品表
CREATE TABLE `weidian_items` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `item_id` varchar(32) NOT NULL COMMENT '微店商品ID',
  `title` varchar(255) NOT NULL COMMENT '商品標題',
  `price` decimal(10,2) NOT NULL COMMENT '價格',
  `original_price` decimal(10,2) DEFAULT NULL COMMENT '原價',
  `stock` int(11) DEFAULT 0 COMMENT '庫存',
  `sales` int(11) DEFAULT 0 COMMENT '銷量',
  `main_image` varchar(255) DEFAULT NULL COMMENT '主圖URL',
  `category_id` int(11) DEFAULT NULL COMMENT '分類ID',
  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_item_id` (`item_id`)
);

-- 商品詳情圖表
CREATE TABLE `weidian_item_images` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `item_id` varchar(32) NOT NULL COMMENT '關(guān)聯(lián)商品ID',
  `image_url` varchar(255) NOT NULL COMMENT '圖片URL',
  `type` tinyint(1) DEFAULT 0 COMMENT '0=詳情圖,1=主圖',
  PRIMARY KEY (`id`),
  KEY `idx_item_id` (`item_id`)
);


2. 數(shù)據(jù)分析應(yīng)用

  • 價格監(jiān)控:記錄商品歷史價格,生成價格波動圖
  • 銷量分析:分析關(guān)鍵詞搜索結(jié)果的銷量分布
  • 競品對比:對比同類型商品的價格、銷量和評價
  • 關(guān)鍵詞優(yōu)化:分析熱門搜索詞,優(yōu)化商品標題和描述


請登錄后查看

鍵盤上的螞蟻 最后編輯于2025-05-29 14:25:29

快捷回復(fù)
回復(fù)
回復(fù)
回復(fù)({{post_count}}) {{!is_user ? '我的回復(fù)' :'全部回復(fù)'}}
排序 默認正序 回復(fù)倒序 點贊倒序

{{item.user_info.nickname ? item.user_info.nickname : item.user_name}} LV.{{ item.user_info.bbs_level }}

作者 管理員 企業(yè)

{{item.floor}}# 同步到gitee 已同步到gitee {{item.is_suggest == 1? '取消推薦': '推薦'}}
{{item.is_suggest == 1? '取消推薦': '推薦'}}
沙發(fā) 板凳 地板 {{item.floor}}#
{{item.user_info.title || '暫無簡介'}}
附件

{{itemf.name}}

{{item.created_at}}  {{item.ip_address}}
打賞
已打賞¥{{item.reward_price}}
{{item.like_count}}
{{item.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)

{{itemc.user_info.nickname}}

{{itemc.user_name}}

回復(fù) {{itemc.comment_user_info.nickname}}

附件

{{itemf.name}}

{{itemc.created_at}}
打賞
已打賞¥{{itemc.reward_price}}
{{itemc.like_count}}
{{itemc.showReply ? '取消回復(fù)' : '回復(fù)'}}
刪除
回復(fù)
回復(fù)
查看更多
打賞
已打賞¥{{reward_price}}
183
{{like_count}}
{{collect_count}}
添加回復(fù) ({{post_count}})

相關(guān)推薦

快速安全登錄

使用微信掃碼登錄
{{item.label}} 加精
{{item.label}} {{item.label}} 板塊推薦 常見問題 產(chǎn)品動態(tài) 精選推薦 首頁頭條 首頁動態(tài) 首頁推薦
取 消 確 定
回復(fù)
回復(fù)
問題:
問題自動獲取的帖子內(nèi)容,不準確時需要手動修改. [獲取答案]
答案:
提交
bug 需求 取 消 確 定
打賞金額
當前余額:¥{{rewardUserInfo.reward_price}}
{{item.price}}元
請輸入 0.1-{{reward_max_price}} 范圍內(nèi)的數(shù)值
打賞成功
¥{{price}}
完成 確認打賞

微信登錄/注冊

切換手機號登錄

{{ bind_phone ? '綁定手機' : '手機登錄'}}

{{codeText}}
切換微信登錄/注冊
暫不綁定
CRMEB客服

CRMEB咨詢熱線 咨詢熱線

400-8888-794

微信掃碼咨詢

CRMEB開源商城下載 源碼下載 CRMEB幫助文檔 幫助文檔
返回頂部 返回頂部
CRMEB客服