<?php
/*
- tracking_number 快递单号
- carrier_code 运输商简码(查询链接 https://www.trackingmore.com/help_article-16-30-cn.html)
-
Trackingmore-Api-Key: 后台生成API key
*/
$url = "http://api.trackingmore.com/v2/trackings/realtime";
$header = array(
'Content-Type:application/json',
'Trackingmore-Api-Key:b7a0009f-6cd2-43ee-9d1d-ed7135ad460f'
);
$postData = array(
'tracking_number'=>'LK664578623CN',
'carrier_code'=>'china-ems'
);
$res = curl_post($url,json_encode($postData),$header);
print_r($res);
function curl_post($url, $postData,$header=array(),$cookie_file='',$isheader=0,$proxy='',$debug=0,$autoRedirect=0,$time=89){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(!empty($isheader)){
curl_setopt($ch, CURLOPT_HEADER, $isheader);
}
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT,$time);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:44.0) Gecko/20100101 Firefox/44.0');
if(!empty($header)){
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
}
if(!empty($autoRedirect)){
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
}
if(!empty($cookie_file)){
// 读取文件所储存的Cookie信息
curl_setopt ( $ch, CURLOPT_COOKIEFILE, $cookie_file );
}
if(!empty($proxy)){
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
//curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
if(!empty($debug)){
curl_setopt($ch,CURLOPT_VERBOSE,1);
curl_setopt($ch,CURLOPT_FAILONERROR,TRUE);
print_r(curl_error($ch));
print_r(curl_getinfo($ch));
}
$html = curl_exec($ch);
curl_close($ch);
return $html;
}