PHP Express Interface API

Source: Internet
Author: User

<?PHPHeader("Content-type:text/html;charset=utf-8");/** * Express.class.php Express Query class * * @copyright Chzeze * @lastmodify 2015-10-27*/classExpress {Private $expressname=Array();//package The name of the Courier        function__construct () {$this->expressname =$this-Expressname (); }        /** How to collect Web content*/    Private functionGetContent ($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; }    /** method for obtaining the corresponding name and corresponding value*/    Private functionExpressname () {$result=$this->getcontent ("http://www.kuaidi100.com/"); //crawl Express name corresponding to the Courier code        Preg_match_all("/data\-code\=\" (? p<name_code>\w+) \ "\> (? p<name>.*) \<\/a>/iu ",$result,$data);//(? p<name>) regular match stored characters        $name=Array(); //var_dump ($data [' name ']); echo "<br>";        foreach($data[' Name '] as $k=$v){            $name[$v] =$data[' Name_code '] [$k];//Example: $name [Zhong Tong]=zhontong            Echo"[".$v."] =".$name[$v]." <br> ";//Get Courier Code        }            Echo"One query". " <br> "; return $name; }        /** Method of parsing an object array * @param $json input Object Arrays * Return $data array*/    Private functionJson_array ($json){        if($json){            foreach((Array)$json  as $k=$v){                $data[$k] = !is_string($v)?$this->json_array ($v):$v; }            return $data; }    }        /** Return $data array Express arrays * @param $name Express Name * Support input of the courier name is as follows * (Shen Tong-ems-Shun Fung-Yuantong-Zhong Tong-such as Wind Tatsu-Yun da-day-to-pass-all Peak-Darbond-Home delivery-An Sinda-Parcel Mail-FedEx Logistics * DHL Express-OTA Logistics-Germany State Logistics-ems Domestic-ems International-e-mail-van Courier-All customer delivery-Guo Tong Express-registered-total speed-International parcel * Huitong Express-Huayu Logistics-hui Qiang Express-Jia Ji Express-Jia Yi Logistics-Canada Post-fast Czech Express-Longbang Express-FedEx-Union Hao Tong * can reach Courier-such as wind-Sweden post-all one Express-Pang Express-full-day pass-Shentong Express-Shun Fung Express-Express Courier-tnt Express-Daily Express * heaven and earth Huayu-ups Express-new state logistics-new Egg Logistics-Hongkong Post-Yuantong Express-Yun da Express-Post        Package--------Express----------------------------@param $order Express number * $data [' Ischeck '] ==1 has signed * $data [' data '] Status of express real-time query array*/     Public  functionGetOrder ($name,$order){        $keywords=$this->expressname[$name]; //Var_dump ($keywords);        $result=$this->getcontent ("http://www.kuaidi100.com/query?type={$keywords}&postid={$order}"); $result= Json_decode ($result); $data=$this->json_array ($result); return $data; }}$a=NewExpress ();$result=$a->getorder ("Shun Fung", 688625443900);Var_dump($result);/*for ($num =688625443009; $num <=688625443999; $num + +) {$result = $a->getorder ("Shun Fung", $num);    Var_dump ($result); echo "<br>";}*/?>

PHP Express Interface API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.