首页 火车查询 火车查询示例代码 余票查询[PHP]

余票查询示例代码[PHP]

作者: 阅读数:1224 上传时间:2016-03-10

余票查询

<?php

require_once 'curl.func.php';

$appkey = 'your_appkey_here';//你的appkey
$start = '杭州';//utf8
$end = '北京';//utf8
$date = date('Y-m-d');
$url = "https://api.jisuapi.com/train/ticket?appkey=$appkey&start=$start&end=$end&date=$date";
$result = curlOpen($url, ['ssl'=>true]);
$jsonarr = json_decode($result, true);
//exit(var_dump($jsonarr));
if($jsonarr['status'] != 0)
{
    echo $jsonarr['msg'];
    exit();
}

foreach($jsonarr['result'] as $val)
{
    echo $val['trainno'].' '.$val['type'].' '.$val['station'].' '.$val['endstation'].' '.$val['departuretime'].' '.$val['arrivaltime'].' '.$val['numsw'].'
'; } function gb2utf8($gbstr) { return iconv('gbk','utf-8//ignore',$gbstr); }