拼多多商品详情接口(封装代码)

Posted Noah-1723045498

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了拼多多商品详情接口(封装代码)相关的知识,希望对你有一定的参考价值。

一、使用拼多多商品接口可以获取拼多多商品详情。

下面是获取商品详情的基本步骤和代码详解。

1. 注册账号并创建应用,获取 API 访问权限和密钥

2. 根据 API 文档了解所需的参数和返回结果,构造请求参数和签名。其中,需要特别注意的是签名的生成方法,必须按照规定的方法进行,否则会导致请求失败或数据错误。

3. 通过 HTTP GET 请求访问拼多多商品详情接口并获取响应结果。需要注意 HTTP 请求的超时时间和异常处理。

4. 处理 JSON 格式的响应结果,并从中提取出需要的商品数据字段信息。

	"item": 
		"num_iid": 1620002566,
		"title": "【2件套】套装秋冬新款仿獭兔毛钉珠皮草毛毛短外套加厚大衣女装",
		"price": 95.4,
		"minGroupPrice": 95.4,
		"maxGroupPrice": 95.4,
		"total_price": "",
		"desc_short": "【2件套】套装秋冬新款仿獭兔毛钉珠皮草毛毛短外套加厚大衣女装",
		"cid": 8484,
		"orginal_price": 1.15,
		"nick": "果果家气质女装",
		"num": 1000,
		"sales": 43000,
		"detail_url": "https://mobile.yangkeduo.com/goods1.html?goods_id=1620002566",
		"desc": "<img src=\\"https://img.pddpic.com/mms-material-img/2022-09-18/3f89d470-1af8-4dee-b529-6d62aa2ea3b7.png\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2019-02-15/ddf6fe7b-b536-4183-932d-69a1189a3f59.png\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/20f659b04d3e7e5851c27ff9931c96fc.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2019-11-14/4420a8c3-49ed-46d8-ab55-15e7a638ca31.jpg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/26c3e9d5cfbaf4e8f13b2bdd38f48d71.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/0aa872fa74599dad7b6aefe6b6c035c0.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/6bc959e32a30424c7a5284a37676999c.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/1fa9861a8c99c5e9e8119fd2239fef5a.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/b62cabf1d2320c5761e3f4c15203fb20.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/6f6e54376a66cbc78e16700d4c424fe1.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/2f60753dfc875a6876adc35833a69d31.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/ae0116e589d8de712f8dafd0c356cefe.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/da910c98fcc8de1b4d2d1498cd7899fd.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/140349649d8b7d08c8e88bfbbaa2f900.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/a953bae2eeb7364ef3ef2976a97d07eb.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/4da59828136c3b1308aad0aa990778a7.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-09-02/4a365b61a80e47288c8609ccd5982396.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-11-17/cd0a8a96b783a51236812ce24c59a329.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-11-17/16008ac19768d05e7dee16406ff958a1.jpeg\\"/><img src=\\"https://t00img.yangkeduo.com/goods/images/2018-11-17/ef1d17b69ebf9449a8bb52459b168c26.jpeg\\"/><img src=\\"https://www.o0b.cn/i.php?t.png&rid=gw-4.64759b7c06ab4&p=1778787051&k=i_key&t=1685429122\\" style=\\"display:none\\" />",
		"item_imgs": [
			
				"url": "https://omsproductionimg.yangkeduo.com/images/2017-12-12/bcf848aa71c6389607ae7a84b70f1543.jpeg"
			,
			
				"url": "https://omsproductionimg.yangkeduo.com/images/2017-12-12/176019babfdecffa1d9f98f40b7e99b4.jpeg"
			,
			
				"url": "https://omsproductionimg.yangkeduo.com/images/2017-12-12/efb5db42397550bffd3211ca6f197498.jpeg"
			,
			
				"url": "https://omsproductionimg.yangkeduo.com/images/2017-12-12/d209ef7bcc9183c3bb8ca1dfdb108d49.jpeg"
			,
			
				"url": "https://omsproductionimg.yangkeduo.com/images/2017-12-12/74257ab65f3f00da7a90fde9042fe640.jpeg"
			,
			
				"url": "https://img.pddpic.com/goods/images/2019-08-17/e8fbd9cb-cc74-4caa-9380-84c46d27b008.jpg"
			,
			
				"url": "https://img.pddpic.com/goods/images/2019-08-17/d76f515b-e375-4060-b94e-cf64f6b0964e.jpg"
			,
			
				"url": "https://img.pddpic.com/goods/images/2019-08-17/f2f279b5-6000-4fbe-b99b-7c1cbd7884ea.jpg"
			
		],
		"pic_url": "https://omsproductionimg.yangkeduo.com/images/2018-06-06/463c0e2a5580ba3266846e41fe3e444a.jpeg",
		"props_name": "1215:1115500378:颜色:粉色两件套(外套+裙子);1215:1115501666:颜色:米色两件套(外套+裙子);1215:105309781:颜色:蓝色两件套(外套+裙子);1226:119128:尺码:S(90斤以下);1226:96784:尺码:M(90-100斤);1226:33651:尺码:L(100-110斤);1226:33652:尺码:XL(110-120斤);1226:33653:尺码:2XL(120-130斤);1226:33656:尺码:3XL(130-140斤);",
		"prop_imgs": 
			"prop_img": [
				
					"properties": "1215:1115500378",
					"url": "https://t00img.yangkeduo.com/goods/images/2018-08-28/062d42b525a7c786920cbb83ac772af7.jpeg"
				,
				
					"properties": "1215:1115501666",
					"url": "https://t00img.yangkeduo.com/goods/images/2018-08-28/415bed99d5a925123d7b7c39547205de.jpeg"
				,
				
					"properties": "1215:105309781",
					"url": "https://t00img.yangkeduo.com/goods/images/2018-11-17/48b30664f0f7e526ab1b956e813f25cf.jpeg"
				
			]
		,
		"props": [
			
				"name": "面料材质",
				"value": "仿皮草"
			,
			
				"name": "成分含量",
				"value": "71%(含)—80%(含)"
			,
			
				"name": "版型",
				"value": "修身"
			,
			
				"name": "领型",
				"value": "圆领"
			,
			
				"name": "衣长",
				"value": "短款"
			,
			
				"name": "是否带毛领",
				"value": "不带毛领"
			,
			
				"name": "主风格",
				"value": "气质名媛"
			
		],
		"skus": 
			"sku": [
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115500378;1226:119128",
					"properties_name": "1215:1115500378:颜色:粉色两件套(外套+裙子);1226:119128:尺码:S(90斤以下)",
					"quantity": 108,
					"sku_id": 57114357891
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115500378;1226:96784",
					"properties_name": "1215:1115500378:颜色:粉色两件套(外套+裙子);1226:96784:尺码:M(90-100斤)",
					"quantity": 38,
					"sku_id": 57114357892
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115500378;1226:33651",
					"properties_name": "1215:1115500378:颜色:粉色两件套(外套+裙子);1226:33651:尺码:L(100-110斤)",
					"quantity": 59,
					"sku_id": 57114357893
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115500378;1226:33652",
					"properties_name": "1215:1115500378:颜色:粉色两件套(外套+裙子);1226:33652:尺码:XL(110-120斤)",
					"quantity": 114,
					"sku_id": 57114357894
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115500378;1226:33653",
					"properties_name": "1215:1115500378:颜色:粉色两件套(外套+裙子);1226:33653:尺码:2XL(120-130斤)",
					"quantity": 200,
					"sku_id": 57114357895
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115500378;1226:33656",
					"properties_name": "1215:1115500378:颜色:粉色两件套(外套+裙子);1226:33656:尺码:3XL(130-140斤)",
					"quantity": 126,
					"sku_id": 57114357896
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115501666;1226:119128",
					"properties_name": "1215:1115501666:颜色:米色两件套(外套+裙子);1226:119128:尺码:S(90斤以下)",
					"quantity": 961,
					"sku_id": 57114357897
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115501666;1226:96784",
					"properties_name": "1215:1115501666:颜色:米色两件套(外套+裙子);1226:96784:尺码:M(90-100斤)",
					"quantity": 135,
					"sku_id": 57114357898
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115501666;1226:33651",
					"properties_name": "1215:1115501666:颜色:米色两件套(外套+裙子);1226:33651:尺码:L(100-110斤)",
					"quantity": 135,
					"sku_id": 57114357899
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115501666;1226:33652",
					"properties_name": "1215:1115501666:颜色:米色两件套(外套+裙子);1226:33652:尺码:XL(110-120斤)",
					"quantity": 578,
					"sku_id": 57114357900
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115501666;1226:33653",
					"properties_name": "1215:1115501666:颜色:米色两件套(外套+裙子);1226:33653:尺码:2XL(120-130斤)",
					"quantity": 124,
					"sku_id": 57114357901
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:1115501666;1226:33656",
					"properties_name": "1215:1115501666:颜色:米色两件套(外套+裙子);1226:33656:尺码:3XL(130-140斤)",
					"quantity": 249,
					"sku_id": 57114357902
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:105309781;1226:119128",
					"properties_name": "1215:105309781:颜色:蓝色两件套(外套+裙子);1226:119128:尺码:S(90斤以下)",
					"quantity": 556,
					"sku_id": 103851107855
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:105309781;1226:96784",
					"properties_name": "1215:105309781:颜色:蓝色两件套(外套+裙子);1226:96784:尺码:M(90-100斤)",
					"quantity": 514,
					"sku_id": 103851107856
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:105309781;1226:33651",
					"properties_name": "1215:105309781:颜色:蓝色两件套(外套+裙子);1226:33651:尺码:L(100-110斤)",
					"quantity": 843,
					"sku_id": 103851107857
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:105309781;1226:33652",
					"properties_name": "1215:105309781:颜色:蓝色两件套(外套+裙子);1226:33652:尺码:XL(110-120斤)",
					"quantity": 546,
					"sku_id": 103851107858
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:105309781;1226:33653",
					"properties_name": "1215:105309781:颜色:蓝色两件套(外套+裙子);1226:33653:尺码:2XL(120-130斤)",
					"quantity": 561,
					"sku_id": 103851107853
				,
				
					"price": 95.4,
					"orginal_price": 115,
					"properties": "1215:105309781;1226:33656",
					"properties_name": "1215:105309781:颜色:蓝色两件套(外套+裙子);1226:33656:尺码:3XL(130-140斤)",
					"quantity": 570,
					"sku_id": 103851107854
				
			]
		,
		"props_list": 
			"1215:1115500378": "颜色:粉色两件套(外套+裙子)",
			"1215:1115501666": "颜色:米色两件套(外套+裙子)",
			"1215:105309781": "颜色:蓝色两件套(外套+裙子)",
			"1226:119128": "尺码:S(90斤以下)",
			"1226:96784": "尺码:M(90-100斤)",
			"1226:33651": "尺码:L(100-110斤)",
			"1226:33652": "尺码:XL(110-120斤)",
			"1226:33653": "尺码:2XL(120-130斤)",
			"1226:33656": "尺码:3XL(130-140斤)"
		,
		"props_img": 
			"1215:1115500378": "https://t00img.yangkeduo.com/goods/images/2018-08-28/062d42b525a7c786920cbb83ac772af7.jpeg",
			"1215:1115501666": "https://t00img.yangkeduo.com/goods/images/2018-08-28/415bed99d5a925123d7b7c39547205de.jpeg",
			"1215:105309781": "https://t00img.yangkeduo.com/goods/images/2018-11-17/48b30664f0f7e526ab1b956e813f25cf.jpeg"
		,
		"property_alias": "",
		"_ddf": "xdl",
		"shop_id": 461742,
		"seller_info": 
			"nick": "果果家气质女装",
			"score": 4.42,
			"delivery_score": 4.42,
			"item_score": null,
			"shop_type": "",
			"user_num_id": 461742,
			"shop_name": "果果家气质女装",
			"zhuy": "https://mobile.yangkeduo.com/mall_page.html?mall_id=461742",
			"sid": 461742
		,
		"format_check": "ok",
		"desc_img": [
			"https://img.pddpic.com/mms-material-img/2022-09-18/3f89d470-1af8-4dee-b529-6d62aa2ea3b7.png",
			"https://t00img.yangkeduo.com/goods/images/2019-02-15/ddf6fe7b-b536-4183-932d-69a1189a3f59.png",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/20f659b04d3e7e5851c27ff9931c96fc.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2019-11-14/4420a8c3-49ed-46d8-ab55-15e7a638ca31.jpg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/26c3e9d5cfbaf4e8f13b2bdd38f48d71.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/0aa872fa74599dad7b6aefe6b6c035c0.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/6bc959e32a30424c7a5284a37676999c.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/1fa9861a8c99c5e9e8119fd2239fef5a.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/b62cabf1d2320c5761e3f4c15203fb20.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/6f6e54376a66cbc78e16700d4c424fe1.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/2f60753dfc875a6876adc35833a69d31.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/ae0116e589d8de712f8dafd0c356cefe.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/da910c98fcc8de1b4d2d1498cd7899fd.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/140349649d8b7d08c8e88bfbbaa2f900.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/a953bae2eeb7364ef3ef2976a97d07eb.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/4da59828136c3b1308aad0aa990778a7.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-09-02/4a365b61a80e47288c8609ccd5982396.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-11-17/cd0a8a96b783a51236812ce24c59a329.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-11-17/16008ac19768d05e7dee16406ff958a1.jpeg",
			"https://t00img.yangkeduo.com/goods/images/2018-11-17/ef1d17b69ebf9449a8bb52459b168c26.jpeg"
		],
		"shop_item": [],
		"relate_items": []
	,
	"error": "",
	"secache": "38dc3c822554ca397f00e5e9b681e8fb",
	"secache_time": 1685429122,
	"secache_date": "2023-05-30 14:45:22",
	"translate_status": "",
	"translate_time": 0,
	"language": 
		"default_lang": "cn",
		"current_lang": "cn"
	,
	"reason": "",
	"error_code": "0000",

  

获取到拼多多的商品数据之后,可以通过以下方式应用起来:

1. 数据分析和研究:对拼多多的商品数据进行分析,深入了解消费者需求和购物行为,为进一步优化产品策略提供参考和支持。

2. 商品竞争力分析:通过与所在行业同类别商品的价格、销量等指标进行比较,找出产品的优点和短板,了解市场竞争情况,为制定营销策略和产品调整提供依据。

3. 营销策略运营:根据分析结果,制定相应产品和营销策略,提高销售额。例如,针对销售较差的商品申请降价促销,或者在平台内外对有潜在用户群体的商品发起推广活动。

4. 产品推广:根据具体情况,可以将商品信息发布到自己的电商、社交媒体或其他在线平台上,增加商品曝光,吸引消费者购买。

需要注意的是,数据来源和获取和到数据的真实性以及有效性都是数据应用的前提,因此要确保所使用的API接口稳定性以及得到数据去除异常值等正确处理方法。同时,在数据分析和应用过程中也要遵守相关政策和法规,保障商家权益和个人隐私。

公众号搭建淘宝京东拼多多查券平台

双十一之前终于把淘宝客公众号搭建好了,虽然耗时不少,但还是蛮有成就感的,能不能赚钱就另外一回事了。

我这里用到了淘宝联盟api权限、拼多多平台接口api、京东申请比较麻烦就没有申请,所以京东使用了第三方免费接口,各联盟账号api权限申请我就不赘述了,有疑问的话可以在下面留言,或加我微信公众号“网购有券”联系我。

淘宝找券实现

原理:

  1. 通过用户手淘分享的商品信息,信息中包含商品关键字和链接,使用商品关键字通过淘宝 通用物料搜索API 接口查询一批商品;
  2. 然后通过分享信息中的淘宝链接http抓包方式获取淘宝商品item id;
  3. 然后通过item id在查询的一批商品中找到指定的商品优惠券、佣金等信息。
public static string GetTaobaoCoupon(RequestMessageText responseMessageText)
        {
            string itemInfo = responseMessageText.Content.Trim();

            string responeMessage = "";
            try
            {
                Match m_title = Regex.Match(itemInfo, @"【.*】");
                string temp = m_title.Value;
                if (!string.IsNullOrEmpty(temp))
                {
                    temp = temp.Substring(1, temp.Length - 2);
                }
                else
                {
                    return "";
                }

                if (temp.Contains("#手聚App"))
                {
                    int IndexofA = temp.IndexOf("宝贝不错:");
                    int IndexofB = temp.IndexOf("(分享自");
                    temp = temp.Substring(IndexofA + 5, IndexofB - IndexofA - 5);
                }

                string title = temp;

                //通过商品关键字查询商品
                ITopClient client = new DefaultTopClient(taobaoApiUrl,taobaoAppkey, taobaoSecret);
                TbkDgMaterialOptionalRequest req = new TbkDgMaterialOptionalRequest();
                req.AdzoneId = addzoneId;
                req.Platform = 2L;
                
                req.PageSize = 100L;
                req.Q = title;
           
                req.PageNo = 1L;
                TbkDgMaterialOptionalResponse rsp = client.Execute(req);

                if (rsp.ResultList.Count > 0)
                {
                    //获取淘宝短链接
                    Match m_url = Regex.Match(itemInfo, @"htt(p|ps)://([w-]+(.[w-]+)*/)*[w-]+(.[w-]+)*/?(?([w-.,@?^=%&:/~+#]*)+)?");

                    if (m_url.Value == "")
                    {
                        return responeMessage;
                    }
                    var s = HttpUtility.HttpGet(m_url.Value, "", "utf-8");

                    //Match am_url = Regex.Match(s, @"(?<=var url = ')(.*)(?=')");
                    //获取宝贝item id
                    Match m_item = Regex.Match(s, @"(?<=m.taobao.com/i)([0-9]*)");
                    string item_id = m_item.Value;

                    if (string.IsNullOrEmpty(item_id))
                    {
                        Match am_url = Regex.Match(s, @"(?<=var url = ')(.*)(?=')");
                        var htmlContent = HttpUtility.HttpGet(am_url.Value, "", "gbk");
                        Match re_m_item = Regex.Match(htmlContent, @"(?<=taobao.com/item.htm?id=)([0-9]*)");
                        item_id = re_m_item.Value;
                    }

                    if (string.IsNullOrEmpty(item_id))
                    {
                        //LogHelper.WriteLog(typeof(WechatController), "通过抓包方式未获取到宝贝item id");
                        var g = rsp.ResultList.Where(y => !string.IsNullOrEmpty(y.CouponId)).OrderByDescending(w => w.Volume).FirstOrDefault();
                        if (g == null)
                        {
                            responeMessage = ConfigurationManager.AppSettings["tbk_nocoupon_msg"].Replace("\n", "
").Replace("\ue231", "ue231");

                        }
                        else
                        {
                            var hongbao = (decimal.Parse(g.ZkFinalPrice) - decimal.Parse(Regex.Match(g.CouponInfo, "减" + @"(d+)").Groups[1].Value)) * decimal.Parse(g.CommissionRate) / 10000 * commission_rate;
                            
                            responeMessage = $"{g.Title}
【在售价】{g.ZkFinalPrice}元
【巻后价】{Math.Round(double.Parse(g.ZkFinalPrice) - double.Parse(Regex.Match(g.CouponInfo, "减" + @"(d+)").Groups[1].Value), 2)} 元
复制这条信息,打开「手机绹宝」领巻下单{GetTaobaoKePassword(g.CouponShareUrl, g.PictUrl + "_400x400.jpg")}
";

                        }
                        return responeMessage;

                    }
                    else
                    {
                        float numid = 0;
                        try
                        {
                            numid = float.Parse(item_id);
                        }
                        catch (Exception ex)
                        {

                          //通过淘宝链接没有获取到item id,显示销量最高商品
                            var g = rsp.ResultList.Where(y => !string.IsNullOrEmpty(y.CouponId)).OrderByDescending(y => y.Volume).FirstOrDefault();

                            var hongbao = (decimal.Parse(g.ZkFinalPrice) - decimal.Parse(Regex.Match(g.CouponInfo, "减" + @"(d+)").Groups[1].Value)) * decimal.Parse(g.CommissionRate) / 10000 * commission_rate;
                            responeMessage = $"{g.Title}
【在售价】{g.ZkFinalPrice}元
【巻后价】{Math.Round(double.Parse(g.ZkFinalPrice) - double.Parse(Regex.Match(g.CouponInfo, "减" + @"(d+)").Groups[1].Value), 2)} 元
复制这条信息,打开「手机绹宝」领巻下单{GetTaobaoKePassword(g.CouponShareUrl, g.PictUrl + "_400x400.jpg")}
";

                            return responeMessage;

                        }

                        //在接口返回的商品中找查询的商品
                        foreach (var g in rsp.ResultList)
                        {
                            if (g.NumIid == numid)
                            {
                                if (string.IsNullOrEmpty(g.CouponInfo))
                                {
                                    var hongbao = decimal.Parse(g.ZkFinalPrice) * decimal.Parse(g.CommissionRate) / 10000 * commission_rate;

                                    responeMessage = $"{g.Title}
【在售价】{g.ZkFinalPrice}元
【约返利】{Math.Round(hongbao, 2)}元
复制这条信息,打开「手机绹宝」领巻下单{GetTaobaoKePassword(g.Url, g.PictUrl + "_400x400.jpg")}
==========================
下单确认收货后就能收到返利佣金啦~
 点击查看  <a href='http://mp.weixin.qq.com/s?__biz=Mzg2NTAxOTEyMA==&mid=100000146&idx=1&sn=62405c8df3db46e74940aefb9ac3737b&chksm=4e61340d7916bd1bf645afbc6d10c1f19561d7fa59847516c01e64c0791e6d544f4f56c4f498#rd'>如何领取返利</a>";
                                    return responeMessage;
                                }
                                else
                                {
                                    var hongbao = (decimal.Parse(g.ZkFinalPrice) - decimal.Parse(Regex.Match(g.CouponInfo, "减" + @"(d+)").Groups[1].Value)) * decimal.Parse(g.CommissionRate) / 10000 * commission_rate;
                                    responeMessage = $"{g.Title}
【在售价】{g.ZkFinalPrice}元
【巻后价】{Math.Round(double.Parse(g.ZkFinalPrice) - double.Parse(Regex.Match(g.CouponInfo, "减" + @"(d+)").Groups[1].Value), 2)} 元
复制这条信息,打开「手机绹宝」领巻下单{GetTaobaoKePassword(g.CouponShareUrl, g.PictUrl + "_400x400.jpg")}
";
                                    return responeMessage;
                                }
                            }
                        }

                        //没有找到,有相似宝贝推荐
                        var w = rsp.ResultList.Where(y => !string.IsNullOrEmpty(y.CouponId)).OrderByDescending(y => y.Volume).FirstOrDefault();

                        if (w == null)
                        {
                            responeMessage = ConfigurationManager.AppSettings["tbk_nocoupon_msg"].Replace("\n", "
").Replace("\ue231", "ue231");
                        }
                        else
                        {
                            var hongbao = (decimal.Parse(w.ZkFinalPrice) - decimal.Parse(Regex.Match(w.CouponInfo, "减" + @"(d+)").Groups[1].Value)) * decimal.Parse(w.CommissionRate) / 10000 * commission_rate;

                            responeMessage = $"/:rose 亲,这款商品的优惠返利活动结束了~
已为你推荐以下宝贝。
==========================
{w.Title}
【在售价】{w.ZkFinalPrice}元
【巻后价】{Math.Round(double.Parse(w.ZkFinalPrice) - double.Parse(Regex.Match(w.CouponInfo, "减" + @"(d+)").Groups[1].Value), 2)} 元
复制这条信息,打开「手机绹宝」领巻下单{GetTaobaoKePassword(w.CouponShareUrl, w.PictUrl + "_400x400.jpg")}
";
                        }

                        return responeMessage;

                    }


                }
                else
                {
                    responeMessage = ConfigurationManager.AppSettings["tbk_nocoupon_msg"].Replace("\n", "
").Replace("\ue231", "ue231");

                }

            }
            catch (Exception ex)
            {
                //LogHelper.WriteLog(typeof(WechatController), "返回消息异常" + ex.Message);

            }

            return responeMessage;

        }

京东、拼多多找券

京东、拼多多找券都比较简单,微信支持京东、拼多多链接,可以通过链接获取到商品id,然后直接通过接口使用商品id找券。
京东代码:使用了第三方接口(好京客)

 public static string GetJDCoupon(RequestMessageText requestMessageText)
        {
           
            string msg = requestMessageText.Content;
            Match m_goods = Regex.Match(msg, @"(?<=product/)([0-9]*)|(?<=sku=)([0-9]*)");

            string skuId = m_goods.Value;

            if (string.IsNullOrEmpty(skuId))
            {
               // LogHelper.WriteLog(typeof(WechatController), "获取京东skuid失败" + msg);
                return "";
            }

            try
            {
                var hjkGoodsDetail = hjkApi.GetJDGoodsDetail(skuId);

                if (hjkGoodsDetail.StatusCode == 200 && hjkGoodsDetail.Data != null && !string.IsNullOrEmpty(hjkGoodsDetail.Data.CouponList))
                {
                    var model = hjkApi.GetUnionUrl(skuId, hjkGoodsDetail.Data.CouponList);
                    if (model != null && model.StatusCode == 200 && !string.IsNullOrEmpty(model.Data))
                    {
                        return $"{hjkGoodsDetail.Data.SkuName}
【在售价】{hjkGoodsDetail.Data.WlPrice}元
【巻后价】{hjkGoodsDetail.Data.WlPriceAfter} 元

ue231 <a href='{model.Data}'>点击这里领券下单</a>

";
                    }
                    else
                    {
                        return ConfigurationManager.AppSettings["jd_nocoupon_msg"].Replace("\n", "
").Replace("\ue231", "ue231");
                    }

                }
                else
                {
                    return ConfigurationManager.AppSettings["jd_nocoupon_msg"].Replace("\n", "
").Replace("\ue231", "ue231");
                }
            }
            catch (Exception ex)
            {
                //LogHelper.WriteLog(typeof(WechatController), "获取京东skuid失败" + ex.Message);
                return "";
            }
        }

拼多多代码如下:

 public static async Task<string> GetPDDCouponAsync(RequestMessageText responseMessageText)
        {
            PddCommonApi.ClientId = "d8172a66ddf14220beac58e8eddca0d9";
            PddCommonApi.ClientSecret = "d5993ce16cc0d1bd35403176f35544962e786645";
            PddCommonApi.RedirectUri = "RedirectUri";
            PddCommonApi.AccessToken = "";

            string msg = responseMessageText.Content;
            Match m_goods = Regex.Match(msg, @"(?<=goods_id=)([0-9]*)");

            string goods_id = m_goods.Value;

            if (string.IsNullOrEmpty(goods_id))
            {
                //LogHelper.WriteLog(typeof(WechatController), "获取拼多多goods id失败" + msg);
                return "";
            }

            DdkApi api = new DdkApi();

            var model = new DetailDdkGoodsRequestModel()
            {
                Type = "pdd.ddk.goods.detail",
                GoodsIdList = $"[{goods_id}]"
            };
            DetailDdkGoodsResponseModel result = null;
            try
            {
                result = await api.DetailDdkGoodsAsync(model);
            }
            catch (Exception ex)
            {
                //LogHelper.WriteLog(typeof(WechatController), "调用拼多多获取商品详细信息失败" + ex.Message);
                return "";
            }


            var goods = result.GoodsDetailResponse.GoodsDetails.FirstOrDefault();

            if (goods == null) //无优惠券 无佣金
            {
                return "/:rose 亲,这款商品的优惠返利活动结束了~
请换个商品试试吧。
========================
ue231    <a href='https://mobile.yangkeduo.com/duo_cms_mall.html?pid=2495191_31302208cpsSign=CM2495191_31302208_3a1c1a0431608b9c1eb417183d57c1bdduoduo_type=2'>拼多多优惠券商城</a>
下单确认收货后就能收到返利佣金啦~";
            }
            else if (goods.HasCoupon) //有优惠券 有佣金
            {
                try
                {
                    var promotionUrlModel = await api.GenerateDdkGoodsPromotionUrlAsync(new GenerateDdkGoodsPromotionUrlRequestModel
                    {
                        Type = "pdd.ddk.goods.promotion.url.generate",
                        PId = pdd_pid,
                        GoodsIdList = $"[{goods_id}]",
                        GenerateShortUrl = true,
                        CustomParameters = responseMessageText.FromUserName
                    });


                    return $"/:rose 亲,商品信息如下~
========================
{goods.GoodsName}
【在售价】{((decimal)goods.MinGroupPrice) / 100}元
【券后价】{Math.Round(((decimal)(goods.MinGroupPrice - goods.CouponDiscount.Value)) / 100, 2)}元
ue231 <a href='{promotionUrlModel.GoodsPromotionUrlGenerateResponse.GoodsPromotionUrlList.FirstOrDefault().Url}'>点击这里下单</a>
下单确认收货后就能收到返利佣金啦~";

                    //return $"/:rose 亲,商品信息如下~
========================
{goods.GoodsName}
【在售价】{((decimal)goods.MinGroupPrice) / 100}元
【券后价】{Math.Round(((decimal)(goods.MinGroupPrice - goods.CouponDiscount.Value)) / 100,2)}元
【约返利】{Math.Round((decimal)((goods.MinNormalPrice - goods.CouponDiscount.Value) * goods.PromotionRate) / 100000,2)}元
ue231 <a href='{promotionUrlModel.GoodsPromotionUrlGenerateResponse.GoodsPromotionUrlList.FirstOrDefault().Url}'>点击这里下单</a>
下单确认收货后就能收到返利佣金啦~";

                }
                catch (Exception ex)
                {
                    //LogHelper.WriteLog(typeof(WechatController), "调用拼多多获取推广链接失败" + ex.Message);
                    return "";
                }
            }
            else //无优惠券 但有佣金
            {
                try
                {
                    var promotionUrlModel = await api.GenerateDdkGoodsPromotionUrlAsync(new GenerateDdkGoodsPromotionUrlRequestModel
                    {
                        Type = "pdd.ddk.goods.promotion.url.generate",
                        GoodsIdList = $"[{goods_id}]",
                        PId = pdd_pid,
                        GenerateShortUrl = true,
                        CustomParameters = responseMessageText.FromUserName
                    });


                    return $"/:rose 亲,商品信息如下~
========================
{goods.GoodsName}
【在售价】{((decimal)goods.MinGroupPrice) / 100}元
【约返利】{Math.Round((decimal)(goods.MinGroupPrice * goods.PromotionRate) / 100000, 2)}元
ue231 <a href='{promotionUrlModel.GoodsPromotionUrlGenerateResponse.GoodsPromotionUrlList.FirstOrDefault().Url}'>点击这里下单</a>
下单确认收货后就能收到返利佣金啦~

 点击查看  <a href='http://mp.weixin.qq.com/s?__biz=Mzg2NTAxOTEyMA==&mid=100000146&idx=1&sn=62405c8df3db46e74940aefb9ac3737b&chksm=4e61340d7916bd1bf645afbc6d10c1f19561d7fa59847516c01e64c0791e6d544f4f56c4f498#rd'>如何领取返利</a>";
                }
                catch (Exception ex)
                {
                    //LogHelper.WriteLog(typeof(WechatController), "调用拼多多获取推广链接失败" + ex.Message);
                    return "";
                }

            }
            
        }

完整代码 https://github.com/xuhang2015/TBK
请关注“网购有券”,支持下我吧。有任何问题也可以在公众号中联系我。

以上是关于拼多多商品详情接口(封装代码)的主要内容,如果未能解决你的问题,请参考以下文章

拼多多获取整站实时商品详情数据|商品标题|商品链接,数据采集,数据分析提取教程

公众号搭建淘宝京东拼多多查券平台

拼多多商品id怎么看?怎样看店铺ID?

9ABPZero系列教程之拼多多卖家工具 拼团提醒类库封装

在哪能找到拼多多token登录软件?

大数据分析50万条拼多多商品数据, 得出了这样的结论