Home >Backend Development >PHP Tutorial >How to query courier information in PHP, how to query courier information in PHP_PHP tutorial
The example in this article describes the method of querying courier information with PHP. Share it with everyone for your reference. The details are as follows:
Use Express 100 logistics inquiry here
The official document can only return html interface, but can also return json
The php code is as follows:
Copy code The code is as follows:/**
* @desc Get courier information
* @param string $code express code
* @param string $invoice express number
* @return mixed $result(
'status','info','state','data'
)
*/
function getExpressDelivery($code,$invoice){
$result = array('status'=>0,'info'=>'Unknown error');
$url = "http://m.kuaidi100.com/query?type={$code}&postid={$invoice}&id=1&valicode=&temp=".rand(1,710);
$body = file_get_contents($url); //FIXME
$body = json_decode($body,true);
$result['status'] = $body['status'] == 200 ? 1 : 0;
$result['info'] = $body['message'];
isset($body['data']) && ($result['state']=$body['state']) && ($result['data'] = $body['data']) ;
Return $result;
}
I hope this article will be helpful to everyone’s PHP programming design.