Home > php教程 > php手册 > PHP查询快递信息的方法,PHP快递信息方法

PHP查询快递信息的方法,PHP快递信息方法

WBOY
Release: 2016-06-13 09:13:31
Original
1547 people have browsed it

PHP查询快递信息的方法,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程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template