zhangqf 6 gadi atpakaļ
vecāks
revīzija
aa44cff81a

+ 0 - 0
src/AK_Agent.html


+ 2 - 1
src/AirasiaWeb.py

@@ -26,6 +26,7 @@ class AirasiaWeb(tornado.web.RequestHandler):
         self.write('这里是亚航生单API。')
     def post(self):
         param = self.request.body.decode('utf-8')
+        logging.info('生单数据:'+param)
         prarm = json.loads(param)
         try:
             _thread.start_new_thread(self.akorder,(prarm,))
@@ -59,7 +60,7 @@ class AirasiaWeb(tornado.web.RequestHandler):
                     logging.info('Error: 无法启动线程')
                 logging.info('-------------------查询发起成功,刷新执行结果-------')
                 counter = 1
-                while counter < 15:
+                while counter < 25:
                     if orderServer.checkQuery():
                         print('----------------亲,已经刷新到结果啦.......可以继续下一步了')
                         break

+ 103 - 37
src/order/OrderServer.py

@@ -23,8 +23,9 @@ class OrderServer():
         self.oinfo = OrderInfo();
         self.queryInputJson = {}
         self.session = requests.session()
-        self.num = random.randint(0,168)
-        self.proxyurl = self.oinfo.proxiesList[self.num]
+        self.__VIEWSTATE = ''
+        cl = call()
+        self.proxyurl = cl.getProxyIP()
         self.proxy_handler = {
             'http': 'http://'+self.proxyurl,
             'https': 'https://'+self.proxyurl,
@@ -38,8 +39,10 @@ class OrderServer():
             "Upgrade-Insecure-Requests": "1",
             "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
         }
+        self.session.headers.update(self.headers)
         #登录提交参数
         self.logindata = {
+            "__VIEWSTATE":"/wEPDwUBMGRktapVDbdzjtpmxtfJuRZPDMU9XYk=",
             "__EVENTARGUMENT":"",
             "__EVENTTARGET":"ControlGroupLoginAgentView$AgentLoginView$LinkButtonLogIn",
             "ControlGroupLoginAgentView$AgentLoginView$TextBoxUserID":"CNTRIPTOPK_ADMIN",
@@ -213,12 +216,30 @@ class OrderServer():
             return False
     #代理人进行登录
     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=60)
+        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']
+        logging.info(self.salt+'__VIEWSTATE:'+self.__VIEWSTATE)
+        
+        logindata = {
+            "__EVENTARGUMENT": "",
+            "__EVENTTARGET": "ControlGroupLoginAgentView$AgentLoginView$LinkButtonLogIn",
+            "ControlGroupLoginAgentView$AgentLoginView$TextBoxUserID": "CNTRIPTOPK_ADMIN",
+            "ControlGroupLoginAgentView$AgentLoginView$PasswordFieldPassword": "Tripto123",
+            "pageToken": "",
+            "TimeZoneDiff": "480"
+        }
+        res = self.session.post("https://booking2.airasia.com/LoginAgent.aspx", data=logindata, verify=False, timeout=60)
         agentHomeUrl = res.url
+        logging.info(self.salt+res.url)
+        if 'LoginAgent.aspx' in agentHomeUrl:
+            logging.info(self.salt+'一次,登录失败,再次提交一下')
+            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()
+        htmlContent = res.text
         isReload = 'window.location.reload'
         if isReload in htmlContent:
             res = self.session.get(agentHomeUrl)
@@ -230,6 +251,10 @@ class OrderServer():
         else:
             #登录失败
             logging.info(self.salt+'AK_Agent登录失败')
+            logging.info(self.salt)
+            f = open('AK_Agent.html', 'w',encoding='utf-8')
+            f.write(res.text)
+            f.close()
             return False
     #代理人查询
     def AgentSearch(self):
@@ -243,7 +268,7 @@ class OrderServer():
                 currencyAkId = rate['code']
         logging.info(self.salt+'币种ID:'+str(currencyAkId)) 
         self.oinfo.currenctAkCode = currencyAkId
-        
+        logging.info(self.salt+'组织请求参数')
         #--------------------------组织请求参数-----------------
         structure = 'OneWay'
         if self.oinfo.tripType == 1:
@@ -252,6 +277,9 @@ class OrderServer():
             structure = 'RoundTrip'
         fromPicker = self.oinfo.fromDate[-2:]+'/'+self.oinfo.fromDate[5:7]+'/'+self.oinfo.fromDate[0:4]
         retPicker = self.oinfo.retDate[-2:]+'/'+self.oinfo.retDate[5:7]+'/'+self.oinfo.retDate[0:4]    
+        logging.info(self.salt+'structure:'+structure)
+        logging.info(self.salt+'fromPicker:'+fromPicker)
+        logging.info(self.salt+'retPicker:'+retPicker)
         searchDate = {
                 '__EVENTTARGET':'',
                 '__EVENTARGUMENT':'',
@@ -281,29 +309,48 @@ class OrderServer():
                 'ControlGroupSearchView$ButtonSubmit':'Search',
                 '__VIEWSTATEGENERATOR':'05F9A2B0'
             }
-        
+        logging.info(self.salt+'发起查询')
         res = self.session.post('https://booking2.airasia.com/Search.aspx',verify=False,data=searchDate,timeout=60)
+        logging.info(self.salt+'解析代理人查询结果')
+        logging.info(self.salt+res.url)
+        logging.info(self.salt+str(res.status_code))
         #解析代理人查询结果
+        f = open('E://testSelect0.html', 'w',encoding='utf-8')
+        f.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%;',''))
+        f.close()
         self.AgentSearchAnalysis(res.text)
-
+        logging.info(self.salt+'解析代理人查询结果完毕')
     #解析代理人查询结果
     def AgentSearchAnalysis(self,queryHtml):
         b = pq(queryHtml) 
+        logging.info(self.salt+'文档加载成功,现在解析')
         afromFlight = self.oinfo.fromFlight[0:-1].split(',')
-        aretFlight = self.oinfo.retFlight[0:-1].split(',')
-        cabinObj = [{'code':'EC','name':'促销'}
+        
+        cabinObj4 = [{'code':'EC','name':'促销'}
+            ,{'code':'EP','name':'低航费'}
+            ,{'code':'HF','name':'常飞客'}
+            ,{'code':'PM','name':'豪华平躺'}]
+        cabinObj3 = [{'code':'EC','name':'促销'}
                     ,{'code':'EP','name':'低航费'}
-                    ,{'code':'HF','name':'常飞客'}
                     ,{'code':'PM','name':'豪华平躺'}]
+        
         tablessss = b("table[class='rgMasterTable']")
         fromTableTr =  b("tr[class='rgRow']", tablessss[0])
         fromJson = {}
         for tb in fromTableTr:
-            resultFareCell = b("td[class='resultFareCell4']", tb)
+            resultFareCell = b("td", tb)
             index = 0
             for td in resultFareCell:
+                if index == 0:
+                    index +=1
+                    continue
                 input = b("div[id='fareRadio']", td)
                 radioValue = b("input", input).attr("value")
+                cabinObj = []
+                if len(resultFareCell) == 4:
+                    cabinObj =cabinObj3
+                else:
+                    cabinObj =cabinObj4
                 if radioValue != None:
                     rv = radioValue.replace('~','').replace(' ','')
                     isFlight = True
@@ -313,29 +360,38 @@ class OrderServer():
                             break
                     if isFlight == False:
                         break
-                    originalLowestFare = b("div[id='originalLowestFare']", td).text().replace(',','')
+                    originalLowestFare = b(".price span", td).text().replace(',','').replace(' CNY','')
                     typsJson = {}
                     typsJson['currency'] = 'CNY'
-                    typsJson['cabin'] = cabinObj[index]['code']
-                    typsJson['cabinName'] = cabinObj[index]['name']
+                    typsJson['cabin'] = cabinObj[index-1]['code']
+                    typsJson['cabinName'] = cabinObj[index-1]['name']
                     typsJson['adultPrice'] = float(originalLowestFare)
                     typsJson['adultTax'] = 0.0
                     typsJson['priceTotal'] = float(originalLowestFare)
                     typsJson['radioValue'] = radioValue
-                    fromJson[cabinObj[index]['code']] =  typsJson
+                    fromJson[cabinObj[index-1]['code']] =  typsJson
                 index +=1
         logging.info(self.salt+str(fromJson))
         logging.info(self.salt+'-------------------返程数据---------------------')    
         retJson = {}
         if self.oinfo.tripType == 2:
+            aretFlight = self.oinfo.retFlight[0:-1].split(',')
             fromTableTr =  b("tr[class='rgRow']", tablessss[1])
             for tb in fromTableTr:
-                resultFareCell = b("td[class='resultFareCell4']", tb)
+                resultFareCell = b("td", tb)
                 index = 0
                 for td in resultFareCell:
+                    if index == 0:
+                        index +=1
+                        continue
                     input = b("div[id='fareRadio']", td)
                     radioValue = b("input", input).attr("value")
-                    originalLowestFare = b("div[id='originalLowestFare']", td).text().replace(',','')
+                    cabinObj = []
+                    if len(resultFareCell) == 4:
+                        cabinObj =cabinObj3
+                    else:
+                        cabinObj =cabinObj4
+                    
                     if radioValue != None:
                         rv = radioValue.replace('~','').replace(' ','')
                         isFlight = True
@@ -345,15 +401,16 @@ class OrderServer():
                                 break
                         if isFlight == False:
                             break
+                        originalLowestFare = b(".price span", td).text().replace(',','').replace(' CNY','')
                         typsJson = {}
                         typsJson['currency'] = 'CNY'
-                        typsJson['cabin'] = cabinObj[index]['code']
-                        typsJson['cabinName'] = cabinObj[index]['name']
+                        typsJson['cabin'] = cabinObj[index-1]['code']
+                        typsJson['cabinName'] = cabinObj[index-1]['name']
                         typsJson['adultPrice'] = float(originalLowestFare)
                         typsJson['adultTax'] = 0.0
                         typsJson['priceTotal'] = float(originalLowestFare)
                         typsJson['radioValue'] = radioValue
-                        retJson[cabinObj[index]['code']] =  typsJson
+                        retJson[cabinObj[index-1]['code']] =  typsJson
                     index +=1
         logging.info(self.salt+str(retJson))
         logging.info(self.salt+'............................................')
@@ -414,22 +471,27 @@ class OrderServer():
             if 'EC' in bigretPrice.keys():
                 bigrPrice = bigretPrice['EC']['priceTotal']
                 
-                
-        #一决雌雄  使用那种方式生单  AGENT_ORDER WEB_ORDER BIG_ORDER
-        if (bigfPrice + bigrPrice) < (webfPrice + webrPrice) and (bigfPrice + bigrPrice) < (agfPrice + agrPrice):
-            #Big价格优势
-            self.oinfo.modeOrder = 'BIG_ORDER'
-            return
+        if bigfPrice != 0.0:        
+            #一决雌雄  使用那种方式生单  AGENT_ORDER WEB_ORDER BIG_ORDER
+            if (bigfPrice + bigrPrice) < (webfPrice + webrPrice) and (bigfPrice + bigrPrice) < (agfPrice + agrPrice):
+                #Big价格优势
+                self.oinfo.modeOrder = 'BIG_ORDER'
+                return
         
         self.oinfo.modeOrder = 'AGENT_ORDER'
         #接下来是官网与代理的对决
-        if webfPrice < agfPrice:
-            self.oinfo.fromRadioValue = webfromVal
+        if webfPrice != 0.0:
+            if webfPrice < agfPrice:
+                self.oinfo.fromRadioValue = webfromVal
+            else:
+                self.oinfo.fromRadioValue = agfromVal
         else:
             self.oinfo.fromRadioValue = agfromVal
-        
-        if webrPrice < agrPrice:
-            self.oinfo.retRadioValue = webretVal
+        if webrPrice != 0.0:
+            if webrPrice < agrPrice:
+                self.oinfo.retRadioValue = webretVal
+            else:
+                self.oinfo.retRadioValue = agretVal
         else:
             self.oinfo.retRadioValue = agretVal
         
@@ -680,8 +742,11 @@ class OrderServer():
         logging.info(self.salt+str(res.status_code))
         logging.info(self.salt+res.url)
         return res.text
-    #支付选择
+    #支付选择 选择支付宝支付
     def Payment(self,payHtml):
+#         f4 = open('E://payHtml.html', 'w',encoding='utf-8')
+#         f4.write(payHtml.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()
         page = etree.HTML(payHtml)
         PaymentData = {
             '__EVENTTARGET':'',
@@ -696,18 +761,19 @@ class OrderServer():
             'CONTROLGROUPPAYMENTBOTTOM$MultiCurrencyConversionViewPaymentView$DropDownListCurrency':self.oinfo.currenctAkCode,
             'MCCOriginCountry':page.xpath('//input[@name="MCCOriginCountry"]/@value')[0],
             'CONTROLGROUPPAYMENTBOTTOM$PaymentInputViewPaymentView$HiddenFieldUpdatedMCC':'',
-            'CONTROLGROUPPAYMENTBOTTOM$PaymentInputViewPaymentView$RadioButtonDirectDebit':'RadioButton_CUPPBB-CUPPBB',
+            'CONTROLGROUPPAYMENTBOTTOM$PaymentInputViewPaymentView$RadioButtonDirectDebit':page.xpath('//input[@id="CONTROLGROUPPAYMENTBOTTOM_PaymentInputViewPaymentView_RadioButton_ALIPAY-ALIPAY"]/@value'),
             'CONTROLGROUPPAYMENTBOTTOM$ButtonSubmit':'Submit payment',
             'HiddenFieldPageBookingData':page.xpath('//input[@id="HiddenFieldPageBookingDataId"]/@value')[0],
             '__VIEWSTATEGENERATOR':'05F9A2B0'
             }
+        logging.info(self.salt+str(PaymentData))
         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()
+#         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()
         page = etree.HTML(res.text)
         PNR = page.xpath('//input[@id="HiddenFieldPageBookingDataId"]/@value')[0]
         return PNR

+ 35 - 11
src/test/AgentQueryHtmlTest.py

@@ -2,32 +2,48 @@
 
 from pyquery import PyQuery as pq
 
-f = open('E://testSelect.html',encoding='utf-8')
+f = open('E://ak/testSelect0.html',encoding='utf-8')
 queryHtml = f.read()
 b = pq(queryHtml) 
     
     
-afromFlight = 'AK119,D7178'.split(',')
-aretFlight = 'D7179,AK118'.split(',')
+# afromFlight = 'FD3168,'.split(',')
+# aretFlight = ''.split(',')
+
+afromFlight = 'D7798,'.split(',')
+aretFlight = ''.split(',')
 
     
-cabinObj = [{'code':'EC','name':'促销'}
+cabinObj4 = [{'code':'EC','name':'促销'}
             ,{'code':'EP','name':'低航费'}
             ,{'code':'HF','name':'常飞客'}
             ,{'code':'PM','name':'豪华平躺'}]
+cabinObj3 = [{'code':'EC','name':'促销'}
+            ,{'code':'EP','name':'低航费'}
+            ,{'code':'PM','name':'豪华平躺'}]
     
 print('------------------------------------------------------')
 tablessss = b("table[class='rgMasterTable']")
 fromTableTr =  b("tr[class='rgRow']", tablessss[0])
 fromJson = {}
 for tb in fromTableTr:
-    resultFareCell = b("td[class='resultFareCell4']", tb)
+    resultFareCell = b("td", tb)
     index = 0
+    print('---------------'+str(len(resultFareCell)))
     for td in resultFareCell:
+        if index == 0:
+            index +=1
+            continue
         input = b("div[id='fareRadio']", td)
         radioValue = b("input", input).attr("value")
+        cabinObj = []
+        if len(resultFareCell) == 4:
+            cabinObj =cabinObj3
+        else:
+            cabinObj =cabinObj4
         if radioValue != None:
             rv = radioValue.replace('~','').replace(' ','')
+            print(rv)
             isFlight = True
             for a in afromFlight:
                 if a not in rv:
@@ -35,16 +51,16 @@ for tb in fromTableTr:
                     break
             if isFlight == False:
                 break
-            originalLowestFare = b("div[id='originalLowestFare']", td).text().replace(',','')
+            originalLowestFare = b(".price span", td).text().replace(',','').replace(' CNY','')
             typsJson = {}
             typsJson['currency'] = 'CNY'
-            typsJson['cabin'] = cabinObj[index]['code']
-            typsJson['cabinName'] = cabinObj[index]['name']
+            typsJson['cabin'] = cabinObj[index-1]['code']
+            typsJson['cabinName'] = cabinObj[index-1]['name']
             typsJson['adultPrice'] = originalLowestFare
             typsJson['adultTax'] = 0
             typsJson['priceTotal'] = originalLowestFare
             typsJson['radioValue'] = radioValue
-            fromJson[cabinObj[index]['code']] =  typsJson
+            fromJson[cabinObj[index-1]['code']] =  typsJson
         index +=1
 print(fromJson)
 print('............................................')
@@ -54,12 +70,20 @@ print('-------------------返程数据---------------------')
 retJson = {}
 fromTableTr =  b("tr[class='rgRow']", tablessss[1])
 for tb in fromTableTr:
-    resultFareCell = b("td[class='resultFareCell4']", tb)
+    resultFareCell = b("td", tb)
     index = 0
     for td in resultFareCell:
+        if index == 0:
+            index +=1
+            continue
         input = b("div[id='fareRadio']", td)
         radioValue = b("input", input).attr("value")
-        originalLowestFare = b("div[id='originalLowestFare']", td).text().replace(',','')
+        cabinObj = []
+        if len(resultFareCell) == 4:
+            cabinObj =cabinObj3
+        else:
+            cabinObj =cabinObj4
+        originalLowestFare = b(".price span", td).text().replace(',','').replace(' CNY','')
         if radioValue != None:
             rv = radioValue.replace('~','').replace(' ','')
             isFlight = True

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 375 - 0
src/test/company.py


+ 12 - 0
src/test/getIP.py

@@ -0,0 +1,12 @@
+#-*- coding:utf-8 -*-
+
+import requests
+import json
+
+
+session = requests.session()
+res = session.get('http://ip.16yun.cn:817/myip/pl/89932955-62b8-40bf-990b-fb1671267c51/?s=fpbefmgsks&u=laopeng')
+
+
+print(res.text)
+

+ 12 - 4
src/utils/CallbackOrderUtils.py

@@ -67,10 +67,18 @@ class CallbackOrderUtils():
             currency.AkFinalRate = json_str['AkFinalRate']                  #亚航调整后汇率
             return currency
         return
+    #获取代理IP
+    def getProxyIP(self):
+        session = requests.session()
+        res = session.get('http://ip.16yun.cn:817/myip/pl/89932955-62b8-40bf-990b-fb1671267c51/?s=fpbefmgsks&u=laopeng')
+        ip = res.text.split('\n')[0]
+        print(ip)
+        return ip.strip()
 if __name__ == '__main__':
     cout = CallbackOrderUtils()
-    cout.BallbackOrder('2018030915450779734174620', '1', 'YUNIHJ', '代理人占座', 'CNTRIPTOPK_ADMIN')
-    currency = cout.cityToCurrency('CAN')
-    print(currency.currencyCode)
-    
+    #cout.BallbackOrder('2018030915450779734174620', '1', 'YUNIHJ', '代理人占座', 'CNTRIPTOPK_ADMIN')
+    #currency = cout.cityToCurrency('CAN')
+    #print(currency.currencyCode)
+    ip = cout.getProxyIP()
+    print('----'+ip+'-----')