[PHP] 纯文本查看 复制代码<?php
// 具体参数可查看 https://union.jd.com/openplatform/api/10421 文档说明
error_reporting(0);
$sourceurl = $_GET["u"];
if($sourceurl == ""){
echo "请传入url参数";
exit();
}
$app_key='1';
$method = "jd.union.open.promotion.common.get";
$sign = "";
$timestamp = date('Y-m-d H:i:s',time());
$format = "json";
$v='1.0';
$sign_method='md5';
$sign='';
$promotionCodeReq=[
'materialId'=>'',
'siteId'=>''
];
$baseurl = "https://api.jd.com/routerjson?";
//业务参数
$_360buy_param_json =json_encode($promotionCodeReq);
//系统参数
$fields = [
"app_key" => $app_key,
"method" => urlencode($method),
"timestamp" => urlencode($timestamp),
"v" => urlencode($v),
'format'=>$format,
'sign_method'=>$sign_method,
'sign'=>
];
$fields_string = "";
$_tempString='';
foreach($fields as $key=>$value)
{
$_tempString .= $key.$value;
$fields_string.= $key.'='.$value.'&';
}
$sign = strtoupper(md5($fields_string));
$fields_string .= ("sign=".$sign);
$link = $baseurl.$fields_string;
$result=curl_get($link);
$jsonArray = json_decode($result,true);
$error_result=$jsonArray['error_response'];
if(!empty($error_result)) {
echo'获取失败';
echo "\r\n";
echo'失败原因:'.$error_result['zh_desc'];
echo "\r\n";
echo'Falit_MSG:'.$error_result['en_desc'];
}else
{
// 打印成功数据
$success_result=$jsonArray['data'];
echo '转换成功:'.$success_result['clickURL'];
}
function curl_get($url){
$header = array(
'Accept: application/json',
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$data = curl_exec($curl);
if (curl_error($curl)) {
print "Error: " . curl_error($curl);
return null;
}
return $data;
}
?>