|
@@ -5,6 +5,7 @@ import requests
|
|
|
import time
|
|
|
import datetime
|
|
|
import re
|
|
|
+import random
|
|
|
from lxml import etree
|
|
|
from pyquery import PyQuery as pq
|
|
|
from entity.OrderInfo import OrderInfo,Contact,Passengers,Segments
|
|
@@ -12,14 +13,23 @@ from utils.CallbackOrderUtils import CallbackOrderUtils as call
|
|
|
from query.AkWebQuery import AkWebQuery
|
|
|
from query.AkBigQuery import AkBigQuery
|
|
|
urllib3.disable_warnings()
|
|
|
+import logging
|
|
|
|
|
|
class OrderServer():
|
|
|
def __init__(self,prarm):
|
|
|
- print('初始化')
|
|
|
+ self.salt = ''
|
|
|
+ self.isContinue = True
|
|
|
self.json_str = prarm
|
|
|
self.oinfo = OrderInfo();
|
|
|
self.queryInputJson = {}
|
|
|
self.session = requests.session()
|
|
|
+ self.num = random.randint(0,168)
|
|
|
+ self.proxyurl = self.oinfo.proxiesList[self.num]
|
|
|
+ self.proxy_handler = {
|
|
|
+ 'http': 'http://'+self.proxyurl,
|
|
|
+ 'https': 'https://'+self.proxyurl,
|
|
|
+ }
|
|
|
+ self.session.proxies = self.proxy_handler
|
|
|
#请求头
|
|
|
self.headers = {
|
|
|
'Accept-Encoding': 'gzip',
|
|
@@ -46,6 +56,7 @@ class OrderServer():
|
|
|
self.luggageDict = {20:'PBAB',25:'PBAC',30:'PBAD',40:'PBAF'}
|
|
|
#获取订单信息
|
|
|
def LoadPrarm(self):
|
|
|
+ self.salt = self.json_str['cid']+'|'
|
|
|
self.oinfo.cid =self.json_str['cid'] #CID 唯一标识
|
|
|
self.oinfo.tripType =self.json_str['tripType'] #行程类型 1.单程 2.往返
|
|
|
self.oinfo.formCity =self.json_str['formCity'] #去程三字码
|
|
@@ -99,6 +110,11 @@ class OrderServer():
|
|
|
seg.flightNumber = kfsa['flightNumber'] #航班号 ZQ555
|
|
|
seg.aircraftCode = kfsa['aircraftCode'] #机型 空客A380
|
|
|
seg.cabin = kfsa['cabin'] #舱位等级 EC.特惠 EP.低航费 VF.超值套餐 HF.常飞客 PM.豪华平躺
|
|
|
+ if 'E' == seg.cabin:
|
|
|
+ seg.cabin = 'EC'
|
|
|
+ if 'EC' != seg.cabin:
|
|
|
+ self.isContinue = False
|
|
|
+ return
|
|
|
seg.depAirport = kfsa['depAirport'] #出发机场IATA三字码 KUL
|
|
|
seg.arrAirport = kfsa['arrAirport'] #到达机场IATA三字码 DPS
|
|
|
seg.arrTime = kfsa['arrTime'] #起飞时间20180428053
|
|
@@ -119,6 +135,11 @@ class OrderServer():
|
|
|
seg.flightNumber = kfsa['flightNumber'] #航班号 ZQ555
|
|
|
seg.aircraftCode = kfsa['aircraftCode'] #机型 空客A380
|
|
|
seg.cabin = kfsa['cabin'] #舱位等级 EC.特惠 EP.低航费 VF.超值套餐 HF.常飞客 PM.豪华平躺
|
|
|
+ if 'E' == seg.cabin:
|
|
|
+ seg.cabin = 'EC'
|
|
|
+ if 'EC' != seg.cabin:
|
|
|
+ self.isContinue = False
|
|
|
+ return
|
|
|
seg.depAirport = kfsa['depAirport'] #出发机场IATA三字码 KUL
|
|
|
seg.arrAirport = kfsa['arrAirport'] #到达机场IATA三字码 DPS
|
|
|
seg.arrTime = kfsa['arrTime'] #起飞时间20180428053
|
|
@@ -128,13 +149,13 @@ class OrderServer():
|
|
|
fromSegments.append(seg)
|
|
|
self.oinfo.retFlight = retFlight
|
|
|
self.oinfo.retSegments = retSegments
|
|
|
- print('数据解析完毕,现在可以输出数据了')
|
|
|
- print(self.oinfo.fromFlight)
|
|
|
- print(self.oinfo.retFlight)
|
|
|
- print(self.oinfo.formCity)
|
|
|
- print(self.oinfo.toCity)
|
|
|
- print(self.oinfo.fromDate)
|
|
|
- print(self.oinfo.retDate)
|
|
|
+ logging.info(self.salt+'数据解析完毕,现在可以输出数据了')
|
|
|
+ logging.info(self.salt+self.oinfo.fromFlight)
|
|
|
+ logging.info(self.salt+self.oinfo.retFlight)
|
|
|
+ logging.info(self.salt+self.oinfo.formCity)
|
|
|
+ logging.info(self.salt+self.oinfo.toCity)
|
|
|
+ logging.info(self.salt+self.oinfo.fromDate)
|
|
|
+ logging.info(self.salt+self.oinfo.retDate)
|
|
|
#查询字符串JSON
|
|
|
self.queryInputJson = {
|
|
|
"adultNum": self.oinfo.adultNum,
|
|
@@ -148,6 +169,7 @@ class OrderServer():
|
|
|
"uuid": "AKBigWeb",
|
|
|
"currency": self.oinfo.currencyCode
|
|
|
}
|
|
|
+ logging.info(self.salt+'查询提交参数:'+str(self.queryInputJson))
|
|
|
#调用货币查询结果
|
|
|
def CurrencyQuery(self):
|
|
|
cl = call()
|
|
@@ -155,17 +177,17 @@ class OrderServer():
|
|
|
self.oinfo.currency = currency
|
|
|
self.oinfo.fxRate = currency.AkOriginRate
|
|
|
self.oinfo.currencyCode = currency.currencyCode
|
|
|
- print(self.oinfo.fxRate)
|
|
|
- print(self.oinfo.currencyCode)
|
|
|
+ logging.info(self.salt+str(self.oinfo.fxRate))
|
|
|
+ logging.info(self.salt+str(self.oinfo.currencyCode))
|
|
|
#发起Web查询
|
|
|
def WebQuery(self):
|
|
|
akwebQuer = AkWebQuery(self.queryInputJson,self.oinfo.tripType,self.oinfo.fromFlight,self.oinfo.retFlight,self.oinfo.fxRate)
|
|
|
akQueryWebFrom,akQueryWebRet,isOk = akwebQuer.StartQuery()
|
|
|
if self.oinfo.webIsOk:
|
|
|
return
|
|
|
- print('WebQuer:'+str(isOk))
|
|
|
- print('Web去程:'+json.dumps(akQueryWebFrom))
|
|
|
- print('Web返程:'+json.dumps(akQueryWebRet))
|
|
|
+ logging.info(self.salt+'WebQuer:'+str(isOk))
|
|
|
+ logging.info(self.salt+'Web去程:'+json.dumps(akQueryWebFrom))
|
|
|
+ logging.info(self.salt+'Web返程:'+json.dumps(akQueryWebRet))
|
|
|
#判断对象是否为空
|
|
|
if self.oinfo.webIsOk == False:
|
|
|
self.oinfo.webIsOk = isOk
|
|
@@ -177,9 +199,9 @@ class OrderServer():
|
|
|
akQueryBigFrom,akQueryBigRet,isOk = akbigQuer.StartQuery()
|
|
|
if self.oinfo.bigIsOk:
|
|
|
return
|
|
|
- print('BigQuer:'+str(isOk))
|
|
|
- print('Big去程:'+json.dumps(akQueryBigFrom))
|
|
|
- print('Big返程:'+json.dumps(akQueryBigRet))
|
|
|
+ logging.info(self.salt+'BigQuer:'+str(isOk))
|
|
|
+ logging.info(self.salt+'Big去程:'+json.dumps(akQueryBigFrom))
|
|
|
+ logging.info(self.salt+'Big返程:'+json.dumps(akQueryBigRet))
|
|
|
if self.oinfo.bigIsOk == False:
|
|
|
self.oinfo.bigIsOk = isOk
|
|
|
self.oinfo.bigFromJson = akQueryBigFrom
|
|
@@ -192,8 +214,10 @@ class OrderServer():
|
|
|
#代理人进行登录
|
|
|
def AagenLogin(self):
|
|
|
self.session.get("https://www.airasia.com/my/en/login/travel-agent.page")
|
|
|
- res = self.session.post("https://booking2.airasia.com/LoginAgent.aspx", data=self.logindata, verify=False, timeout=30)
|
|
|
+ res = self.session.post("https://booking2.airasia.com/LoginAgent.aspx", data=self.logindata, verify=False, timeout=60)
|
|
|
agentHomeUrl = res.url
|
|
|
+ logging.info(self.salt+agentHomeUrl)
|
|
|
+ logging.info(self.salt+str(self.logindata))
|
|
|
htmlContent = res.content.decode()
|
|
|
isReload = 'window.location.reload'
|
|
|
if isReload in htmlContent:
|
|
@@ -201,23 +225,23 @@ class OrderServer():
|
|
|
htmlContent = res.content.decode()
|
|
|
if 'ZENG' in htmlContent:
|
|
|
#登录成功
|
|
|
- print('AK_Agent登录成功')
|
|
|
+ logging.info(self.salt+'AK_Agent登录成功')
|
|
|
return True
|
|
|
else:
|
|
|
#登录失败
|
|
|
- print('AK_Agent登录失败')
|
|
|
+ logging.info(self.salt+'AK_Agent登录失败')
|
|
|
return False
|
|
|
#代理人查询
|
|
|
def AgentSearch(self):
|
|
|
res = self.session.get("https://booking2.airasia.com/Search.aspx")
|
|
|
- print('打开查询页面')
|
|
|
+ logging.info(self.salt+'打开查询页面')
|
|
|
externalRateList = re.findall(r'ExternalRateList":(.*)},\n', res.text)[0]
|
|
|
rateinfo = json.loads(externalRateList)
|
|
|
currencyAkId = 'default'
|
|
|
for rate in rateinfo:
|
|
|
if rate['quotedCurrency'] == self.oinfo.currencyCode and rate['collectedCurrency'] == 'CNY':
|
|
|
currencyAkId = rate['code']
|
|
|
- print('币种ID:'+str(currencyAkId))
|
|
|
+ logging.info(self.salt+'币种ID:'+str(currencyAkId))
|
|
|
self.oinfo.currenctAkCode = currencyAkId
|
|
|
|
|
|
#--------------------------组织请求参数-----------------
|
|
@@ -258,7 +282,7 @@ class OrderServer():
|
|
|
'__VIEWSTATEGENERATOR':'05F9A2B0'
|
|
|
}
|
|
|
|
|
|
- res = self.session.post('https://booking2.airasia.com/Search.aspx',verify=False,data=searchDate,timeout=30)
|
|
|
+ res = self.session.post('https://booking2.airasia.com/Search.aspx',verify=False,data=searchDate,timeout=60)
|
|
|
#解析代理人查询结果
|
|
|
self.AgentSearchAnalysis(res.text)
|
|
|
|
|
@@ -300,8 +324,8 @@ class OrderServer():
|
|
|
typsJson['radioValue'] = radioValue
|
|
|
fromJson[cabinObj[index]['code']] = typsJson
|
|
|
index +=1
|
|
|
- print(fromJson)
|
|
|
- print('-------------------返程数据---------------------')
|
|
|
+ logging.info(self.salt+str(fromJson))
|
|
|
+ logging.info(self.salt+'-------------------返程数据---------------------')
|
|
|
retJson = {}
|
|
|
if self.oinfo.tripType == 2:
|
|
|
fromTableTr = b("tr[class='rgRow']", tablessss[1])
|
|
@@ -331,8 +355,8 @@ class OrderServer():
|
|
|
typsJson['radioValue'] = radioValue
|
|
|
retJson[cabinObj[index]['code']] = typsJson
|
|
|
index +=1
|
|
|
- print(retJson)
|
|
|
- print('............................................')
|
|
|
+ logging.info(self.salt+str(retJson))
|
|
|
+ logging.info(self.salt+'............................................')
|
|
|
self.oinfo.agentIsOk = True
|
|
|
self.oinfo.agentFromJson = fromJson
|
|
|
self.oinfo.agentRetJson = retJson
|
|
@@ -436,8 +460,8 @@ class OrderServer():
|
|
|
self.oinfo.fromRadioValue = agfromVal
|
|
|
self.oinfo.retRadioValue = agretVal
|
|
|
|
|
|
- print('去程字符串:'+self.oinfo.fromRadioValue)
|
|
|
- print('回程字符串:'+self.oinfo.retRadioValue)
|
|
|
+ logging.info(self.salt+'去程字符串:'+self.oinfo.fromRadioValue)
|
|
|
+ logging.info(self.salt+'回程字符串:'+self.oinfo.retRadioValue)
|
|
|
|
|
|
|
|
|
#航班选定
|
|
@@ -485,13 +509,13 @@ class OrderServer():
|
|
|
flightData['ControlGroupSelectView$AvailabilityInputSelectView$market2'] = self.oinfo.retRadioValue
|
|
|
else:
|
|
|
flightData['oneWayOnly'] = '1'
|
|
|
- print('--------提交航班 ')
|
|
|
- print('go:'+self.oinfo.fromRadioValue)
|
|
|
- print('back:'+self.oinfo.retRadioValue)
|
|
|
- res = self.session.post('https://booking2.airasia.com/Select.aspx', data=flightData, verify=False,timeout = 30)
|
|
|
- print('提交成功,打开填写乘客信息页面')
|
|
|
- print(res.status_code)
|
|
|
- print(res.url)
|
|
|
+ logging.info(self.salt+'--------提交航班 ')
|
|
|
+ logging.info(self.salt+'go:'+self.oinfo.fromRadioValue)
|
|
|
+ logging.info(self.salt+'back:'+self.oinfo.retRadioValue)
|
|
|
+ res = self.session.post('https://booking2.airasia.com/Select.aspx', data=flightData, verify=False,timeout = 60)
|
|
|
+ logging.info(self.salt+'提交成功,打开填写乘客信息页面')
|
|
|
+ logging.info(self.salt+str(res.status_code))
|
|
|
+ logging.info(self.salt+res.url)
|
|
|
return res.text
|
|
|
#乘机人信息填写
|
|
|
def Passenger(self,passHtml):
|
|
@@ -580,11 +604,11 @@ class OrderServer():
|
|
|
passengerData["CONTROLGROUP_OUTERTRAVELER$CONTROLGROUPTRAVELER$PassengerInputTravelerView$DropDownListBirthDateDay_%d_%d" % (idx, idx)] = passenger.birthday[-2:]
|
|
|
passengerData["CONTROLGROUP_OUTERTRAVELER$CONTROLGROUPTRAVELER$PassengerInputTravelerView$DropDownListBirthDateMonth_%d_%d" % (idx, idx)] = passenger.birthday[5:7]
|
|
|
passengerData["CONTROLGROUP_OUTERTRAVELER$CONTROLGROUPTRAVELER$PassengerInputTravelerView$DropDownListBirthDateMonth_ONTROLGROUPTRAVELER$PassengerInputTravelerView$DropDownListBirthDateYear_%d_%d" % (idx, idx)] = passenger.birthday[:4]
|
|
|
- print('------------------------------------------提交乘机人---:')
|
|
|
- res = self.session.post('https://booking2.airasia.com/Traveler.aspx', data=passengerData, verify=False,timeout = 30)
|
|
|
- print('乘机人提交成功,进入下一步!')
|
|
|
- print(res.status_code)
|
|
|
- print(res.url)
|
|
|
+ logging.info(self.salt+'------------------------------------------提交乘机人---:')
|
|
|
+ res = self.session.post('https://booking2.airasia.com/Traveler.aspx', data=passengerData, verify=False,timeout = 60)
|
|
|
+ logging.info(self.salt+'乘机人提交成功,进入下一步!')
|
|
|
+ logging.info(self.salt+str(res.status_code))
|
|
|
+ logging.info(self.salt+res.url)
|
|
|
return res.text
|
|
|
def AddOns(self,addOnsHtml):
|
|
|
page = etree.HTML(addOnsHtml)
|
|
@@ -627,12 +651,11 @@ class OrderServer():
|
|
|
}
|
|
|
for row in page.xpath("//div[starts-with(@class,'ctw-book')]/input/@name"):
|
|
|
AddOnsData[row]='0'
|
|
|
- print('-------------提交租车服务')
|
|
|
- print(AddOnsData)
|
|
|
- res = self.session.post('https://booking2.airasia.com/AddOns.aspx', data=AddOnsData, verify=False,timeout = 30)
|
|
|
- print('附加服务提交成功,进入下一步!')
|
|
|
- print(res.status_code)
|
|
|
- print(res.url)
|
|
|
+ logging.info(self.salt+'-------------提交租车服务')
|
|
|
+ res = self.session.post('https://booking2.airasia.com/AddOns.aspx', data=AddOnsData, verify=False,timeout = 60)
|
|
|
+ logging.info(self.salt+'附加服务提交成功,进入下一步!')
|
|
|
+ logging.info(self.salt+str(res.status_code))
|
|
|
+ logging.info(self.salt+res.url)
|
|
|
return res.text
|
|
|
def UnitMap(self,unitMapHtml):
|
|
|
b = pq(unitMapHtml)
|
|
@@ -652,13 +675,10 @@ class OrderServer():
|
|
|
inputList = b.find("#passengerListBody input")
|
|
|
for row in inputList:
|
|
|
UnitMapData[pq(row).attr("name")] = ''
|
|
|
- res = self.session.post('https://booking2.airasia.com/UnitMap.aspx', data=UnitMapData, verify=False,timeout = 30)
|
|
|
- print('选择舱位提交成功,进入下一步!')
|
|
|
- print(res.status_code)
|
|
|
- print(res.url)
|
|
|
- f3 = open('E://testUnitMap.html', 'w',encoding='utf-8')
|
|
|
- f3.write(res.text.replace('position: fixed; top: 0; left: 0; background: #ffffff; filter:alpha(opacity=70); -moz-opacity:0.7; opacity: 0.7; z-index:9997; width:100%; height:100%;',''))
|
|
|
- f3.close()
|
|
|
+ res = self.session.post('https://booking2.airasia.com/UnitMap.aspx', data=UnitMapData, verify=False,timeout = 60)
|
|
|
+ logging.info(self.salt+'选择舱位提交成功,进入下一步!')
|
|
|
+ logging.info(self.salt+str(res.status_code))
|
|
|
+ logging.info(self.salt+res.url)
|
|
|
return res.text
|
|
|
#支付选择
|
|
|
def Payment(self,payHtml):
|
|
@@ -681,10 +701,10 @@ class OrderServer():
|
|
|
'HiddenFieldPageBookingData':page.xpath('//input[@id="HiddenFieldPageBookingDataId"]/@value')[0],
|
|
|
'__VIEWSTATEGENERATOR':'05F9A2B0'
|
|
|
}
|
|
|
- res = self.session.post('https://booking2.airasia.com/Payment.aspx', data=PaymentData, verify=False,timeout = 30)
|
|
|
- print('支付选择提交成,进入下一步!')
|
|
|
- print(res.status_code)
|
|
|
- print(res.url)
|
|
|
+ res = self.session.post('https://booking2.airasia.com/Payment.aspx', data=PaymentData, verify=False,timeout = 60)
|
|
|
+ logging.info(self.salt+'支付选择提交成,进入下一步!')
|
|
|
+ logging.info(self.salt+str(res.status_code))
|
|
|
+ logging.info(self.salt+res.url)
|
|
|
f4 = open('E://testPayment.html', 'w',encoding='utf-8')
|
|
|
f4.write(res.text.replace('position: fixed; top: 0; left: 0; background: #ffffff; filter:alpha(opacity=70); -moz-opacity:0.7; opacity: 0.7; z-index:9997; width:100%; height:100%;',''))
|
|
|
f4.close()
|