拼多多api接口php算法,PHP 调用 拼多多 API 模板

拼多多的API模板就更简单了,前段时间刚放出来接口权限,上周开始对接完成。

都是无需授权的接口,所以也就不需要刷新token之类的事。<?php

/*拼多多API类*/

class PDDApi

{

private $client_id = 'client_id'; // 你的client_id

private $client_secret = 'client_secret'; // 你的client_secret

/**

* 获取拼多多接口数据

* @param string $apiType API 名称 如:pdd.ddk.direct.goods.query

* @param array $param 公共参数 如:['page' => 1 , 'page_size' => 100]

* @return mixed

*/

public function GetPDDApi($apiType, $param)

{

$url = 'http://gw-api.pinduoduo.com/api/router';

$param['client_id'] = $this->client_id;

$param['type'] = $apiType;

$param['data_type'] = 'JSON';

$param['timestamp'] = $this->getMillisecond();

ksort($param); // 排序

$str = ''; // 拼接的字符串

foreach ($param as $k => $v) $str .= $k . $v;

$sign = strtoupper(md5($this->client_secret. $str . $this->client_secret)); // 生成签名 MD5加密转大写

$param['sign'] = $sign;

return $this->curl_post($url, $param);

}

/**

* 发送post请求

* @param $url

* @param $curlPost

* @return mixed

*/

private 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;

}

// 获取13位时间戳

private function getMillisecond()

{

list($t1, $t2) = explode(' ', microtime());

return sprintf('%.0f', (floatval($t1) + floatval($t2)) * 1000);

}

}

// 调用方法

$p = new PDDApi();

echo $p->GetPDDApi('pdd.ddk.direct.goods.query',['page'=>1]);

本文由 Yuuuuuu 创作,采用 知识共享署名4.0 国际许可协议进行许可

本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名

最后编辑时间为: Nov 12, 2018 at 04:57 pm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值