|
@@ -0,0 +1,249 @@
|
|
|
|
+#-*- coding:utf-8 -*-
|
|
|
|
+import json
|
|
|
|
+import requests
|
|
|
|
+from lxml import etree
|
|
|
|
+from pyquery import PyQuery as pq
|
|
|
|
+from entity.RelationInfo import OrderRelationEntity,PassengerEntity
|
|
|
|
+import logging
|
|
|
|
+
|
|
|
|
+# 订单关联
|
|
|
|
+class RelationOrder():
|
|
|
|
+ def __init__(self,params):
|
|
|
|
+ self.josn_str = params
|
|
|
|
+ # 转换为实体类字段
|
|
|
|
+ self.orderRelation = OrderRelationEntity();
|
|
|
|
+ self.orderRelation.__dict__ = json.loads(self.josn_str)
|
|
|
|
+ self.passengers = self.orderRelation.passengers
|
|
|
|
+ self.session = requests.session()
|
|
|
|
+ self.__VIEWSTATE = ''
|
|
|
|
+ #请求头
|
|
|
|
+ self.headers = {
|
|
|
|
+ 'Accept-Encoding': 'gzip',
|
|
|
|
+ "Content-Encoding": "gzip, deflate, sdch",
|
|
|
|
+ "Accept-Language": "zh-CN,zh;q=0.8,en;q=0.6",
|
|
|
|
+ "Upgrade-Insecure-Requests": "1",
|
|
|
|
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
|
|
|
+ "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36",
|
|
|
|
+ }
|
|
|
|
+ self.session.headers.update(self.headers)
|
|
|
|
+ #登录提交参数
|
|
|
|
+ self.logindata = {
|
|
|
|
+ "__VIEWSTATE":"/wEPDwUBMGRktapVDbdzjtpmxtfJuRZPDMU9XYk=",
|
|
|
|
+ "__EVENTARGUMENT":"",
|
|
|
|
+ "__EVENTTARGET":"ControlGroupLoginAgentView$AgentLoginView$LinkButtonLogIn",
|
|
|
|
+ "ControlGroupLoginAgentView$AgentLoginView$TextBoxUserID":"CNTRIPTOPK_ADMIN",
|
|
|
|
+ "ControlGroupLoginAgentView$AgentLoginView$PasswordFieldPassword":"Tripto123",
|
|
|
|
+ "pageToken":"",
|
|
|
|
+ "TimeZoneDiff":"480"
|
|
|
|
+ }
|
|
|
|
+ self.msg = '';
|
|
|
|
+ self.isok = True;
|
|
|
|
+ #校验参数是否正确
|
|
|
|
+ def checkParams(self):
|
|
|
|
+ if len(self.orderRelation.orderNo) < 1:
|
|
|
|
+ #订单号不能为空
|
|
|
|
+ self.msg = '订单号不能为空';
|
|
|
|
+ return False;
|
|
|
|
+ if len(self.orderRelation.singleAccount) < 1:
|
|
|
|
+ #账号不能为空
|
|
|
|
+ self.msg = '账号不能为空';
|
|
|
|
+ return False;
|
|
|
|
+ if len(self.orderRelation.singleAccountPassWord) < 1:
|
|
|
|
+ #密码不能为空
|
|
|
|
+ self.msg = '密码不能为空';
|
|
|
|
+ return False;
|
|
|
|
+ if len(self.orderRelation.passengers) < 1:
|
|
|
|
+ #关联人不能为空
|
|
|
|
+ self.msg = '关联人不能为空';
|
|
|
|
+ return False;
|
|
|
|
+ return True;
|
|
|
|
+
|
|
|
|
+ def Login(self):
|
|
|
|
+ #添加代理IP
|
|
|
|
+# cl = call()
|
|
|
|
+# proxyurl = cl.getProxyIP()
|
|
|
|
+# proxy_handler = {
|
|
|
|
+# 'http': 'http://'+proxyurl,
|
|
|
|
+# 'https': 'https://'+proxyurl,
|
|
|
|
+# }
|
|
|
|
+# self.session.proxies = proxy_handler
|
|
|
|
+# logging.info('IP:'+proxyurl)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ res = self.session.get("https://www.airasia.com/my/en/login/travel-agent.page")
|
|
|
|
+ page = etree.HTML(res.text)
|
|
|
|
+ self.logindata['__VIEWSTATE'] = page.xpath("//input[@name='__VIEWSTATE']/@value")[0]
|
|
|
|
+ self.__VIEWSTATE = self.logindata['__VIEWSTATE']
|
|
|
|
+ print(self.__VIEWSTATE)
|
|
|
|
+ logging.info('__VIEWSTATE:'+self.__VIEWSTATE)
|
|
|
|
+
|
|
|
|
+ logindata = {
|
|
|
|
+ "__EVENTARGUMENT": "",
|
|
|
|
+ "__EVENTTARGET": "ControlGroupLoginAgentView$AgentLoginView$LinkButtonLogIn",
|
|
|
|
+ "ControlGroupLoginAgentView$AgentLoginView$TextBoxUserID": "CNTRIPTOPK_ADMIN",
|
|
|
|
+ "ControlGroupLoginAgentView$AgentLoginView$PasswordFieldPassword": "Tripto123",
|
|
|
|
+ "pageToken": "",
|
|
|
|
+ "TimeZoneDiff": "480"
|
|
|
|
+ }
|
|
|
|
+ self.session.cookies['i10c.bdddb'] = 'c2-f0103ZLNqAeI3BH6yYOfG7TZlRtCrMwzKDQfPMpdrBiHtspjoz4hG1gmlRTCqoP3KDqfQuYkuTrJ0zjBTuTfS8ZkqMupqjxVKDq7gmYkJNoptsolozTpvkQUSMtHlpVtKDQfPM0u5KY8oxo6uXRaGVZkqo8pgTsvP8rINHdKESnj9soBo01fLvZkQMtHHdplG8qkKNBiESNCtxyuZZBaGvZlOPoHQjxvly9WxxYkJNopssolozT4slZkqMupltWqPDGuoc0BESnCuVjBt3OftxZkqMtrloxBjRlkPHeIESnIoxRCozTaGVZkqk9c8jxvKEOfPMdfJ5nCtxjGUuTFBve3czUtRjxvKEOiKMDfJSCeoxo6uXOfGqelSMtHltY'
|
|
|
|
+ res = self.session.post("https://booking2.airasia.com/LoginAgent.aspx", data=logindata, verify=False, timeout=60)
|
|
|
|
+ agentHomeUrl = res.url
|
|
|
|
+ logging.info(res.url)
|
|
|
|
+
|
|
|
|
+ if 'LoginAgent.aspx' in agentHomeUrl:
|
|
|
|
+ logging.info('一次,登录失败,再次提交一下')
|
|
|
|
+ res = self.session.post("https://booking2.airasia.com/LoginAgent.aspx", data=self.logindata, verify=False, timeout=60)
|
|
|
|
+ agentHomeUrl = res.url
|
|
|
|
+ logging.info(agentHomeUrl)
|
|
|
|
+ logging.info(str(self.logindata))
|
|
|
|
+ htmlContent = res.text
|
|
|
|
+# f = open('AK_Agent1.html', 'w',encoding='utf-8')
|
|
|
|
+# f.write(res.text)
|
|
|
|
+# f.close()
|
|
|
|
+ isReload = 'window.location.reload'
|
|
|
|
+ if isReload in htmlContent:
|
|
|
|
+ res = self.session.get(agentHomeUrl)
|
|
|
|
+ htmlContent = res.content.decode()
|
|
|
|
+ if 'ZENG' in htmlContent:
|
|
|
|
+ #登录成功
|
|
|
|
+ logging.info('AK_Agent登录成功')
|
|
|
|
+ return True
|
|
|
|
+ else:
|
|
|
|
+ #登录失败
|
|
|
|
+ logging.info('AK_Agent登录失败')
|
|
|
|
+ f = open('AK_Agent.html', 'w',encoding='utf-8')
|
|
|
|
+ f.write(res.text)
|
|
|
|
+ f.close()
|
|
|
|
+ return False
|
|
|
|
+ #查找订单
|
|
|
|
+ def lookupOrder(self):
|
|
|
|
+ res = self.session.get("https://booking2.airasia.com/BookingList.aspx")
|
|
|
|
+ page = etree.HTML(res.text)
|
|
|
|
+ queryOrderList = {
|
|
|
|
+ '__EVENTARGUMENT':'',
|
|
|
|
+ '__EVENTTARGET':'ControlGroupBookingListView$BookingListSearchInputView$LinkButtonFindBooking',
|
|
|
|
+ '__VIEWSTATE':page.xpath("//input[@id='viewState']/@value"),
|
|
|
|
+ '__VIEWSTATEGENERATOR':page.xpath("//input[@id='__VIEWSTATEGENERATOR']/@value"),
|
|
|
|
+ 'ControlGroupBookingListView$BookingListSearchInputView$DropDownListTypeOfSearch':'1',
|
|
|
|
+ 'ControlGroupBookingListView$BookingListSearchInputView$Search':'ForAgent',
|
|
|
|
+ 'ControlGroupBookingListView$BookingListSearchInputView$TextBoxKeyword':self.orderRelation.orderNo,
|
|
|
|
+ 'pageToken':''
|
|
|
|
+ }
|
|
|
|
+ logging.info(queryOrderList)
|
|
|
|
+ res = self.session.post('https://booking2.airasia.com/BookingList.aspx', data=queryOrderList, verify=False,timeout = 60)
|
|
|
|
+ logging.info('通过PRN码查找订单')
|
|
|
|
+ logging.info(str(res.status_code))
|
|
|
|
+ logging.info(res.url)
|
|
|
|
+ queryOrder = {
|
|
|
|
+ '__EVENTARGUMENT':'Edit:'+self.orderRelation.orderNo,
|
|
|
|
+ '__EVENTTARGET':'ControlGroupBookingListView$BookingListSearchInputView',
|
|
|
|
+ '__VIEWSTATE':page.xpath("//input[@id='viewState']/@value"),
|
|
|
|
+ '__VIEWSTATEGENERATOR':page.xpath("//input[@id='__VIEWSTATEGENERATOR']/@value"),
|
|
|
|
+ 'ControlGroupBookingListView$BookingListSearchInputView$DropDownListTypeOfSearch':'1',
|
|
|
|
+ 'ControlGroupBookingListView$BookingListSearchInputView$Search':'ForAgent',
|
|
|
|
+ 'ControlGroupBookingListView$BookingListSearchInputView$TextBoxKeyword':self.orderRelation.orderNo,
|
|
|
|
+ 'pageToken':''
|
|
|
|
+ }
|
|
|
|
+ logging.info(queryOrder)
|
|
|
|
+ res = self.session.post('https://booking2.airasia.com/BookingList.aspx', data=queryOrder, verify=False,timeout = 60)
|
|
|
|
+ logging.info('通过PRN码打开订单')
|
|
|
|
+ logging.info(str(res.status_code))
|
|
|
|
+ logging.info(res.url)
|
|
|
|
+ ChangeItineraryData = {
|
|
|
|
+ '__EVENTARGUMENT':'',
|
|
|
|
+ '__EVENTTARGET':'ChangeControl$LinkButtonEarnBiggies',
|
|
|
|
+ '__VIEWSTATE':page.xpath("//input[@id='viewState']/@value"),
|
|
|
|
+ '__VIEWSTATEGENERATOR':page.xpath("//input[@id='__VIEWSTATEGENERATOR']/@value"),
|
|
|
|
+ 'hdRememberMeEmail':'',
|
|
|
|
+ 'HiddenFieldPageBookingData':'',
|
|
|
|
+ 'memberLogin_chk_RememberMe':'on',
|
|
|
|
+ 'MemberLoginChangeItineraryView2$PasswordFieldPassword':'',
|
|
|
|
+ 'MemberLoginChangeItineraryView2$TextBoxUserID':'',
|
|
|
|
+ 'pageToken':''
|
|
|
|
+ }
|
|
|
|
+ res = self.session.post('https://booking2.airasia.com/ChangeItinerary.aspx', data=ChangeItineraryData, verify=False,timeout = 60)
|
|
|
|
+ logging.info('打开Big关联页面')
|
|
|
|
+ logging.info(str(res.status_code))
|
|
|
|
+ logging.info(res.url)
|
|
|
|
+ f = open('E://EarnBiggies.html', 'w',encoding='utf-8')
|
|
|
|
+ f.write(res.text)
|
|
|
|
+ f.close()
|
|
|
|
+ page = etree.HTML(res.text)
|
|
|
|
+ glu = page.xpath("//iframe[@id='glu']/@src")[0]
|
|
|
|
+ glu = glu.replace('http:','https:')
|
|
|
|
+ logging.info("请求Big详情子页面URL:"+glu)
|
|
|
|
+ res = self.session.get(glu)
|
|
|
|
+ logging.info('打开Big详情子页面')
|
|
|
|
+ logging.info(str(res.status_code))
|
|
|
|
+ logging.info(res.url)
|
|
|
|
+ f = open('E://PassengerBigIDLive.html', 'w',encoding='utf-8')
|
|
|
|
+ f.write(res.text)
|
|
|
|
+ f.close()
|
|
|
|
+ return res.text
|
|
|
|
+ def RelationOrder(self,relationHtml):
|
|
|
|
+ page = etree.HTML(relationHtml)
|
|
|
|
+ b = pq(relationHtml)
|
|
|
|
+ RelationData = {
|
|
|
|
+ '__VIEWSTATE':page.xpath("//input[@id='__VIEWSTATE']/@value")[0],
|
|
|
|
+ '__VIEWSTATEGENERATOR':page.xpath("//input[@id='__VIEWSTATEGENERATOR']/@value")[0],
|
|
|
|
+ '__EVENTVALIDATION':page.xpath("//input[@id='__EVENTVALIDATION']/@value")[0],
|
|
|
|
+ 'hfpnr':page.xpath("//input[@id='hfpnr']/@value")[0],
|
|
|
|
+ 'hfurl':page.xpath("//input[@id='hfurl']/@value")[0],
|
|
|
|
+ '__ASYNCPOST':'true',
|
|
|
|
+ '__EVENTARGUMENT':'',
|
|
|
|
+ '__EVENTTARGET':'LinkButton1',
|
|
|
|
+ 'ScriptManager1':'MainUpdatePanel|LinkButton1'
|
|
|
|
+ }
|
|
|
|
+ form2Url = page.xpath("//form[@id='form2']/@action")[0]
|
|
|
|
+ for row in page.xpath("//table[@id='GridView1']/tr"):
|
|
|
|
+ if len(row.xpath("@align")) != 0:
|
|
|
|
+ continue
|
|
|
|
+ bigname = b('span',row).text()
|
|
|
|
+ logging.info(bigname)
|
|
|
|
+ bigNo = '';
|
|
|
|
+ for passInfo in self.passengers:
|
|
|
|
+ if passInfo['firstName']+' '+passInfo['lastName'] in bigname:
|
|
|
|
+ logging.info(passInfo['bigNo'])
|
|
|
|
+ bigNo = passInfo['bigNo']
|
|
|
|
+ break
|
|
|
|
+ inputName = row.xpath("./td/input/@name")
|
|
|
|
+ logging.info(inputName)
|
|
|
|
+ #判断 ['GridView1$ctl02$hfid', 'GridView1$ctl02$txbigshotid']
|
|
|
|
+ if len(bigNo) > 0:
|
|
|
|
+ #有了
|
|
|
|
+ RelationData[inputName[0]] = '1'
|
|
|
|
+ RelationData[inputName[1]] = bigNo
|
|
|
|
+ else:
|
|
|
|
+ #没有
|
|
|
|
+ RelationData[inputName[0]] = '0'
|
|
|
|
+ RelationData[inputName[1]] = ''
|
|
|
|
+ logging.info('提交URL:'+form2Url)
|
|
|
|
+ logging.info('提交参数:'+str(RelationData))
|
|
|
|
+ #https://selfservice.airasia.com/PassengerBigIDLive/
|
|
|
|
+ #does not exist
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ #添加设置请求头
|
|
|
|
+ self.headers['X-MicrosoftAjax'] = 'Delta=true'
|
|
|
|
+ self.headers['Host'] = 'selfservice.airasia.com'
|
|
|
|
+ self.headers['Referer'] = 'https://selfservice.airasia.com/PassengerBigIDLive/'+form2Url
|
|
|
|
+ self.headers['Cache-Control'] = 'no-cache'
|
|
|
|
+ self.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=utf-8'
|
|
|
|
+ self.session.headers.update(self.headers)
|
|
|
|
+ print(str(self.session.headers))
|
|
|
|
+ res = self.session.post('https://selfservice.airasia.com/PassengerBigIDLive/'+form2Url, data=RelationData,verify=False,timeout = 60)
|
|
|
|
+
|
|
|
|
+ logging.info('提交成功了,检查结果如何')
|
|
|
|
+ logging.info(str(res.status_code))
|
|
|
|
+ logging.info(res.url)
|
|
|
|
+ f = open('E://PassengerBigIDLiveHo.html', 'w',encoding='utf-8')
|
|
|
|
+ f.write(res.text)
|
|
|
|
+ f.close()
|
|
|
|
+ if '0|error|500||' in res.text:
|
|
|
|
+ logging.info('关联失败')
|
|
|
|
+ return False
|
|
|
|
+ if 'does not exist' in res.text:
|
|
|
|
+ logging.info('关联失败')
|
|
|
|
+ return False
|
|
|
|
+ return True
|
|
|
|
+
|