1. 从接口拿数据
日期
出发站
终点站
都填上
xxx/otn/leftTicketPrice/queryAllPublicPrice?leftTicketDTO.train_date=2024-06-15&leftTicketDTO.from_station=BJP&leftTicketDTO.to_station=SJP&purpose_codes=ADULT
返回的数据是这样的
{
"validateMessagesShowId": "_validatorMessage",
"status": true,
"httpstatus": 200,
"data": [
{
"queryLeftNewDTO": {
"train_no": "25000K772836",
"station_train_code": "K7725",
"start_station_telecode": "QTP",
"start_station_name": "秦皇岛",
"end_station_telecode": "HDP",
"end_station_name": "邯郸",
"from_station_telecode": "FTP",
"from_station_name": "北京丰台",
"to_station_telecode": "SJP",
"to_station_name": "石家庄",
"start_time": "05:10",
"arrive_time": "08:44",
"day_difference": "0",
"train_class_name": "快速",
"lishi": "03:34",
"control_train_day": "",
"start_train_date": "",
"seat_feature": "",
"yp_ex": "",
"train_seat_feature": "",
"infoAll_list": "1004150000#3009550001#3009250002#3008750003#1004150000#",
"yz_price": "00415",
"yw_price": "00955"
},
"buttonTextInfo": ""
}],
"messages": [],
"validateMessages": {}
}
2. 解析票价
$t = [];
// 这里需要循环处理
$e = "I026500001#I023500003#J021600001#J019800002#J018500003#O008700000#O008700000#"; // 替换为你的字符串
$n = explode("#", $e);
foreach ($n as $i) {
if ($i) {
$a = substr($i, 0, 1);
$o = strlen($i) >= 10 && $i[9] === '0' ? '' : $i[9];
$s = round((int)substr($i, 1, 5) / 10, 2); // Assuming you want to round to 2 decimal places, adjust as needed
$t[$a . $o] = $s;
if ($o !== '') {
$t[$a] = $s;
}
}
}
dd($t);
function dd($data) {
print_r($data);
die();
}
运行出来的结果
封装一下
3. 与标准座位比较
A: "高级动卧",
B: "混编硬座",
C: "混编硬卧",
D: "优选一等座",
E: "特等软座",
F: "动卧",
F1: "下铺",
F3: "上铺",
G: "二人软包",
H: "一人软包",
H1: "下铺",
H3: "上铺",
I: "一等卧",
I1: "下铺",
I3: "上铺",
J: "二等卧",
J1: "下铺",
J2: "中铺",
J3: "上铺",
K: "混编软座",
L: "混编软卧",
M: "一等座",
O: "二等座",
P: "特等座",
Q: "多功能座",
S: "二等包座",
0: "棚车",
1: "硬座",
2: "软座",
3: "硬卧",
31: "下铺",
32: "中铺",
33: "上铺",
4: "软卧",
41: "下铺",
43: "上铺",
5: "包厢硬卧",
6: "高级软卧",
61: "下铺",
63: "上铺",
7: "一等软座",
8: "二等软座",
9: "商务座"
至此 解析车票 大概逻辑完成