// 出发地
const START = '上海'
// 到达地
const ARRIVE = '重庆'
// 日期
const dates = [
'2020-12-19',
// '2020-12-18'
]
const revert = false
// const revert = true
// 出发城市信息
const startCity = CITIES.find(c => c.cityName === ( !revert ? START : ARRIVE).trim())
// 到达城市信息
const arriveCity = CITIES.find(c => c.cityName === (!revert ? ARRIVE : START).trim())
const headers = new Headers();
headers.append("Cache-Control", "no-cache");
headers.append("versionCode", "17000");
headers.append("platformInfo", "MWEB");
headers.append("Content-Type", "application/json;charset=UTF-8");
headers.append("channelCode", "MWEB");
headers.append("clientVersion", "1.7.0");
headers.append("Sec-Fetch-Site", "same-origin");
headers.append("Sec-Fetch-Mode", "cors");
headers.append("Sec-Fetch-Dest", "empty");
const fetchData = (date, startCity, arriveCity) =>
fetch("https://m.juneyaoair.com/server/v2/flight/AvFare", {
method: 'POST',
headers,
body: JSON.stringify({
"sendCity": startCity.cityName,
"sendCode": startCity.cityCode,
"arrCity": arriveCity.cityName,
"arrCode": arriveCity.cityCode,
"directType": "D",
"flightType": "OW",
"tripType": "D",
"queryType": "",
"blackBox": "eyJ2IjoiNGhYNnhwMGNMOXc5KzVnRnkwNDErMDVYTTNQblgrOEZHMDhXTzZ2UXJEcVQrTUJxUHhaMUFWSXF5UFgyVlQzNCIsIm9zIjoicGFkIiwiaXQiOjU4OCwidCI6InZRM3IvQ2FQcW12T0N6N0dKWlczQmxZTXc5a2tKT1dsS0dDMDZtU1V0SHpIWE5XWFBUWHB5SmJZOTVNUm1GWTdPRnJzVmF5b0dOaklmZjgwN3RyNGNRPT0ifQ==",
"channelCode": "MWEB",
"clientVersion": "1.7.0",
"versionCode": "17000",
departureDate: date,
returnDate: date
}),
redirect: 'follow'
})
.then(response => response.text())
.then(result => JSON.parse(result))
.catch(error => null)
// /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/
const init = async () => {
const arr = CITIES.slice(0, 109).map(arriveCity => fetchData(dates[0], startCity, arriveCity))
// const arr = CITIES.slice(0, 109).map(arriveCity => fetchData(dates[0], arriveCity, startCity))
const originList = await Promise.all(arr).then(list => list.reduce((r, a) => {
return r.concat((a || {}).flightInfoList || [])
}, []))
console.log('length::', originList.length)
const d = []
originList.forEach(o => {
const {
depDateTime,
depAirportName,
depCityName,
arrAirportName,
arrDateTime,
arrCityName
} = o
const a = (o.cabinFareList || []).find(ca => ca.cabinType === 'ADT_UNLIMITED_FLY' && ca.cabinNumber !== '0')
a && d.push({
'出发': '周' + ['日','一','二','三','四','五','六'][new Date(depDateTime).getDay()] + '|' +depDateTime + '|' + depCityName + '/' +depAirportName,
'出发机场': depAirportName,
'到达': arrCityName + '/' + arrAirportName + '|' + arrDateTime,
'余票': a.cabinNumber,
depDateTime
})
})
if (d.length) {
d.sort((i, j) => +new Date(i.depDateTime) - +new Date(j.depDateTime)).map(x => { delete x.depDateTime ; return x })
console.table(d)
} else console.log('真没有!')
}
// init()
console