mengluo

 /**
     * 测试guzzle
     *
     * @return void
     */
    public function index()
    {
        $client = new GuzzleHttp\Client();
        //12306抓取票价
        $request = new Request(\'get\', \'https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2018-12-14&leftTicketDTO.from_station=ZZF&leftTicketDTO.to_station=BJP&purpose_codes=ADULT\');
        $response = $client->send($request, [\'timeout\' => 2]);
        $code = $response->getStatusCode(); // 200
        $reason = $response->getReasonPhrase(); // OK
        $length= $response->getHeader(\'Content-Length\');
        $body = $response->getBody();
        $stringBody = (string) $body;
     
        $arr = json_decode($stringBody,true);

        $result=$arr[\'data\'][\'result\'];
        
         $text=array();
        foreach($result as $urls)
        {
            $text[]=explode(\'|\',$urls);
        }
        var_dump($text);
        //https://kyfw.12306.cn/otn/resources/js/framework/station_name.js?station_version=1.9048
        //3 车次 4 出发站  5 到达站  6 经过站(出发站)  7  到达站 8 经过站开发时间 9 到达终点站时间 10 历时 
        //11 不知道 12 不知道 13 出发时间   29 无座 28 硬座 27 软座  26 硬卧 25 动卧 24 不知道 23 软卧 22 不知道 21 高级软卧        14-29 目前不知道 30 二等座 31 一等座 32 商务座特等座  
        // 普通K:21:软卧、 24:无座  25:  26:硬卧  27:硬座  
        // 普通T:19:高级软  20:其它  21:软卧  24:无座  26:硬卧  27:硬座
        // 普通Z:19:高级软  21:软卧  24:无座  26:硬卧  27:硬座
        // 普通Y:22:软座   24:无座  27:硬座
        // 高铁G:23:特等   24:无座  28:二等  29:一等  30:商务
        // 城际C:23:特等   24:无座  28:二等  29:一等  30:商务 
        // 动车D:21:软卧   24:无座  28:二等  29:一等  31:动卧 
        
        
        // 其他车:21:软卧  24:无座  26:硬卧  27:硬座
        
    }





分类:

技术点:

相关文章:

  • 2021-12-23
  • 2021-04-10
  • 2021-06-21
  • 2021-10-23
  • 2022-01-28
  • 2021-07-07
  • 2022-12-23
猜你喜欢
  • 2022-01-02
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-11-27
相关资源
相似解决方案