PHP如何查询快递信息

这篇文章将为大家详细讲解有关PHP如何查询快递信息,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

具体如下:

这里使用快递100物流查询
官方文档中只能返回html的接口 也可以返回json

php代码如下:

/**
 * @desc 获取快递信息 
 * @param string $code 快递编码
 * @param string $invoice 快递单号
 * @return mixed $result(
      'status','info','state','data'
   )
 */
function getExpressDelivery($code,$invoice){
    $result = array('status'=>0,'info'=>'未知错误');
    $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;
}

关于“PHP如何查询快递信息”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。