1.生成签名
// 拼多多签名生成
/***
type 接口名称
**/
public function pdd_sign_method($type,$data=array()){
$sign_method = array (
'client_id' => '多多进宝绑定Client ID', //多多进宝绑定的Client ID
'type' => $type, //方法名
'timestamp' => time(),//当前时间戳
'data_type' => 'JSON',//返回格式
);
$sign_method = array_merge($sign_method,$data);
// 首字母先后顺序排列
ksort($sign_method);
$data = '拼多多client_secret';
foreach ($sign_method as $key => $value) {
$data .= trim($key) . trim($value);
}
// 首尾加上client_secret
$data .= '拼多多client_secret';
$sign_method['sign'] = strtoupper(md5($data));
return $sign_method;
}
// 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;
}
2.调用方法
//调用方法
$GoodsList = $this->pdd_sign_method('pdd.ddk.goods.search',$param);
//Config::get('pddgoods.pddgoods_url') = https://gw-api.pinduoduo.com/api/router
$GoodsList = curl_post('接口地址', $GoodsList);
$GoodsList = json_decode($GoodsList,true);
拼多多官方配置签名地址:
http://open.pinduoduo.com/#/document
拼多多API接口地址:
http://open.pinduoduo.com/#/apidocument