用官网DEMO无法file_get,所以自己探索其他方案,实测可行?
<?php
//快递查询示范代码之快递鸟付费接口
//需要kdniao.com网站注册并在后台得到ApiKey EBusinessID
$Apiusr='1239100'; //请修改EBusinessID即用户ID
$ApiKey='56da2cf8-c8a2-44b2-b6fa-476cd7d1ba17'; //请修改ApiKey
$Kdcoms="YTO";//请修改快递公司字母代码
$Kdnums="yt1428578711***";//请修改快递单号
$Apiurl='https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx';
$rData= "{'CustomerName': '','OrderCode': '','ShipperCode': '{$Kdcoms}','LogisticCode': '{$Kdnums}'}";
$datas = array();
$datas['EBusinessID'] = $Apiusr;
$datas['RequestType'] = "1002";
$datas['RequestData'] = $rData;
$datas['DataType'] = "2";
$datas['DataSign'] = urlencode(base64_encode(md5($rData.$ApiKey)));
$pdata = "";
foreach($datas as $tt=>$vv){$vv = urlencode($vv);$pdata .= "&{$tt}={$vv}";}
$pdata = Trim($pdata,"&");
$result=ccurl($Apiurl, $pdata);
echo "\r\n<br>result: ".$result;
function ccurl($url , $post) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 600);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if ($referer) {
curl_setopt($curl, CURLOPT_REFERER, $referer);
} else {
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
}
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
if (!empty($post)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($curl, CURLOPT_COOKIE, '');
$nres = curl_exec($curl);
curl_close($curl);
if ($nres) {
return $nres;
}
}
?>
|