PHP 通過單號查詢快遞( 申通、EMS、順豐、圓通、中通、韻達、天天、匯通、全峰、德邦、宅急送)

 

 

 0,
		CURLOPT_URL => $url,
		CURLOPT_FRESH_CONNECT => 1,
		CURLOPT_RETURNTRANSFER => 1,
		CURLOPT_FORBID_REUSE => 1,
		CURLOPT_TIMEOUT => 4,
		CURLOPT_POSTFIELDS => http_build_query($post)
	);

	$ch = curl_init();
	curl_setopt_array($ch, ($options + $defaults));
	if( ! $result = curl_exec($ch))
	{
	trigger_error(curl_error($ch));
	}
	curl_close($ch);
	return $result;
}

//正確的返回格式 JSON
/**
* {"message":"ok","state":"3″,"data":[{"context":"已簽收,簽收人是【本人】",
* "time":"2013-12-15 11:02:26","ftime":"2013-12-15 11:02:26"},{"context":"
* 【湖南長沙雨花分公司】的派件員【林大自取分部82177562 電話(82171562)】正在派件",
* "time":"2013-12-14 21:43:38","ftime":"2013-12-14 21:43:38"},{"context":
* "快件已到達【湖南長沙雨花分公司】 掃描員是【湯建敏】上一站是【】","time":"2013-12-14
* 17:19:52","ftime":"2013-12-14 17:19:52"},{"context":"由【湖南長沙航空部】發往
* 【湖南長沙雨花分公司】","time":"2013-12-14 16:26:36","ftime":"2013-12-14 16:26:36"}
* ,{"context":"【浙江蕭山公司】正在進行【裝袋】掃描","time":"2013-12-12 18:59:17",
* "ftime":"2013-12-12 18:59:17"},{"context":"由【浙江蕭山公司】發往【湖南長沙中轉部】"
* ,"time":"2013-12-12 18:59:17","ftime":"2013-12-12 18:59:17"},{"context":"【浙江蕭山公司】
* 的收件員【公司漢帛 】已收件","time":"2013-12-12 18:20:47","ftime":"2013-12-12 18:20:47"},
* {"context":"【浙江蕭山公司】的收件員【公司漢帛 】已收件","time":"2013-12-12
* 14:56:21","ftime":"2013-12-12 14:56:21"}],"status":"200″,"com":"shentong","nu":
* "768064369802″,"condition":"F00″,"ischeck":"1″}
*/
//正確放回的格式 JSON
/**
* {"message":"ok","state":"3″,
* "data":[{"context":"微山縣付村郵電支局:投遞並簽收
* 投遞結果:他人簽收代收","time":"2013-12-17 15:42:00",
* "ftime":"2013-12-17 15:42:00"},{"context":"微山縣付村郵電支局:投遞並簽收",
* "time":"2013-12-17 09:47:00","ftime":"2013-12-17 09:47:00"}
* ,{"context":"微山縣郵政局速遞公司:離開處理中心,發往微山縣付村郵電支局",
* "time":"2013-12-16 18:38:56","ftime":"2013-12-16 18:38:56"},
* {"context":"微山縣郵政局速遞公司:到達處理中心,來自金華市","time":"
* 2013-12-16 17:27:18","ftime":"2013-12-16 17:27:18"},{"context":
* "金華市:離開處理中心,發往棗莊市","time":"2013-12-14 23:57:43","ftime":
* "2013-12-14 23:57:43"},{"context":"金華市:到達處理中心,來自義烏市",
* "time":"2013-12-14 22:51:02","ftime":"2013-12-14 22:51:02"},
* {"context":"義烏市義烏市電子商務分公司:收寄","time":"2013-12-14 15:00:00",
* "ftime":"2013-12-14 15:00:00"}],"status":"200″,"com":"ems","nu":"5000655082802″,
* "condition":"F00″,"ischeck":"1″}
*/
//錯誤的格式 JSON
/**
* {"status":"201″,"message":"快遞公司參數異常:單號不存在或者已經過期"}
*/
/**
* @param string $postid 快遞單號
* @param string $type 快遞類型
* shentong —> 申通
* ems —> EMS
* shunfeng –> 順豐
* yuantong –> 圓通
* zhongtong –> 中通
* yunda –> 韻達
* tiantian —> 天天快遞
* huitongkuaidi –> 匯通快遞
* quanfengkuaidi –> 全峰快遞
* debangwuliu –> 德邦物流
* zhaijisong –> 宅急送
* @return mixed json格式
*/

function Dquery($postid = '268323324324' , $type = 'shentong')
{
	$post_data = array (
	"type" => $type,
	"postid" => $postid ,
	"id" => "1",
	"valicode" => "",
	"temp" => '0.7771608149632812'
	) ;
	$url ='https://www.kuaidi100.com/query';
	return curl_get($url,$post_data);
}



/**
* 申通快遞
* @param string $postid String 快遞單號
* @return mixed at most json
*/
function shentong($postid = '229055602837')
{
	return Dquery($postid,'shentong');
}



/**
* EMS
* @param string $postid 快遞單號
* @return mixed JSON
*/
function EMS($postid = '5000655082802')
{
	return Dquery($postid,'ems');
}



/**
* 順豐快遞
* @param string $postid 快遞單號
* @return mixed JSON
*/
function shunfeng($postid = '370270606236')
{
	return Dquery($postid,'shunfeng');
}



/**
* 圓通快遞
* @param string $postid 快遞單號
* @return mixed JSON
*/
function yuantong($postid = '9149223354')
{
	return Dquery($postid,'yuantong');
}
/**
* 中通快遞
* @param string $postid 快遞單號
* @return mixed JSON
*/
function zhongtong($postid = '778179380478')
{
	return Dquery($postid,'zhongtong');
}

/**
* 韻達快遞
* @param string $postid 快遞單號
* @return mixed JSON
*/
function yunda($postid = '1201030121554')
{
	return Dquery($postid,'yunda');
}

/**
* 天天快遞
* @param string $postid 快遞單號
* @return mixed JSON
*/
function tiantian($postid = '580054419316')
{
	return Dquery($postid,'tiantian');
}

/**
* 匯通快遞
* @param string $postid 快遞單號
* @return mixed JSON
*/
function huitongkuaidi($postid='210322948150')
{
	return Dquery($postid,'huitongkuaidi');
}

/**
* 全峰快遞
* @param string $postid 快遞單號
* @return mixed JSON
*/
function quanfengkuaidi($postid='340003662547')
{
	return Dquery($postid,'quanfengkuaidi');
}

/**
* 德邦物流
* @param string $postid 快遞單號
* @return mixed JSON
*/
function debangwuliu($postid='16312048')
{
	return Dquery($postid,'debangwuliu');
}

/**
* 宅急送
* @param string $postid 快遞單號
* @return mixed JSON
*/
function chaijisong($postid = '3332776112')
{
	return Dquery($postid,'zhaijisong');
}


//Debug 這裡是調用時的 debug,最好再加個訂單號。
//放回格式都是json喔。。 記得解析
print_r(json_decode(shentong()));
//echo EMS();
//echo shunfeng();
//echo yuantong();
//echo zhongtong();
//echo yunda();
//echo tiantian();
//echo huitongkuaidi();
//echo quanfengkuaidi();
//echo debangwuliu();


?>

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *