• ThinkPhp3.2快递100 查询类 何苦


    //调用单号 查询出快递名称
    $waybillCode = '778880350676';
    $res = expressinfo($waybillCode);
    $trace = $res['data'];
    $express = $this->traceExpress();
    foreach ($express as $key => $value) {
        if ($res['com'] == $key) {
            $comName = $value;
            break;
        } else {
            $comName = '暂无匹配';
        }
    }
    $this->assign('trace', $trace); //快递信息
    $this->assign('comName', $comName);//快递名称
    
    public function traceExpress()
    {
        $express = array(
            'aae'            => 'aae全球专递',
            'anjie'          => '安捷快递',
            'anxindakuaixi'  => '安信达快递',
            'biaojikuaidi'   => '彪记快递',
            'datianwuliu'    => '大田物流',
            'debangwuliu'    => '德邦物流',
            'ems'            => 'ems快递',
            'guotongkuaidi'  => '国通快递',
            'huitongkuaidi'  => '汇通快运',
            'jixianda'       => '急先达',
            'kuaijiesudi'    => '快捷速递',
            'quanfengkuaidi' => '全峰快递',
            'rufengda'       => '如风达',
            'shentong'       => '申通',
            'shunfeng'       => '顺丰',
            'tiantian'       => '天天快递',
            'xinfengwuliu'   => '信丰物流',
            'yibangwuliu'    => '一邦速递',
            'yuantong'       => '圆通速递',
            'yunda'          => '韵达快运',
            'zhaijisong'     => '宅急送',
            'zhongtong'      => '中通速递',
            'jd'             => '京东快递'
        );
        return $express;
    }
    
    
    //根据快递单号查询物流信息函数
    function expressinfo($order)
    {
        header('Content-Type:text/html; charset=utf-8');
        $express = new \Think\Express();
        $result = $express->getorder($order);
        // var_dump($result);
        return $result;
    }
    
    
    /**
     * Express.class.php 快递查询类 v1.0
     *
     * @copyright        福星高照
     * @license          http://www.25531.com
     * @lastmodify       2014-08-22
     */
    namespace Think;
    class Express
    {
        /*
         * 网页内容获取方法
        */
        private function getcontent($url)
        {
            if (function_exists("file_get_contents")) {
                $file_contents = file_get_contents($url);
            } else {
                $ch = curl_init();
                $timeout = 5;
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
                $file_contents = curl_exec($ch);
                curl_close($ch);
            }
            return $file_contents;
        }
    
        /*
         * 获取对应名称和对应传值的方法
        */
        private function expressname($order)
        {
            $name = json_decode($this->getcontent("http://www.kuaidi100.com/autonumber/auto?num={$order}"), true);
            $result = $name[0]['comCode'];
            if (empty($result)) {
                return false;
            } else {
                return $result;
            }
        }
    
        /*
         * 返回$data array      快递数组查询失败返回false
         * @param $order        快递的单号
         * $data['ischeck'] ==1 已经签收
         * $data['data']        快递实时查询的状态 array
        */
        public function getorder($order)
        {
            $keywords = $this->expressname($order);
            if (!$keywords) {
                return false;
            } else {
                $result = $this->getcontent("http://www.kuaidi100.com/query?type={$keywords}&postid={$order}");
                $data = json_decode($result, true);
                return $data;
            }
        }
    }
    
  • 相关阅读:
    常见SQL语句
    测试用例的设计
    移动端测试注意事项
    markdown编辑模式基本使用
    常用修改请求或返回方法
    前端性能测试工具Lighthouse
    presto环境部署
    pyenv管理python版本
    python2.6.6升级python2.7.14
    InfluxDB权限认证机制
  • 原文地址:https://www.cnblogs.com/fuqian/p/16026581.html
Copyright © 2020-2023  润新知