PHP curl查询全国快递物流信息

  1. 首先你要了解curl。
    curl是PHP一个很强大的,用来发送http请求的函数 详情请见:https://www.runoob.com/php/php-ref-curl.html。
    2.直接进入正题
    // n u m b e r 你 查 询 的 快 递 数 p u b l i c f u n c t i o n e x p r e s s ( number 你查询的快递数 public function express( numberpublicfunctionexpress(number)
    {
    if (empty($number)) {
    return ajax_error(‘运单号不能为空!’);
    }
    $host = “http://wuliu.market.alicloudapi.com”; // api访问链接
    $path = “/kdi”; // API访问后缀
    $method = “GET”;
    $appcode =**** //自己的阿里云appcode
    h e a d e r s = [ ] ; / / 组 成 请 求 的 h e a r d e r 头 信 息 类 似 于 企 业 签 名 a r r a y p u s h ( headers = []; //组成请求的hearder头信息 类似于企业签名 array_push( headers=[];//hearderarraypush(headers, "Authorization:APPCODE " . $appcode);

     $querys = "no=" . $number; // 参数写在这里
      $url = $host . $path . "?" . $querys; // url拼接
      
      // 初始化curl会话
     $curl = curl_init();
     // 设置请求方法
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
    
     // 设置请求的url地址
     curl_setopt($curl, CURLOPT_URL, $url);
    
    // 设置http的头字段
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     
      // 将获取的信息以文件流的形式返回(如果不设置此参数,你所得到的数据将会直接输出不能使用)
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    

    //执行
    curl_exec($curl) //返回的信息是字符串类型

    此时你需要json_decode(curl_exec($curl));
    转换为json对象来使用

返回的信息参数介绍

object(stdClass)#9 (3) {
  ["status"] => string(1) "0"  //状态吗
  ["msg"] => string(2) "ok"  
  ["result"] => object(stdClass)#12 (11) {
    ["number"] => string(12) "" 快递单号
    ["type"] => string(3) ""        快递类型
    ["list"] => array(6) {            快递信息
      [0] => object(stdClass)#20 (2) {
        ["time"] => string(19) ""   时间
        ["status"] => string(77) "" 快递信息
      }
      [1] => object(stdClass)#21 (2) {
        ["time"] => string(19) ""
        ["status"] => string(54) ""
      }
      [2] => object(stdClass)#22 (2) {
        ["time"] => string(19) ""
        ["status"] => string(80) ""
      }
      [3] => object(stdClass)#23 (2) {
        ["time"] => string(19) ""
        ["status"] => string(57) ""
      }
      [4] => object(stdClass)#24 (2) {
        ["time"] => string(19) ""
        ["status"] => string(74) ""
      }
      [5] => object(stdClass)#25 (2) {
        ["time"] => string(19) ""
        ["status"] => string(112) ""
      }
    }
  }

}

    
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值