Home > php教程 > php手册 > 微信公众平台开发(43)火车时刻查询

微信公众平台开发(43)火车时刻查询

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 11:28:47
Original
1362 people have browsed it

微信公众平台开发 微信公众平台开发模式 企业微信公众平台 火车票接口 列车时刻接口 火车车次查询
作者:方倍工作室 
原文: http://www.cnblogs.com/txw1958/p/weixin-43-train.html

 

一、火车查询接口

在百度找到去哪儿的接口

http://train.qunar.com/qunar/checiInfo.jsp?ex_track=<span &q</span>=t110<span &format</span>=json<span &cityname</span>=123456<span &ver</span>=1373813217828<span &callback</span>=XQScript_5
Copy after login

q为车次
ver为当前毫秒时间戳
cityname按车次查询时为123456

二、结果数据

<span string(3634) "XQScript_5(
{"ticketInfo":
{"2192\/2193":[
{"pr":88.5,"type":"硬座"},
{"pr":183.5,"type":"硬卧中"},
{"pr":304.5,"type":"软卧下"}]},"trainInfo":
{"2192\/2193":
{"arriCity_py":"zhengzhou","istmp":false,"code":"2192\/2193","deptCity_py":"wenzhou","arriStation":"郑州","arriCity":"郑州","trainType":"普快","deptTime":"13:52","deptStation":"温州","deptCity":"温州","arriTime":"14:20","interval":"1天28分"}},"trainScheduleHead":["站次","站名","日期","到达时间","开车时间","停车时间","里程","硬座","软座","二等软座","一等软座","硬卧上\/中\/下","软卧上\/下"],"extInfo":
{"allMileage":"1496公里","allTime":"1天28分"},"trainScheduleBody":[
{"mxl":34521376777470,"content":[83,"长兴南","第一天","23:25","23:29","4分","575公里",110,"0","0","0","154\/157\/160","204\/210"]},
{"content":[34,"武义","第一天","17:31","17:33","2分","222公里",46.5,"0","0","0","80.5\/83.5\/85.5","107.5\/111.5"]},
{"content":[17,"丽水","第一天","16:00","16:03","3分","136公里",24.5,"0","0","0","58.5\/61.5\/63.5","81.5\/85.5"]},
{"content":[62,"芜湖","第二天","01:53","02:00","7分","753公里",99,"0","0","0","153\/157\/161","217\/224"]},
{"content":[24,"宣城","第二天","00:55","01:03","8分","689公里",57,"0","0","0","107\/110\/114","165\/173"]},
{"content":[45,"德清西","第一天","22:27","22:37","10分","517公里",70,"0","0","0","111\/113\/116","156\/161"]},
{"content":[55,"缙云","第一天","16:35","16:37","2分","168公里",63.5,"0","0","0","97.5\/100.5\/102.5","122.5\/126.5"]},
{"content":[93,"永康","第一天","17:08","17:11","3分","201公里",104.5,"0","0","0","138.5\/141.5\/143.5","164.5\/168.5"]},
{"content":[76,"青田","第一天","14:44","14:48","4分","57公里",78,"0","0","0","112\/115\/117","131.5\/135.5"]},
{"content":[38,"温州","-","起点站","13:52","-",0,37,0,0,0,"37\/37\/37","37\/37"]},
{"content":[51,"杭州","第一天","21:30","21:44","14分","449公里",73.5,"0","0","0","110.5\/113.5\/115.5","150.5\/155.5"]},
{"mxl":16076029707508,"content":[58,"亳州","第二天","10:15","10:22","7分","1219公里",114.5,"0","0","0","190.5\/196.5\/202.5","288.5\/300.5"]},
{"mxl":7253046021614,"content":[79,"淮南","第二天","05:49","05:55","6分","989公里",125.5,"0","0","0","191.5\/196.5\/201.5","274.5\/284.5"]},
{"mxl":19294423176992,"content":[69,"开封","第二天","13:10","13:24","14分","1424公里",131.5,"0","0","0","216.5\/223.5\/230.5","328.5\/341.5"]},
{"content":[100,"巢湖","第二天","02:53","02:59","6分","830公里",140,"0","0","0","198\/202\/207","269\/278"]},
{"content":[41,"合肥","第二天","03:54","04:14","20分","894公里",82,"0","0","0","142\/146\/151","216\/225"]},
{"content":[13,"义乌","第一天","19:41","19:46","5分","310公里",28.5,"0","0","0","62.5\/65.5\/67.5","93.5\/97.5"]},
{"content":[20,"阜阳","第二天","07:50","08:20","30分","1115公里",71.5,"0","0","0","143.5\/148.5\/154.5","234.5\/245.5"]},
{"content":[96,"商丘","第二天","11:17","11:21","4分","1293公里",153.5,"0","0","0","232.5\/238.5\/244.5","333.5\/345.5"]},
{"content":[72,"金华西","第一天","18:52","19:07","15分","262公里",85.5,"0","0","0","119.5\/122.5\/124.5","148.5\/152.5"]},
{"content":[31,"兰考","第二天","12:29","12:39","10分","1381公里",91.5,"0","0","0","174.5\/181.5\/187.5","282.5\/295.5"]},
{"mxl":16683831947510,"content":[107,"郑州","第二天","14:20","终到站","-","1496公里",170.5,"0","0","0","258.5\/265.5\/272.5","372.5\/386.5"]},
{"mxl":9451012451240,"content":[90,"民权","第二天","12:04","12:07","3分","1345公里",149.5,"0","0","0","230.5\/236.5\/243.5","335.5\/347.5"]}]});"</span>
Copy after login

三、源代码

<?<span php
</span><span var_dump</span>(getTrainInfo("t110"<span ));

</span><span function</span> getTrainInfo(<span $line</span><span )
{
    </span><span $curTime</span> = <span explode</span> (" ", <span microtime</span><span ());  
    </span><span $curMicroTime</span> = <span round</span>(<span $curTime</span>[1].(<span $curTime</span>[0]*1000<span ));
    </span><span $url</span> = "http://train.qunar.com/qunar/checiInfo.jsp?ex_track=&q=".<span $line</span>."&format=json&cityname=123456&ver=".<span $curMicroTime</span>."&callback=XQScript_5"<span ;

    </span><span $headers</span> = <span array</span><span (
        </span>"User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1",
        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
        "Accept-Language: en-us,en;q=0.5",
        <span //</span><span "Accept-Encoding: gzip, deflate",</span>
        "Referer: http://train.qunar.com/list_num.htm?fromStation=".<span $line</span><span 
    );
    </span><span $ch</span> =<span  curl_init();
    curl_setopt(</span><span $ch</span>, CURLOPT_URL, <span $url</span><span );
    curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, 1<span );
    curl_setopt(</span><span $ch</span>, CURLOPT_HTTPHEADER, <span $headers</span><span ); 
    </span><span $result</span> = curl_exec(<span $ch</span><span );
    curl_close(</span><span $ch</span><span );
    
    </span><span return</span> <span $result</span><span ;
}
</span>?>
Copy after login

 

四、遗留问题

返回数据不是按顺序排列的。。。。。。
需要再找排列的算法

 

 

 

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template