PHP调用京东联盟接口以及配置签名

PHP调用京东联盟接口以及配置签名

  • 1.生成签名
  • 2.调用方法实例

1.生成签名

// 京东联盟生成签名
/**
	method 接口名称
**/
function sign_method($method,$data=array()){
	date_default_timezone_set("PRC");
	$sign_method = array(
					'app_key'=> '您的appkey',
					'timestamp'=> date('Y-m-d H:i:s'),
					'format' => 'json',
					'method' => $method,
					'v' => '1.0',
					'sign_method'=>'md5',
				);
	$sign_method = array_merge($sign_method,$data);
	ksort($sign_method);
	// var_dump($array_merge);die();
	$data = '您的app_secret';
	foreach ($sign_method as $key => $value) {
		$data .= trim($key) .trim($value);
	}
	$data .= '您的app_secret';
	$sign_method['sign'] = strtoupper(md5($data));
	// echo "
";
	// var_dump($sign_method);die();
	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.调用方法实例

$param = array();
$data['skuIds'] = '5225346,7275691'; 
$param['param_json'] = json_encode($data);
$GoodsList = sign_method('jd.union.open.goods.promotiongoodsinfo.query',$param);
$GoodsList = curl_post('https://router.jd.com/api', $GoodsList);
$GoodsList = json_decode($GoodsList,true);

官方配置签名地址:
https://union.jd.com/helpcenter/12188-12384-46301
API接口地址:
https://union.jd.com/openplatform/api

你可能感兴趣的:(PHP)