由于有不少小伙伴要求在淘宝客插件上添加拼多多的商品推广功能,狗哥为了满足你们被迫递交了资料给拼多多。我一直不想接入拼多多的主要原因有两点,第一是需要实名认证,第二是它的接口写得及其不规范。在开发时也证明了接口十分难用,各大搜索引擎关于拼多多多多客推广接口的相关内容非常少,可想而知这东西好不好用。
下面以拼多多的商品详情接口为例,用实例告诉大家PHP如何使用拼多多的接口。多多进宝接口统一请求地址:https://gw-api.pinduoduo.com/api/router
首先看签名方法,拼多多的签名方式与其它大厂的签名方法有些区别,最明显的就是连接不需要符号。
function Make_sign($params,$client_secret){ksort($params);$paramsStr = '';array_walk($params, function ($item, $key) use (&$paramsStr) {$paramsStr .= sprintf('%s%s', $key, $item);});$sign = strtoupper(md5(sprintf('%s%s%s',$client_secret,$paramsStr,$client_secret)));return $sign;}
简单使用
$data=array( 'type'=>'pdd.ddk.goods.detail', 'client_id'=>$client_id, 'timestamp'=>strval(time()), 'p_id'=>$p_id, 'goods_id_list'=>'[141449426]' ); $data['sign']=Make_sign($data,$client_secret);
到此,$data
变量中存放的就是我们需要提交给拼多多服务器的数据,提交方式post,先准备一个post方法。
// post请求 function curl_post($url, $curlPost) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); $result = curl_exec($ch); curl_close($ch); return $result; }
简单使用
$data=array( 'type'=>'pdd.ddk.goods.detail', 'client_id'=>$client_id, 'timestamp'=>strval(time()), 'p_id'=>$p_id, 'goods_id_list'=>'[141449426]' ); $data['sign']=Make_sign($data,$client_secret); $result=curl_post($url,$data); print_r($result);
将client_id、client_secret、p_id(推广位id)换成自己的就行了。下面是测试返回的数据。
{ "goods_detail_response": { "goods_details": [ { "mall_coupon_remain_quantity": 0, "plan_type": 2, "category_name": "食品", "coupon_remain_quantity": 18000, "promotion_rate": 140, "cat_ids": [ 6398, 6399, 6410 ], "coupon_min_order_amount": 0, "category_id": 1, "service_tags": [ 36, 37, 13 ], "mall_coupon_discount_pct": 0, "mall_id": 781984, "mall_name": "粒上皇官方旗舰店", "coupon_total_quantity": 50000, "mall_coupon_end_time": 0, "mall_coupon_min_order_amount": 0, "merchant_type": 3, "lgst_txt": "高", "goods_name": "【粒上皇-甘栗80g*4/6包】熟制板栗仁迁西板栗健康休闲零食特产", "sales_tip": "2.7万", "only_scene_auth": true, "goods_gallery_urls": [ "https://img.pddpic.com/mms-material-img/2021-01-09/8078205f-d30a-412b-bb8b-5b9d76db42da.jpeg.a.jpeg", "https://img.pddpic.com/mms-material-img/2020-08-18/51e39b7b-e37e-455e-8f87-4e9fb56db93e.jpeg.a.jpeg", "https://img.pddpic.com/mms-material-img/2020-08-18/9dfe7b60-e9fd-4d19-ac77-60b2e88c70f2.jpeg.a.jpeg", "https://t00img.yangkeduo.com/goods/images/2019-02-27/37f5f38d-a853-4e46-8d87-8db6883ff751.jpg", "https://t00img.yangkeduo.com/goods/images/2019-02-27/2034a15f-97ac-46bc-b57f-10b2c7383d40.jpg", "https://img.pddpic.com/mms-material-img/2021-01-09/9f46e982-07f8-4311-a5c4-9e53f8acde67.jpeg.a.jpeg", "https://img.pddpic.com/mms-material-img/2021-01-09/ed3cd626-e257-4587-987c-1e09fc174e2e.jpeg.a.jpeg", "https://img.pddpic.com/mms-material-img/2021-01-09/8144f023-38ce-416d-8ae8-dfc714e76003.jpeg.a.jpeg", "https://img.pddpic.com/mms-material-img/2020-08-18/4fabd1b5-9de0-41b9-9322-f9a479913f8d.jpeg.a.jpeg" ], "goods_id": 141449426, "predict_promotion_rate": 140, "desc_txt": "高", "goods_desc": "【粒上皇-甘栗80g*4/6包】熟制板栗仁迁西板栗健康休闲零食特产", "opt_name": "食品", "share_rate": 0, "goods_thumbnail_url": "https://t00img.yangkeduo.com/goods/images/2021-01-09/471a0d41bd1660dc2e9a3c3a95480b88.jpeg", "opt_ids": [ 1, 23553, 8836, 8584, 10696, 8585, 8586, 10700, 12, 22926, 22932, 22297, 10009, 219, 6366, 96, 21857, 10723, 11876, 228, 22953, 5867, 6389, 9975, 8569, 8570, 8571, 9979 ], "opt_id": 1, "goods_image_url": "https://img.pddpic.com/mms-material-img/2021-01-09/8078205f-d30a-412b-bb8b-5b9d76db42da.jpeg.a.jpeg", "has_mall_coupon": false, "has_coupon": true, "min_normal_price": 4480, "mall_coupon_start_time": 0, "serv_txt": "高", "unified_tags": [ "正品险" ], "video_urls": [ "https://video1.pinduoduo.com/i1/20190227/733433b9cac949da8bb614abca7b931a.mp4" ], "mall_coupon_total_quantity": 0, "mall_coupon_max_discount_amount": 0, "coupon_start_time": 1600617600, "min_group_price": 3880, "mall_cps": 1, "coupon_discount": 2100, "goods_sign": "c9T2omIgpkZKDwEhwfHYm2Zb2uqh_JiENmf8rO", "coupon_end_time": 1616428799, "zs_duo_id": 0 } ], "request_id": "16108831204286103" } }
拼多多在接口文档上写的goods_id_list
参数为长整型数组LONG[]
,你能想到提交的时候需要写成'[123456789]'
?更离谱的是goods_sign_list
参数文档上写的字符串类型数组STRING[]
,我测试了各种写法,没试出拼多多什么意思,无赖放弃。
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/242117.html