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

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

用 Python 獨(dú)立商城接入拼多多 API 的 SDK 模板,

管理 管理 編輯 刪除

好的,我?guī)湍銓懸粋€(gè) 完整的 Python SDK 模板,可以直接用在你的獨(dú)立商城后臺(tái),支持拼多多商品同步、商品詳情、訂單查詢和推廣鏈接獲取。

這個(gè) SDK 封裝了簽名、請(qǐng)求、返回解析等常用功能,方便直接調(diào)用。

拼多多 Python SDK 模板

import hashlib
import time
import requests
import json


class PinduoduoSDK:
    """
    拼多多開放平臺(tái) Python SDK
    功能:
    - 商品搜索
    - 商品詳情
    - 訂單查詢
    - 推廣鏈接獲?。ǘ喽嗫?API)
    """

    def __init__(self, client_id: str, client_secret: str, access_token: str = None):
        """
        初始化 SDK
        :param client_id: 拼多多應(yīng)用 Client ID
        :param client_secret: 拼多多應(yīng)用 Client Secret
        :param access_token: 已授權(quán)用戶 Access Token(部分接口需要)
        """
        self.client_id = client_id
        self.client_secret = client_secret
        self.access_token = access_token
        self.gateway_url = "https://gw-api.pinduoduo.com/api/router"

    def _sign(self, params: dict) -> str:
        """
        拼多多接口簽名
        規(guī)則:
        1. 參數(shù)按字母升序排序
        2. 拼接 key=value 字符串
        3. 前后加 client_secret
        4. MD5 后大寫
        """
        sorted_items = sorted(params.items())
        query = self.client_secret + ''.join(f"{k}{v}" for k, v in sorted_items) + self.client_secret
        return hashlib.md5(query.encode('utf-8')).hexdigest().upper()

    def _post(self, data: dict):
        """
        發(fā)送 POST 請(qǐng)求
        """
        data["client_id"] = self.client_id
        data["timestamp"] = str(int(time.time()))
        data["data_type"] = "JSON"

        if self.access_token:
            data["access_token"] = self.access_token

        # 生成簽名
        data["sign"] = self._sign(data)

        # 發(fā)送請(qǐng)求
        resp = requests.post(self.gateway_url, data=data, timeout=10)
        try:
            return resp.json()
        except json.JSONDecodeError:
            return {"error": "Invalid JSON response", "text": resp.text}

    # =======================
    # 商品搜索
    # =======================
    def search_goods(self, keyword: str, page: int = 1, page_size: int = 20):
        """
        搜索商品
        :param keyword: 搜索關(guān)鍵詞
        :param page: 頁碼
        :param page_size: 每頁數(shù)量
        """
        data = {
            "type": "pdd.goods.search",
            "page": page,
            "page_size": page_size,
            "keyword": keyword
        }
        return self._post(data)

    # =======================
    # 商品詳情
    # =======================
    def goods_detail(self, goods_id: int):
        """
        獲取商品詳情
        :param goods_id: 拼多多商品ID
        """
        data = {
            "type": "pdd.goods.detail",
            "goods_id_list": json.dumps([goods_id])
        }
        return self._post(data)

    # =======================
    # 訂單查詢
    # =======================
    def order_list(self, start_update_time: int, end_update_time: int, page: int = 1, page_size: int = 20):
        """
        查詢訂單
        :param start_update_time: 開始更新時(shí)間(時(shí)間戳)
        :param end_update_time: 結(jié)束更新時(shí)間(時(shí)間戳)
        """
        data = {
            "type": "pdd.order.list.get",
            "page": page,
            "page_size": page_size,
            "start_update_time": start_update_time,
            "end_update_time": end_update_time
        }
        return self._post(data)

    # =======================
    # 多多客商品搜索
    # =======================
    def ddk_goods_search(self, keyword: str, page: int = 1, page_size: int = 20):
        """
        多多客商品搜索(推廣接口)
        :param keyword: 搜索關(guān)鍵詞
        """
        data = {
            "type": "pdd.ddk.goods.search",
            "keyword": keyword,
            "page": page,
            "page_size": page_size
        }
        return self._post(data)


# =======================
# 示例用法
# =======================
if __name__ == "__main__":
    CLIENT_ID = "你的ClientID"
    CLIENT_SECRET = "你的ClientSecret"
    ACCESS_TOKEN = "可選用戶授權(quán)token"

    sdk = PinduoduoSDK(CLIENT_ID, CLIENT_SECRET, ACCESS_TOKEN)

    # 商品搜索
    search_result = sdk.search_goods(keyword="藍(lán)牙耳機(jī)", page=1, page_size=5)
    print("搜索結(jié)果:")
    print(json.dumps(search_result, indent=2, ensure_ascii=False))

    # 商品詳情
    if "goods_list" in search_result.get("goods_search_response", {}):
        goods_id = search_result["goods_search_response"]["goods_list"][0]["goods_id"]
        detail = sdk.goods_detail(goods_id=goods_id)
        print("\n商品詳情:")
        print(json.dumps(detail, indent=2, ensure_ascii=False))

    # 多多客搜索
    ddk_result = sdk.ddk_goods_search(keyword="藍(lán)牙耳機(jī)")
    print("\n多多客商品搜索:")
    print(json.dumps(ddk_result, indent=2, ensure_ascii=False))


? SDK 特性

  1. 自動(dòng)生成簽名,無需手動(dòng)拼接
  2. 支持拼多多開放平臺(tái)主要接口
  3. 可直接集成到獨(dú)立商城后臺(tái)
  4. 支持 商品同步、詳情、訂單查詢、推廣搜索
  5. 返回結(jié)果 JSON 可直接存庫或前端渲染


請(qǐng)登錄后查看

小碼二開 最后編輯于2025-10-06 10:39:10

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

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

作者 管理員 企業(yè)

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

{{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}}
179
{{like_count}}
{{collect_count}}
添加回復(fù) ({{post_count}})

相關(guān)推薦

快速安全登錄

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

微信登錄/注冊(cè)

切換手機(jī)號(hào)登錄

{{ bind_phone ? '綁定手機(jī)' : '手機(jī)登錄'}}

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

CRMEB咨詢熱線 咨詢熱線

400-8888-794

微信掃碼咨詢

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