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

车次查询示例代码[PHP]

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

车次查询

<?php

require_once 'curl.func.php';

$appkey = 'your_appkey_here';//你的appkey
$trainno = 'G34';
$url = "https://api.jisuapi.com/train/line?appkey=$appkey&trainno=$trainno";
$result = curlOpen($url, ['ssl'=>true]);
$jsonarr = json_decode($result, true);
//exit(var_dump($jsonarr));
if($jsonarr['status'] != 0)
{
    echo $jsonarr['msg'];
    exit();
}
$result = $jsonarr['result'];
if(empty($result))
{
    echo '车次不存在';
    exit();
}
echo $result['trainno'].' '.$result['type'].'
'; foreach($result['list'] as $val) { echo $val['sequenceno'].' '.$val['station'].' '.$val['arrivaltime'].' '.$val['departuretime'].' '.$val['stoptime'].'
'; }