python实现拼多多商品详情接口API

最近工作需要用到拼多多的一些接口,官方竟然没有提供,python的sdk,于是就自己简单的写了一个商品SKU接口的api。

1、代码

#!/usr/bin/python3# -*- coding: utf-8 -*-# @Time    : 2020/3/29 0021 下午 19:40# @Author  : xiaozhi!# @FileName: pdd_api# @Software: PyCharmimport timeimport hashlibimport requestsfrom urllib.parse import urlencode
class PddApi:    host = "https://gw-api.pinduoduo.com/api/router?"    headers = {        "accept": "application/json"    }
    def __init__(self, id=None, token=None, secret=None):        """        初始化        """        self.client_id = id        self.secret = secret        self.access_token = token        self.data_type = "JSON"
    def sign_md5(self, params):        """        对拼接好的字符串进行md5签名        """        hl = hashlib.md5()        hl.update(params.encode(encoding='utf-8'))        return hl.hexdigest().upper()
    def splice_str(self):        """        升序排序请求参数,连接字符串,并在首尾加上client_secret        """        self.timestamp = f"{time.time()}".split(".")[0]        pdd_dict = self.__dict__.copy()        secret = self.secret        del pdd_dict["secret"]        reverse_list = sorted([(k, str(v)) for k, v in pdd_dict.items()], key=lambda x:x[0])        reverse_list.insert(0, ("", secret))        reverse_list.append(("", secret))        reverse_list_str = list(map(lambda x: "".join(x), reverse_list))        params = "".join(reverse_list_str)        return params, pdd_dict
    def urlencode_data(self, params, pdd_dict):        pdd_dict["sign"] = self.sign_md5(params)        result = urlencode(pdd_dict)        url = f"{self.host}{result}"        return url
    def pdd_order_list_get(self, **kwargs):        """        获取订单列表        kwargs: order_status=None, refund_status=None, start_confirm_at=None, end_confirm_at=None,                           page=None, page_size=None        """        res_type = "pdd.order.list.get"        self.type = res_type        for k, v in kwargs.items():            setattr(self, k, v)        params, pdd_dict = self.splice_str()
        url = self.urlencode_data(params, pdd_dict)        return self.response_json(url=url)
    def pdd_order_information_get(self, order_sn=None):        """        获取订单详情        """        res_type = "pdd.order.information.get"        self.order_sn = order_sn        self.type = res_type        params, pdd_dict = self.splice_str()        url = self.urlencode_data(params, pdd_dict)        return self.response_json(url=url)
    def pdd_order_status_get(self, order_sns=None):        """        订单状态        """        res_type = "pdd.order.status.get"        self.order_sns = order_sns        self.type = res_type        params, pdd_dict = self.splice_str()        url = self.urlencode_data(params, pdd_dict)        return self.response_json(url=url)
    def pdd_erp_order_sync(self, **kwargs):        """        erp打单信息同步,        kwargs: order_sn=None, order_state=None, waybill_no=None, logistics_id=None        """        res_type = "pdd.erp.order.sync"        self.type = res_type        for k, v in kwargs.items():            setattr(self, k, v)        params, pdd_dict = self.splice_str()        url = self.urlencode_data(params, pdd_dict)        return self.response_json(url=url)
    def pdd_order_number_list_increment_get(self, **kwargs):        """        订单增量接口        kwargs: is_lucky_flag=None, order_state=None, start_updated_at=None, end_updated_at=None,page_size=None,        page=None, refund_status=None        """        res_type = "pdd.order.number.list.increment.get"        self.type = res_type        for k, v in kwargs.items():            setattr(self, k, v)        params, pdd_dict = self.splice_str()        url = self.urlencode_data(params, pdd_dict)        return self.response_json(url=url)
    def response_json(self, url):        res = requests.post(url=url, headers=self.headers)        return res.json()

2、调用:

图片

3、结果:

图片

返回值

{"items": {"keyword": "女装","page": "1","real_total_results": 300,"total_results": 300,"list_count": 20,"item": [{"title": "【三件套】新款秋冬季女装套装裙皮草短外套搭打底衫毛衣配半身裙","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-06-05/b15035efb5913e1e8b647422010522c1.jpeg","price": 134,"promotion_price": 134,"sales": 18000,"num_iid": 43992967514,"sample_id": "","seller_nick": "果果家气质女装","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=43992967514"},{"title": "【2件套】套装秋冬新款仿獭兔毛钉珠皮草毛毛短外套加厚大衣女装","pic_url": "https://omsproductionimg.yangkeduo.com/images/2018-06-06/463c0e2a5580ba3266846e41fe3e444a.jpeg","price": 169,"promotion_price": 169,"sales": 40000,"num_iid": 1620002566,"sample_id": "","seller_nick": "果果家气质女装","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=1620002566"},{"title": "仿水貂毛皮草外套女冬短款韩版修身显瘦百搭毛绒加厚新娘披肩礼服","pic_url": "https://omsproductionimg.yangkeduo.com/images/2018-01-03/1f3866498a067e00e39a38fe144ec5f3.jpeg","price": 88,"promotion_price": 88,"sales": 218,"num_iid": 410684172,"sample_id": "","seller_nick": "乐荣源淘衣坊","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=410684172"},{"title": "仿貂毛大衣女秋冬加厚仿狐狸毛领皮草外套女长款仿水貂绒外套显瘦","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-06-28/f6ea981d0cfe5dc096af33457328c819.jpeg","price": 298,"promotion_price": 298,"sales": 42000,"num_iid": 144592781204,"sample_id": "","seller_nick": "珞摩服装旗舰店","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=144592781204"},{"title": "三件套裙套装新款秋冬女韩版钉珠皮草短外套搭打底衫毛衣配半身裙","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-09-24/1fd6806d8de95adce0196294765079f1.jpeg","price": 269,"promotion_price": 269,"sales": 2525,"num_iid": 2748395485,"sample_id": "","seller_nick": "蹦蹦服饰","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=2748395485"},{"title": "三件套2020新款秋冬季皮草裙套装女短外套搭打底衫毛衣配半身裙子","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-10-22/97440d8034ad1a319e71cd501aa6d9bc.jpeg","price": 239,"promotion_price": 239,"sales": 119,"num_iid": 4544773413,"sample_id": "","seller_nick": "自然之美服饰","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=4544773413"},{"title": "三件套裙套装2020新款秋冬季皮草女短外套搭打底衫毛衣配半身裙子","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-10-23/0e5aa1adb63ce256664d4274d0ff0fa1.jpeg","price": 188,"promotion_price": 188,"sales": 1587,"num_iid": 3540607180,"sample_id": "","seller_nick": "自然之美服饰","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=3540607180"},{"title": "2020秋冬装毛毛钉珠仿皮草外套新款韩版修身圆领学生上衣【单件】","pic_url": "https://t00img.yangkeduo.com/goods/images/2021-01-28/503c10fe716873ceaccf103c30881908.jpeg","price": 79,"promotion_price": 79,"sales": 1157,"num_iid": 35225305026,"sample_id": "","seller_nick": "夏衣伊人","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=35225305026"},{"title": "两件套秋冬新款气质钉珠仿皮草外套配刺绣半身裙保暖加厚上衣女装","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-09-17/5d57e2f0df37b13f5472d03175246d28.jpeg","price": 139,"promotion_price": 139,"sales": 2616,"num_iid": 369492636,"sample_id": "","seller_nick": "蹦蹦服饰","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=369492636"},{"title": "2020秋冬装毛毛钉珠仿皮草外套新款韩版修身圆领淑女上衣【单件】","pic_url": "https://t00img.yangkeduo.com/goods/images/2021-01-28/b208cc827f66c0b5eac9d40762178d28.jpeg","price": 88,"promotion_price": 88,"sales": 232,"num_iid": 3540686169,"sample_id": "","seller_nick": "自然之美服饰","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=3540686169"},{"title": "2018秋冬装毛毛钉珠仿皮草外套新款韩版修身圆领学生上衣【单件】","pic_url": "https://t00img.yangkeduo.com/goods/images/2018-09-24/22c7a21f49c4ddfe228acc5d15c1bbe0.jpeg","price": 138,"promotion_price": 138,"sales": 210,"num_iid": 3062555797,"sample_id": "","seller_nick": "果果家气质女装","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=3062555797"},{"title": "三件套网红裙套装新款秋冬女钉珠皮草搭打底衫毛衣配半身裙短外套","pic_url": "https://t00img.yangkeduo.com/goods/images/images/2019-09-10/403fae6f0c281b247e305559cff71cca.jpeg","price": 269,"promotion_price": 269,"sales": 144,"num_iid": 35224334938,"sample_id": "","seller_nick": "夏衣伊人","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=35224334938"},{"title": "单件外套短款女秋冬新品海宁仿皮草韩版宽松显瘦百搭钉珠圆领上衣","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-09-24/55a25e3b612a5ba2655046718a20c0ab.jpeg","price": 88,"promotion_price": 88,"sales": 2314,"num_iid": 368488818,"sample_id": "","seller_nick": "蹦蹦服饰","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=368488818"},{"title": "粗花呢套装女2020秋冬新款小香风时尚洋气小西装包臀裙休身显瘦潮","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-07-16/84ffe1375b1d3b1a6455b9c387cd495b.jpeg","price": 139,"promotion_price": 139,"sales": 216,"num_iid": 150435444702,"sample_id": "","seller_nick": "小清新职装","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=150435444702"},{"title": "啄木鸟加厚羽绒棉衣女冬季新款胖mm宽松显瘦棉服外套女士大码棉袄","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-11-24/a8798a380a8e64503a3b6f2df3cdc5e6.jpeg","price": 148,"promotion_price": 148,"sales": 2866,"num_iid": 203004819547,"sample_id": "","seller_nick": "啄木鸟清晚田专卖店","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=203004819547"},{"title": "小香风套装裙女秋冬两件套裙子时尚气质贵夫人高档显瘦小西服上衣","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-09-20/11b73b78660ce240318981f36fedb20b.jpeg","price": 106.8,"promotion_price": 106.8,"sales": 3585,"num_iid": 179099550022,"sample_id": "","seller_nick": "蝶之语服饰","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=179099550022"},{"title": "粉色小西装春季新款名媛小香风套装裙两件套韩版时尚百搭收腰显瘦","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-03-17/2c08521a36bae37e004a5cfe15fcddb1.jpeg","price": 119,"promotion_price": 119,"sales": 136,"num_iid": 94383041769,"sample_id": "","seller_nick": "小清新职装","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=94383041769"},{"title": "小清新刺绣两件套套装裙兔毛领拼接短外套毛呢连衣裙秋冬甜美新款","pic_url": "https://t00img.yangkeduo.com/goods/images/2019-10-07/6f734d1717a3339a74cff707d9ec82c0.jpeg","price": 688,"promotion_price": 688,"sales": 3602,"num_iid": 50964999845,"sample_id": "","seller_nick": "木木时尚服饰","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=50964999845"},{"title": "毛呢两件套装裙子女2021春秋季新款中长连衣裙修身妈妈装短款外套","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-03-12/d9b47beb0f7306f132216c910640f830.jpeg","price": 89.8,"promotion_price": 89.8,"sales": 32000,"num_iid": 2713732007,"sample_id": "","seller_nick": "露雪颜旗舰店","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=2713732007"},{"title": "白鸭绒2020冬季新款网红苏苏羽绒服女中长款大毛领收腰加厚外套潮","pic_url": "https://t00img.yangkeduo.com/goods/images/2020-12-13/735fb9bd599594a424f3f22957aafd06.jpeg","price": 299,"promotion_price": 299,"sales": 3292,"num_iid": 45642569064,"sample_id": "","seller_nick": "晗晗羽绒厂家店","post_fee": "","area": "","detail_url": "http://yangkeduo.com/goods.html?goods_id=45642569064"}]},

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/5141.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

「深度学习之优化算法」(十六)万有引力算法

1. 万有引力算法简介 (以下描述,均不是学术用语,仅供大家快乐的阅读) 万有引力算法(Gravitational Search Algorithm)是受物体之间的万有引力启发而提出的算法。算法提出于2008(2009)年,时间不长,不过相关的文章和应用已经相对较多,也有不少的优化改进方案。   万…

apple pencil二代平替笔哪个好用?苹果平板平替笔排行

光是一款Apple Pencil,就卖到了接近一千多块,信息对于很多人来说都觉得太贵了。事实上,由于平替电容笔的性价比也非常高,因此它还是值得一试的。不管是学习,写作,还是绘画,这支平替电容笔&#…

自洽性改善语言模型中的思维链推理7.13、7.14

自洽性改善语言模型中的思维链推理 摘要介绍对多样化路径的自洽实验实验设置主要结果当CoT影响效率时候,SC会有所帮助与现有方法进行比较附加研究 相关工作总结 原文: 摘要 本篇论文提出了一种新的编码策略——自洽性,来替换思维链中使用的…

AI绘画 | 迷人武士美少女战士作品集

今天用Midjourney生成了质量极高的美少女武士后续会作为固定栏目来分享美图接下来请欣赏作品 提示词分享:1.an asian girl dressed in samurai style, in the style of anime aesthetic, trick of the eye paintings, dollcore, light red and black, resin, 8k, ex…

数据结构--图的基本操作

数据结构–图的基本操作 使用的存储模式&#xff1a; 图的基本操作&#xff1a; • Adjacent(G,x,y)&#xff1a;判断图G是否存在边<x, y>或(x, y)。 • Neighbors(G,x)&#xff1a;列出图G中与结点x邻接的边。 • InsertVertex(G,x)&#xff1a;在图G中插入顶点x。 • …

Apache HTTPD 多后缀解析漏洞

Apache HTTPD 多后缀解析漏洞 一、环境搭建二、漏洞原理三、漏洞复现 一、环境搭建 如下介绍kali搭建的教程 cd ~/vulhub/httpd/apache_parsing_vulnerability // 进入指定环境 docker-compose up -d // 启动环境docker-compose ps使用这条命令查看当前正在运行的环境 打开…

Java入门

目录 一、程序 什么是程序 二、计算机编程语言 1.计算机语言是什么 Java历史 特点 执行机制 计算机执行机制 Java的执行机制 三、JDK安装 名词解释 安装与校验 配置环境变量 四、第一个Java程序 编写代码 编译运行 规范 六、Java核心机制&#xff1a;JVM 1.…

【C语言】memcpy,memmove,memcmp,memset函数详解

memcpy,memmove,memcmp,memset函数详解 memcpy函数一、 memcpy函数的定义&#xff1a;二、memcpy函数的功能&#xff1a;三、memcpy函数模拟memcpy注意事项 memmove函数一、memmove函数简介二、memmove函数的模拟1.两种情况2模拟实现 memcmp函数memecmp函数介绍 memset函数mems…

数据结构(王道)——线性表的存储结构之双链表

双链表和单链表的对比 一、从无到有创建一个双链表及其基础操作 带头结点 的双链表 初始化 双链表的后插操作&#xff1a; 从后插可以拓展到按位序插入&#xff0c;和前插操作。 因为双链表的特性&#xff0c;如果按位序插入或者前插操作&#xff0c;只需要找到插入的位置的前…

基于SpringBoot + EasyExcel + Vue + Blob实现导出Excel文件的前后端完整过程

首先前端发起HTTP请求之后&#xff0c;后端返回一个Excel输出流&#xff0c;然后前端用Blob类型接收数据&#xff0c;并且解析响应头数据以及提取源文件名&#xff0c;最后用a标签完成下载。 一、后端代码 &#xff08;1&#xff09;导入阿里巴巴的EasyExcel依赖&#xff08;…

Type-C PD显示器方案简介

方案概述 LDR6020 Type-C PD显示器方案可以给显示器提供一个全功能C口&#xff0c;支持手机&#xff0c;电脑&#xff0c;游戏主机等一线投屏功能&#xff0c;同时支持PD快充输出。LDR6020内置了 USB Power Delivery 控制器和 PD BMC PHY 收发器&#xff0c;支持PD2.0/3.0等快充…

Low-Light Image Enhancement via Self-Reinforced Retinex Projection Model 论文阅读笔记

这是马龙博士2022年在TMM期刊发表的基于改进的retinex方法去做暗图增强&#xff08;非深度学习&#xff09;的一篇论文 文章用一张图展示了其动机&#xff0c;第一行是估计的亮度层&#xff0c;第二列是通常的retinex方法会对估计的亮度层进行RTV约束优化&#xff0c;从而产生…

ceph----应用

文章目录 一、创建 CephFS 文件系统 MDS 接口1.1 服务端操作1.2 客户端操作 二、创建 Ceph 块存储系统 RBD 接口三、OSD 故障模拟与恢复四、创建 Ceph 对象存储系统 RGW 接口 一、创建 CephFS 文件系统 MDS 接口 1.1 服务端操作 1&#xff09;在管理节点创建 mds 服务 cd /et…

Unity游戏源码分享-Third Person Controller - Shooter Template v1.3.1

Unity游戏源码分享-Third Person Controller - Shooter Template v1.3.1 功能非常齐全 AI格斗 2.5D 完整工程地址&#xff1a;https://download.csdn.net/download/Highning0007/88057824

node自主学习——fs文件操作模块

目录 读文件 读文件是否成功的判定 写文件 写文件是否成功的判定 备注&#xff1a;VsCode、node v18.17.0 读文件 fs.readFile(文件路径, 编码格式&#xff08;可选&#xff09;, 回调函数)// 回调函数可以打印失败和成功的结果 // 若成功&#xff0c;err的值为null // 若…

Spring【AOP】

AOP-面向切面编程 AOP&#xff1a;面向切面编程&#xff0c;通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。 SpringAop中&#xff0c;通过Advice定义横切逻辑&#xff0c;并支持5种类型的Advice&#xff1a; 导入依赖 <dependency><groupId>…

前端JavaScript入门-day06

(创作不易&#xff0c;感谢有你&#xff0c;你的支持&#xff0c;就是我前行的最大动力&#xff0c;如果看完对你有帮助&#xff0c;请留下您的足迹&#xff09; 目录 作用域 局部作用域 全局作用域 作用域链 JS垃圾回收机制 1. 什么是垃圾回收机制 2.内存的生命周…

缕析条分Scroll属性 | 京东云技术团队

最近有项目需要使用js原生开发滑动组件&#xff0c;频繁要用到dom元素的各种属性&#xff0c;其中以各种类型的height和top属性居多&#xff0c;名字相近&#xff0c;含义也很容易搞混。因此特地总结归纳了一下常用的知识点&#xff0c;在文末我们来挑战实现一个简易的移动端Sc…

行为型模式 - 责任链模式

概述 在现实生活中&#xff0c;常常会出现这样的事例&#xff1a;一个请求有多个对象可以处理&#xff0c;但每个对象的处理条件或权限不同。例如&#xff0c;公司员工请假&#xff0c;可批假的领导有部门负责人、副总经理、总经理等&#xff0c;但每个领导能批准的天数不同&a…

无参数读文件和RCE总结

什么是无参数&#xff1f; 顾名思义&#xff0c;就是只使用函数&#xff0c;且函数不能带有参数&#xff0c;这里有种种限制&#xff1a;比如我们选择的函数必须能接受其括号内函数的返回值&#xff1b;使用的函数规定必须参数为空或者为一个参数等 接下来&#xff0c;从代码…