PHP调用拼多多接口以及配置签名

PHP调用拼多多接口以及配置签名

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凯鑫BOSS

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值