首页 > 建站资源 > 微信营销 > 微信公众平台开发教程之火车时刻查询应用代码实例

微信公众平台开发教程之火车时刻查询应用代码实例

时间:2013-08-25    来源:方倍工作室

一、火车查询接口

在百度找到去哪儿的接口

http://train.qunar.com/qunar/checiInfo.jsp?ex_track=&q=t110&format=json&cityname=123456&ver=1373813217828&callback=XQScript_5
  • q为车次
  • ver为当前毫秒时间戳
  • cityname按车次查询时为123456

二、结果数据

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"]}]});"

三、源代码

<?php
var_dump(getTrainInfo("t110"));

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

    $headers = array(
        "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",
        //"Accept-Encoding: gzip, deflate",
        "Referer: http://train.qunar.com/list_num.htm?fromStation=".$line
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    $result = curl_exec($ch);
    curl_close($ch);
    
    return $result;
}
?>

四、遗留问题

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

相关推荐
从10个要点对比传统APP与微信端APP的优劣
微信成功的背后是什么?
杭州微车队通过微信实现分布式社会化协作的案例思考
微信公众帐号消息接口开发教程之桃花运测试应用
微信小小表情符号背后的经济价值
微信公众平台开发之疯狂猜图
微信公众平台应用开发之情侣/夫妻相
自助快速生成微信APP的腾讯风铃介绍
微信创业赚钱的八个方向
微信公众平台开发教程之刮刮乐应用
微信公众帐号开发教程之Emoji表情符号介绍
微信公众账号的Web App平台化设想
微信5.0的APP平台战略
基于微信平台开发的十大火爆应用TOP10
微信医疗平台上线:挂号缴费拿药无需久等
我们是怎么患上“微信角标强迫症”的?
2016微信公开课:张小龙称微信将推出应用号
微信“应用号”登台 独立APP怎么办?
张小龙说的应用号是个什么鬼?Vpp时代或许即将来临
微信应用号的野心
5岁微信商业化之路:广告到应用号哪个靠谱?
应用号会带来啥变化?把微信变成互联网操作系统
微信搜索悄然升级 应用号初现端倪 看看三大猜想
别开发App了 微信公众号才是未来!
所谓的“微信OS” 能否掀起HTML5的二次革命呢?
五大问题全面剖析微信应用号:飓风将至 准备好没?
“应用号”到“小程序” 张小龙的葫芦里卖的啥药?
微信应用号长这样 据说它会杀死APP
一篇文章读懂微信应用号是什么 是否值得投入做?
微信小程序开发:微信放出公众平台小程序文档和工具
为什么你觉得只开发微信应用号是不行的?
微信公众平台消息接口使用教程
微信公众平台教程:没有正确响应Token验证的解决方法
微信公众平台消息接口开发教程之语音触发应用
微信公众平台接口开发教程之人脸识别应用
微信公众平台消息接口开发之小黄鸡机器人应用

精彩推荐

热门教程