火车票查询
其他 官方文档
火车票查询,数据来源于途牛
基本说明:
接口地址:https://huoche.tuniu.com/yii.php
返回格式:json
请求方式:get/post
请求示例:http://huoche.tuniu.com/yii.php?r=train/trainTicket/getTickets&primary[departureDate]=
请求参数说明:
名称 类型 必填 说明
r string 必填 固定值:train/trainTicket/getTickets
primary[departureDate] string 必填 发车日期,yyyy-MM-dd 格式
primary[departureCityName] string 必填 出发站
primary[arrivalCityName] string 必填 到达站
返回参数说明:
名称 类型 说明
- - 见json
JSON返回示例:
{
	"code": 200,
	"data": {
		"count": 10,
		"stores": null,
		"unsureStores": null,
		"trainTypeDetails": [{
			"trainType": 0,
			"number": 10,
			"trainTypeName": "G-高铁"
		}],
		"streamId": null,
		"remark": null,
		"isFinish": null,
		"lastTime": 1627903868000,
		"expire": false,
		"freshUrl": null,
		"reserveUrls": null,
		"crossURL": null,
		"origin": null,
		"list": [{
			"trainId": 167072,
			"trainNum": "G7072",
			"trainType": 0,
			"trainTypeName": "高铁",
			"departStationName": "上海",
			"destStationName": "池州",
			"departDepartTime": "06:06",
			"destArriveTime": "09:49",
			"duration": 223,
			"prices": [{
				"leftNumber": 18,
				"seatStatus": "",
				"seat": 2,
				"price": 353.5,
				"stuPrice": null,
				"promotionPrice": 353.5,
				"resId": 1505436892,
				"detail": [],
				"priceMemo": null,
				"seatName": "一等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 3,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436893,
				"detail": [],
				"priceMemo": null,
				"seatName": "二等座"
			}, {
				"leftNumber": 4,
				"seatStatus": "",
				"seat": 1,
				"price": 412.5,
				"stuPrice": null,
				"promotionPrice": 412.5,
				"resId": 2050079131,
				"detail": [],
				"priceMemo": null,
				"seatName": "特等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 9,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436894,
				"detail": [],
				"priceMemo": null,
				"seatName": "无座"
			}],
			"durationDay": 1,
			"departStationType": 0,
			"destStationType": 2,
			"saleStatus": 0,
			"departStationId": 1175075,
			"destStationId": 1176185,
			"startSaleTime": "",
			"canChooseSeat": 0,
			"memo": "",
			"departureCityCode": 2500,
			"arrivalCityCode": 109,
			"departureCityName": "上海",
			"arrivalCityName": "池州",
			"upOrDown": 0,
			"trainStartDate": "2021-08-03",
			"accessByIdcard": "Y",
			"durationStr": "3小时43分钟",
			"departStationTypeName": "ticketbtn",
			"destStationTypeName": "",
			"sellOut": 0
		}, {
			"trainId": 167076,
			"trainNum": "G7076",
			"trainType": 0,
			"trainTypeName": "高铁",
			"departStationName": "上海",
			"destStationName": "池州",
			"departDepartTime": "06:19",
			"destArriveTime": "10:01",
			"duration": 222,
			"prices": [{
				"leftNumber": 19,
				"seatStatus": "",
				"seat": 2,
				"price": 353.5,
				"stuPrice": null,
				"promotionPrice": 353.5,
				"resId": 1505436895,
				"detail": [],
				"priceMemo": null,
				"seatName": "一等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 3,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436896,
				"detail": [],
				"priceMemo": null,
				"seatName": "二等座"
			}, {
				"leftNumber": 8,
				"seatStatus": "",
				"seat": 1,
				"price": 412.5,
				"stuPrice": null,
				"promotionPrice": 412.5,
				"resId": 1723403266,
				"detail": [],
				"priceMemo": null,
				"seatName": "特等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 9,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436897,
				"detail": [],
				"priceMemo": null,
				"seatName": "无座"
			}],
			"durationDay": 1,
			"departStationType": 0,
			"destStationType": 2,
			"saleStatus": 0,
			"departStationId": 1175075,
			"destStationId": 1176185,
			"startSaleTime": "",
			"canChooseSeat": 0,
			"memo": "",
			"departureCityCode": 2500,
			"arrivalCityCode": 109,
			"departureCityName": "上海",
			"arrivalCityName": "池州",
			"upOrDown": 0,
			"trainStartDate": "2021-08-03",
			"accessByIdcard": "Y",
			"durationStr": "3小时42分钟",
			"departStationTypeName": "ticketbtn",
			"destStationTypeName": "",
			"sellOut": 0
		}, {
			"trainId": 167132,
			"trainNum": "G7132",
			"trainType": 0,
			"trainTypeName": "高铁",
			"departStationName": "上海虹桥",
			"destStationName": "池州",
			"departDepartTime": "09:41",
			"destArriveTime": "13:04",
			"duration": 203,
			"prices": [{
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 2,
				"price": 353.5,
				"stuPrice": null,
				"promotionPrice": 353.5,
				"resId": 1505436901,
				"detail": [],
				"priceMemo": null,
				"seatName": "一等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 3,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436902,
				"detail": [],
				"priceMemo": null,
				"seatName": "二等座"
			}, {
				"leftNumber": 17,
				"seatStatus": "",
				"seat": 0,
				"price": 686.5,
				"stuPrice": null,
				"promotionPrice": 686.5,
				"resId": 1505436900,
				"detail": [],
				"priceMemo": null,
				"seatName": "商务座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 9,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436903,
				"detail": [],
				"priceMemo": null,
				"seatName": "无座"
			}],
			"durationDay": 1,
			"departStationType": 0,
			"destStationType": 2,
			"saleStatus": 0,
			"departStationId": 1175076,
			"destStationId": 1176185,
			"startSaleTime": "",
			"canChooseSeat": 0,
			"memo": "",
			"departureCityCode": 2500,
			"arrivalCityCode": 109,
			"departureCityName": "上海",
			"arrivalCityName": "池州",
			"upOrDown": 0,
			"trainStartDate": "2021-08-03",
			"accessByIdcard": "Y",
			"durationStr": "3小时23分钟",
			"departStationTypeName": "ticketbtn",
			"destStationTypeName": "",
			"sellOut": 0
		}, {
			"trainId": 167136,
			"trainNum": "G7136",
			"trainType": 0,
			"trainTypeName": "高铁",
			"departStationName": "上海虹桥",
			"destStationName": "池州",
			"departDepartTime": "10:30",
			"destArriveTime": "14:07",
			"duration": 217,
			"prices": [{
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 2,
				"price": 353.5,
				"stuPrice": null,
				"promotionPrice": 353.5,
				"resId": 1505436904,
				"detail": [],
				"priceMemo": null,
				"seatName": "一等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 3,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436905,
				"detail": [],
				"priceMemo": null,
				"seatName": "二等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 9,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436906,
				"detail": [],
				"priceMemo": null,
				"seatName": "无座"
			}],
			"durationDay": 1,
			"departStationType": 0,
			"destStationType": 2,
			"saleStatus": 0,
			"departStationId": 1175076,
			"destStationId": 1176185,
			"startSaleTime": "",
			"canChooseSeat": 0,
			"memo": "",
			"departureCityCode": 2500,
			"arrivalCityCode": 109,
			"departureCityName": "上海",
			"arrivalCityName": "池州",
			"upOrDown": 0,
			"trainStartDate": "2021-08-03",
			"accessByIdcard": "Y",
			"durationStr": "3小时37分钟",
			"departStationTypeName": "ticketbtn",
			"destStationTypeName": "",
			"sellOut": 0
		}, {
			"trainId": 167060,
			"trainNum": "G7060",
			"trainType": 0,
			"trainTypeName": "高铁",
			"departStationName": "上海",
			"destStationName": "池州",
			"departDepartTime": "10:41",
			"destArriveTime": "14:23",
			"duration": 222,
			"prices": [{
				"leftNumber": 12,
				"seatStatus": "",
				"seat": 2,
				"price": 353.5,
				"stuPrice": null,
				"promotionPrice": 353.5,
				"resId": 1975379783,
				"detail": [],
				"priceMemo": null,
				"seatName": "一等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 3,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1975379784,
				"detail": [],
				"priceMemo": null,
				"seatName": "二等座"
			}, {
				"leftNumber": 7,
				"seatStatus": "",
				"seat": 0,
				"price": 686.5,
				"stuPrice": null,
				"promotionPrice": 686.5,
				"resId": 1975379782,
				"detail": [],
				"priceMemo": null,
				"seatName": "商务座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 9,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1975379785,
				"detail": [],
				"priceMemo": null,
				"seatName": "无座"
			}],
			"durationDay": 1,
			"departStationType": 0,
			"destStationType": 2,
			"saleStatus": 0,
			"departStationId": 1175075,
			"destStationId": 1176185,
			"startSaleTime": "",
			"canChooseSeat": 0,
			"memo": "",
			"departureCityCode": 2500,
			"arrivalCityCode": 109,
			"departureCityName": "上海",
			"arrivalCityName": "池州",
			"upOrDown": 0,
			"trainStartDate": "2021-08-03",
			"accessByIdcard": "Y",
			"durationStr": "3小时42分钟",
			"departStationTypeName": "ticketbtn",
			"destStationTypeName": "",
			"sellOut": 0
		}, {
			"trainId": 167088,
			"trainNum": "G7088",
			"trainType": 0,
			"trainTypeName": "高铁",
			"departStationName": "上海",
			"destStationName": "池州",
			"departDepartTime": "12:50",
			"destArriveTime": "16:22",
			"duration": 212,
			"prices": [{
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 2,
				"price": 353.5,
				"stuPrice": null,
				"promotionPrice": 353.5,
				"resId": 1505436908,
				"detail": [],
				"priceMemo": null,
				"seatName": "一等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 3,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436909,
				"detail": [],
				"priceMemo": null,
				"seatName": "二等座"
			}, {
				"leftNumber": 17,
				"seatStatus": "",
				"seat": 0,
				"price": 686.5,
				"stuPrice": null,
				"promotionPrice": 686.5,
				"resId": 1505436907,
				"detail": [],
				"priceMemo": null,
				"seatName": "商务座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 9,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436910,
				"detail": [],
				"priceMemo": null,
				"seatName": "无座"
			}],
			"durationDay": 1,
			"departStationType": 0,
			"destStationType": 2,
			"saleStatus": 0,
			"departStationId": 1175075,
			"destStationId": 1176185,
			"startSaleTime": "",
			"canChooseSeat": 0,
			"memo": "",
			"departureCityCode": 2500,
			"arrivalCityCode": 109,
			"departureCityName": "上海",
			"arrivalCityName": "池州",
			"upOrDown": 0,
			"trainStartDate": "2021-08-03",
			"accessByIdcard": "Y",
			"durationStr": "3小时32分钟",
			"departStationTypeName": "ticketbtn",
			"destStationTypeName": "",
			"sellOut": 0
		}, {
			"trainId": 167140,
			"trainNum": "G7140",
			"trainType": 0,
			"trainTypeName": "高铁",
			"departStationName": "上海虹桥",
			"destStationName": "池州",
			"departDepartTime": "14:54",
			"destArriveTime": "18:27",
			"duration": 213,
			"prices": [{
				"leftNumber": 15,
				"seatStatus": "",
				"seat": 2,
				"price": 353.5,
				"stuPrice": null,
				"promotionPrice": 353.5,
				"resId": 1505436916,
				"detail": [],
				"priceMemo": null,
				"seatName": "一等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 3,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436917,
				"detail": [],
				"priceMemo": null,
				"seatName": "二等座"
			}, {
				"leftNumber": 4,
				"seatStatus": "",
				"seat": 1,
				"price": 412.5,
				"stuPrice": null,
				"promotionPrice": 412.5,
				"resId": 2050079132,
				"detail": [],
				"priceMemo": null,
				"seatName": "特等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 9,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1505436918,
				"detail": [],
				"priceMemo": null,
				"seatName": "无座"
			}],
			"durationDay": 1,
			"departStationType": 0,
			"destStationType": 2,
			"saleStatus": 0,
			"departStationId": 1175076,
			"destStationId": 1176185,
			"startSaleTime": "",
			"canChooseSeat": 0,
			"memo": "",
			"departureCityCode": 2500,
			"arrivalCityCode": 109,
			"departureCityName": "上海",
			"arrivalCityName": "池州",
			"upOrDown": 0,
			"trainStartDate": "2021-08-03",
			"accessByIdcard": "Y",
			"durationStr": "3小时33分钟",
			"departStationTypeName": "ticketbtn",
			"destStationTypeName": "",
			"sellOut": 0
		}, {
			"trainId": 167592,
			"trainNum": "G7592",
			"trainType": 0,
			"trainTypeName": "高铁",
			"departStationName": "上海虹桥",
			"destStationName": "池州",
			"departDepartTime": "16:24",
			"destArriveTime": "20:22",
			"duration": 238,
			"prices": [{
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 2,
				"price": 353.5,
				"stuPrice": null,
				"promotionPrice": 353.5,
				"resId": 1506024397,
				"detail": [],
				"priceMemo": null,
				"seatName": "一等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 3,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1506024398,
				"detail": [],
				"priceMemo": null,
				"seatName": "二等座"
			}, {
				"leftNumber": 8,
				"seatStatus": "",
				"seat": 0,
				"price": 686.5,
				"stuPrice": null,
				"promotionPrice": 686.5,
				"resId": 1506024396,
				"detail": [],
				"priceMemo": null,
				"seatName": "商务座"
			}, {
				"leftNumber": 0,
				"seatStatus": "",
				"seat": 9,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1506024399,
				"detail": [],
				"priceMemo": null,
				"seatName": "无座"
			}],
			"durationDay": 1,
			"departStationType": 2,
			"destStationType": 2,
			"saleStatus": 0,
			"departStationId": 1175076,
			"destStationId": 1176185,
			"startSaleTime": "",
			"canChooseSeat": 0,
			"memo": "",
			"departureCityCode": 2500,
			"arrivalCityCode": 109,
			"departureCityName": "上海",
			"arrivalCityName": "池州",
			"upOrDown": 0,
			"trainStartDate": "2021-08-03",
			"accessByIdcard": "Y",
			"durationStr": "3小时58分钟",
			"departStationTypeName": "",
			"destStationTypeName": "",
			"sellOut": 0
		}, {
			"trainId": 167206,
			"trainNum": "G7206",
			"trainType": 0,
			"trainTypeName": "高铁",
			"departStationName": "上海虹桥",
			"destStationName": "池州",
			"departDepartTime": "17:33",
			"destArriveTime": "20:56",
			"duration": 203,
			"prices": [{
				"leftNumber": 16,
				"seatStatus": "",
				"seat": 2,
				"price": 353.5,
				"stuPrice": null,
				"promotionPrice": 353.5,
				"resId": 2060160182,
				"detail": [],
				"priceMemo": null,
				"seatName": "一等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 3,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 2060160183,
				"detail": [],
				"priceMemo": null,
				"seatName": "二等座"
			}, {
				"leftNumber": 10,
				"seatStatus": "",
				"seat": 0,
				"price": 686.5,
				"stuPrice": null,
				"promotionPrice": 686.5,
				"resId": 2060160181,
				"detail": [],
				"priceMemo": null,
				"seatName": "商务座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 9,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 2060160184,
				"detail": [],
				"priceMemo": null,
				"seatName": "无座"
			}],
			"durationDay": 1,
			"departStationType": 0,
			"destStationType": 1,
			"saleStatus": 0,
			"departStationId": 1175076,
			"destStationId": 1176185,
			"startSaleTime": "",
			"canChooseSeat": 0,
			"memo": "",
			"departureCityCode": 2500,
			"arrivalCityCode": 109,
			"departureCityName": "上海",
			"arrivalCityName": "池州",
			"upOrDown": 0,
			"trainStartDate": "2021-08-03",
			"accessByIdcard": "Y",
			"durationStr": "3小时23分钟",
			"departStationTypeName": "ticketbtn",
			"destStationTypeName": "ticketbtn",
			"sellOut": 0
		}, {
			"trainId": 167272,
			"trainNum": "G7272",
			"trainType": 0,
			"trainTypeName": "高铁",
			"departStationName": "上海",
			"destStationName": "池州",
			"departDepartTime": "18:43",
			"destArriveTime": "22:08",
			"duration": 205,
			"prices": [{
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 2,
				"price": 353.5,
				"stuPrice": null,
				"promotionPrice": 353.5,
				"resId": 1974907876,
				"detail": [],
				"priceMemo": null,
				"seatName": "一等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 3,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1974907877,
				"detail": [],
				"priceMemo": null,
				"seatName": "二等座"
			}, {
				"leftNumber": 99,
				"seatStatus": "有",
				"seat": 9,
				"price": 221,
				"stuPrice": null,
				"promotionPrice": 221,
				"resId": 1974907878,
				"detail": [],
				"priceMemo": null,
				"seatName": "无座"
			}],
			"durationDay": 1,
			"departStationType": 0,
			"destStationType": 2,
			"saleStatus": 0,
			"departStationId": 1175075,
			"destStationId": 1176185,
			"startSaleTime": "",
			"canChooseSeat": 0,
			"memo": "",
			"departureCityCode": 2500,
			"arrivalCityCode": 109,
			"departureCityName": "上海",
			"arrivalCityName": "池州",
			"upOrDown": 0,
			"trainStartDate": "2021-08-03",
			"accessByIdcard": "Y",
			"durationStr": "3小时25分钟",
			"departStationTypeName": "ticketbtn",
			"destStationTypeName": "",
			"sellOut": 0
		}],
		"allTrainType": {
			"list": [{
				"trainType": 0,
				"trainTypeName": "G-高铁",
				"trainTypeCode": "G",
				"link": "\/\/huoche.tuniu.com\/station__\/G"
			}],
			"departureCityName": "上海",
			"arrivalCityName": "池州"
		},
		"filter": {
			"filter": [{
				"id": "trainTypes",
				"name": "车型",
				"pros": [{
					"id": 0,
					"name": "G-高铁"
				}]
			}, {
				"id": "seats",
				"name": "座席",
				"pros": [{
					"id": 0,
					"name": "商务座"
				}, {
					"id": 1,
					"name": "特等座"
				}, {
					"id": 2,
					"name": "一等座"
				}, {
					"id": 3,
					"name": "二等座"
				}]
			}, {
				"id": "departureStations",
				"name": "出发车站",
				"pros": [{
					"name": "上海虹桥",
					"id": 1175076
				}, {
					"name": "上海",
					"id": 1175075
				}]
			}, {
				"id": "arrivalStations",
				"name": "到达车站",
				"pros": [{
					"name": "池州",
					"id": 1176185
				}]
			}, {
				"id": "departureTimes",
				"name": "出发时段",
				"pros": [{
					"id": "18-24",
					"name": "18-24点"
				}, {
					"id": "12-18",
					"name": "12-18点"
				}, {
					"id": "6-12",
					"name": "6-12点"
				}]
			}, {
				"id": "arrivalTimes",
				"name": "到达时段",
				"pros": [{
					"id": "18-24",
					"name": "18-24点"
				}, {
					"id": "12-18",
					"name": "12-18点"
				}, {
					"id": "6-12",
					"name": "6-12点"
				}]
			}, {
				"id": "departStationTypes",
				"name": "是否始发",
				"pros": [{
					"id": 0,
					"name": "始发"
				}, {
					"id": 2,
					"name": "过路"
				}]
			}],
			"sort": [{
				"type": 2,
				"id": 1,
				"name": "出发时间"
			}, {
				"type": 2,
				"id": 3,
				"name": "运行时间"
			}, {
				"type": 2,
				"id": 2,
				"name": "到达时间"
			}, {
				"type": 2,
				"id": 4,
				"name": "价格"
			}]
		}
	}
}
服务级错误码参照
错误码 说明
- -
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2021/08/02 22:26
 */
class freeApi
{
    private $apiUrl;

    public function __construct()
    {
        $this->apiUrl = 'http://huoche.tuniu.com/yii.php?r=train/trainTicket/getTickets&primary[departureDate]=2021-08-03&primary[departureCityName]=上海1&primary[arrivalCityName]=池州&start=0&limit=0';
    }

    /**
     * 获取结果
     * @return array
     */
    public function getResult()
    {
        return file_get_contents($this->apiUrl);
    }
}
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

const (
	APIURL   = "http://huoche.tuniu.com/yii.php?r=train/trainTicket/getTickets&primary[departureDate]=2021-08-03&primary[departureCityName]=上海1&primary[arrivalCityName]=池州&start=0&limit=0"
)

func main() {
	queryUrl := fmt.Sprintf("%s",APIURL)
	resp, err := http.Get(queryUrl)
	if err != nil {
		log.Println(err)
		return
	}

	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)

	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(body))
}