PHP cURL学习-快递查询

大二学了一下PHP cURL,做了几个demo。

1、代码如下:

index.php

<html>
<head>
    <title>快递查询</title>
    <meta charset="utf-8">
    <meta name="description" content="快递查询">
    <style type="text/css">
        *{margin: 0;padding: 0;border: 0;}
        body{background-color: rgb(240,240,240);font-family: Microsoft YaHei;}
        p{padding-bottom: 10px;}
        .p_input{width: 100%;height: 50px;outline: 0;padding-left: 50px;font-family: Microsoft YaHei;font-size: 16px;}
        .p_sub{width: 100%;height: 50px;font-family: Microsoft YaHei;background-color: rgb(90,215,0);color: #fff;font-size: 16px;}

        .result_p{width: 95%;padding-left: 5%;height: 60px;display: block;line-height: 60px;background-color: #f8f8f8;}
        .result_p0{
            width: 95%;
            height: 40px;
            display: block;
            padding-left: 5%;
            line-height: 40px;
            font-size: 14px;
            background-color: #fff;
            transition: background-color .5s ease; 
        }
        .result_p1{
            width: 95%;
            height: 60px;
            display: block;
            padding-left: 5%;
            line-height: 32px;
            font-size: 14px;
            background-color: #f8f8f8;
            transition: background-color .5s ease; 
        }
        .result_s{font-size: 12px;text-align: center;margin-top: 20px;}
    </style>
</head>

<body>
    <form method="post">
        <p><input class="p_input" name="kuaidi" type="number" placeholder="请输入单号" maxlength="30" value=""></p>
        <p><input id='show-toast' class="p_sub" name="submit" type="submit" value="查询" οnclick="return form_onsubmit(this.form)"/></p>
    </form>
    <script type="text/javascript">
        function form_onsubmit(obj){   
            if(obj.kuaidi.value == "") {
                alert("亲~请输入单号");
                return false;
            }  
            else{
                // $(document).on("click", "#show-toast", function() {
                //     $.toast("操作成功", function() {
                //         console.log('close');
                //     });
                // })
                return true;
            }
        }
    </script>
    <!-- <script>
    $(function() {
    FastClick.attach(document.body);
    });
    </script> -->
</body>
</html>

<?php 
    error_reporting(0);
    if(isset($_POST['submit'])){
        include 'search.php';
        $k = new kuaidi_query($_POST['kuaidi']);
        $res = $k->kuaidi_query_number();
        // var_dump($res);
        
        if ($res['message']=='ok') {
            $res01 = $res['data'];
            echo("<p class='result_p'>快递单号:$_POST[kuaidi]</p>");
            foreach ($res01 as $key => $value) {
                // var_dump ($key);
                $res02 = $value;
                echo("<p class='result_p0'>$res02[time]</p>");
                echo("<p class='result_p1'>$res02[context]</p>");
            }
            echo ("<p class='result_s'>以上数据来之快递100、快递查询网</p>");
        }
        else {
        // echo $jsondata['msg'];
echo<<<begin2
        <br/>
        <p align="center">抱歉,您输入的快递单号有误或者服务器繁忙!</p>
begin2;
        }
    }

?>

<p align="center" style="font-size: 12px;margin-top: 20px;">by 赛亚王子_Vegeta</p>

search.php

<?php
  /**
  * kuaidi_query
  */
  class kuaidi_query
  {
    private $kuaidi;
    private $get_data;
    
    public function __construct($get_data)
    {
      $this->kuaidi = $get_data;
    }

    public function object_array($array)
    {
       if(is_object($array))
       {
        $array = (array)$array;
       }
       if(is_array($array))
       {
        foreach($array as $key=>$value)
        {
         $array[$key] = $this->object_array($value);
        }
       }
       return $array;
    }

    public function kuaidi_query_number(){
      $kuaidi = $_POST['kuaidi'];
      $company = file_get_contents("http://m.kuaidi100.com/autonumber/auto?num=".$kuaidi);
      preg_match_all('/"(.*?)"/',$company,$match);
      $company = $match[1][1];
      $company = file_get_contents("http://m.kuaidi100.com/query?type=".$company."&postid=".$kuaidi."&id=1&valicode=");
      $c= json_decode($company); 
      $array = $this->object_array($c);
      return $array;
    }

    

  }


?>

2、效果截图








评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值