zhangqf 6 éve%!(EXTRA string=óta)
szülő
commit
32d64318c5

+ 20 - 12
src/AirasiaWeb.py

@@ -40,10 +40,9 @@ class AirasiaWeb(tornado.web.RequestHandler):
             start = time.clock()
             orderStatus = '1' #生单成功
             orderPnr = '' #下单成功后PNR
+            orderType = '代理人占座'
             orderServer = OrderServer(prarm)
             orderServer.LoadPrarm()
-            #代理代理Log self.proxy_handler
-            logging.info('代理:'+orderServer.oinfo.cid+str(orderServer.proxy_handler))
             if orderServer.isContinue:
                 orderServer.CurrencyQuery()
                 #-------------------查询官网价格与Big会员价格方法---------------------
@@ -52,6 +51,8 @@ class AirasiaWeb(tornado.web.RequestHandler):
                     _thread.start_new_thread(orderServer.WebQuery,())
                     _thread.start_new_thread(orderServer.WebQuery,())
                     _thread.start_new_thread(orderServer.WebQuery,())
+                    _thread.start_new_thread(orderServer.WebQuery,())
+                    _thread.start_new_thread(orderServer.WebQuery,())
                     #验证是否Big查询成功(3次重试机会)
                     _thread.start_new_thread(orderServer.BigQuery,())
                     _thread.start_new_thread(orderServer.BigQuery,())
@@ -73,25 +74,32 @@ class AirasiaWeb(tornado.web.RequestHandler):
                 if orderServer.AagenLogin():
                     orderServer.AgentSearch()#发起查询
                     orderServer.Parity()#比价
-                    flightHtml = orderServer.FlightSelected()#提交选择航班
-                    passHtml = orderServer.Passenger(flightHtml) #提交乘机人信息
-                    unitMapHtml = orderServer.AddOns(passHtml) #提交租车信息
-                    payHtml = orderServer.UnitMap(unitMapHtml) #选座
-                    PNR = orderServer.Payment(payHtml)#进行支付并且获取PNR码
-                    logging.info("-------哈哈,得到结果啦PNR:"+PNR)
-                    if len(PNR) == 6:
-                        orderPnr = PNR
+                    if 'BIG_ORDER' != orderServer.oinfo.modeOrder:
+                        flightHtml = orderServer.FlightSelected()#提交选择航班
+                        passHtml = orderServer.Passenger(flightHtml) #提交乘机人信息
+                        unitMapHtml = orderServer.AddOns(passHtml) #提交租车信息
+                        payHtml = orderServer.UnitMap(unitMapHtml) #选座
+                        PNR = orderServer.Payment(payHtml)#进行支付并且获取PNR码
+                        logging.info("-------哈哈,得到结果啦PNR:"+PNR)
+                        if len(PNR) == 6:
+                            orderPnr = PNR
+                        else:
+                            orderStatus = '2' #生单失败
                     else:
+                        #积分生单,回调
                         orderStatus = '2' #生单失败
+                        orderType = '积分占座'
             else:
                 logging.info('-----生单失败')
                 logging.info('-----orderServer.isContinue'+str(orderServer.isContinue))
+                if orderServer.isContinue == False:
+                    orderType = '套餐不占'
                 orderStatus = '2' #生单出错 BaseException Exception
         except BaseException as e:
             logging.info('-----生单失败'+str(e))
             orderStatus = '2' #生单出错
         cl = call()
-        cl.BallbackOrder(orderServer.oinfo.cid, orderStatus, orderPnr, '代理人占座', 'CNTRIPTOPK_ADMIN')
+        cl.BallbackOrder(orderServer.oinfo.cid, orderStatus, orderPnr, orderType, 'CNTRIPTOPK_ADMIN')
         logging.info('-------------------end time(s)-------------------')
         end = time.clock()
         logging.info("read: %f s" % (end - start))
@@ -117,7 +125,7 @@ class AirasiaAgentWeb(tornado.web.RequestHandler):
         try:
             orderServer = OrderServer(prarm)
             orderServer.LoadPrarm() #组装数据
-            logging.info('代理:'+orderServer.oinfo.cid+str(orderServer.proxy_handler))
+            #logging.info('代理:'+orderServer.oinfo.cid+str(orderServer.proxy_handler))
             orderServer.CurrencyQuery()#查询币种
             #-------------------Agent操作----------------------
             if orderServer.AagenLogin():

+ 70 - 17
src/order/OrderServer.py

@@ -5,7 +5,6 @@ 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
@@ -24,13 +23,6 @@ class OrderServer():
         self.queryInputJson = {}
         self.session = requests.session()
         self.__VIEWSTATE = ''
-        cl = call()
-        self.proxyurl = cl.getProxyIP()
-        self.proxy_handler = {
-            'http': 'http://'+self.proxyurl,
-            'https': 'https://'+self.proxyurl,
-        }
-        self.session.proxies = self.proxy_handler
         #请求头
         self.headers = {
             'Accept-Encoding': 'gzip',
@@ -216,6 +208,16 @@ class OrderServer():
             return False
     #代理人进行登录
     def AagenLogin(self):
+        
+        #添加代理IP
+        cl = call()
+        proxyurl = cl.getProxyIP()
+        proxy_handler = {
+            'http': 'http://'+proxyurl,
+            'https': 'https://'+proxyurl,
+        }
+        self.session.proxies = proxy_handler
+        logging.info(self.salt+'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]
@@ -233,6 +235,33 @@ class OrderServer():
         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 'err504' in agentHomeUrl:
+            proxyurl = cl.getProxyIP()
+            proxy_handler = {
+                'http': 'http://'+proxyurl,
+                'https': 'https://'+proxyurl,
+            }
+            self.session.proxies = proxy_handler
+            logging.info(self.salt+'前一个质量不高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']
+            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)
@@ -315,9 +344,9 @@ class OrderServer():
         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()
+#         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+'解析代理人查询结果完毕')
     #解析代理人查询结果
@@ -360,7 +389,10 @@ class OrderServer():
                             break
                     if isFlight == False:
                         break
-                    originalLowestFare = b(".price span", td).text().replace(',','').replace(' CNY','')
+                    pspan = b(".price span", td)
+                    price = pspan.eq(pspan.length-1).text()
+                    price = price[0:price.find('CNY')]
+                    originalLowestFare = price.replace(',','').replace(' ','')
                     typsJson = {}
                     typsJson['currency'] = 'CNY'
                     typsJson['cabin'] = cabinObj[index-1]['code']
@@ -401,7 +433,10 @@ class OrderServer():
                                 break
                         if isFlight == False:
                             break
-                        originalLowestFare = b(".price span", td).text().replace(',','').replace(' CNY','')
+                        pspan = b(".price span", td)
+                        price = pspan.eq(pspan.length-1).text()
+                        price = price[0:price.find('CNY')]
+                        originalLowestFare = price.replace(',','').replace(' ','')
                         typsJson = {}
                         typsJson['currency'] = 'CNY'
                         typsJson['cabin'] = cabinObj[index-1]['code']
@@ -434,7 +469,10 @@ class OrderServer():
             agfPrice = agfromPrice['EC']['priceTotal']
             agfromVal = agfromPrice['EC']['radioValue']
         if 'EP' in agfromPrice.keys():
-            if agfPrice == 0.0 or agfPrice < agfromPrice['EP']['priceTotal']:
+            if agfPrice != 0.0 and agfPrice > agfromPrice['EP']['priceTotal']:
+                agfPrice = agfromPrice['EP']['priceTotal']
+                agfromVal = agfromPrice['EP']['radioValue']
+            if agfPrice == 0.0:
                 agfPrice = agfromPrice['EP']['priceTotal']
                 agfromVal = agfromPrice['EP']['radioValue']
         if agretPrice != None:
@@ -442,10 +480,16 @@ class OrderServer():
                 agrPrice = agretPrice['EC']['priceTotal']
                 agretVal = agretPrice['EC']['radioValue']
             if 'EP' in agretPrice.keys():
-                if agrPrice == 0.0 or agrPrice < agretPrice['EP']['priceTotal']:
+                if agrPrice != 0.0 and agrPrice > agretPrice['EP']['priceTotal']:
+                    agrPrice = agretPrice['EP']['priceTotal']
+                    agretVal = agretPrice['EP']['radioValue']
+                if agrPrice == 0.0:
                     agrPrice = agretPrice['EP']['priceTotal']
                     agretVal = agretPrice['EP']['radioValue']
-         
+                    
+        logging.info(self.salt+'代理人去程:'+str(agfPrice)+'   __'+agfromVal)
+        logging.info(self.salt+'代理人回程:'+str(agrPrice)+'   __'+agretVal)
+        
         webfPrice = 0.0 #Web官网价格
         webrPrice = 0.0 #Web官网价格
         webfromVal = '' #Web官网去程提交字符串
@@ -459,6 +503,9 @@ class OrderServer():
             if 'EC' in webretPrice.keys():
                 webrPrice = webretPrice['EC']['priceTotal']
                 webretVal = webretPrice['EC']['radioValue']
+                
+        logging.info(self.salt+'Web官网去程:'+str(webfPrice) +'  __'+webfromVal)
+        logging.info(self.salt+'Web官网回程:'+str(webrPrice) +'  __'+webretVal)
         
         
         bigfPrice = 0.0 #Big积分价格
@@ -470,12 +517,16 @@ class OrderServer():
         if bigretPrice != None:
             if 'EC' in bigretPrice.keys():
                 bigrPrice = bigretPrice['EC']['priceTotal']
+        
+        logging.info(self.salt+'Big积分去程价:'+str(bigfPrice))
+        logging.info(self.salt+'Big积分回程价:'+str(bigrPrice))
                 
         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'
+                logging.info(self.salt+'-----Big价格优势')
                 return
         
         self.oinfo.modeOrder = 'AGENT_ORDER'
@@ -494,7 +545,9 @@ class OrderServer():
                 self.oinfo.retRadioValue = agretVal
         else:
             self.oinfo.retRadioValue = agretVal
-        
+        logging.info(self.salt+'生单方式:'+self.oinfo.modeOrder)
+        logging.info(self.salt+'去:'+self.oinfo.fromRadioValue)
+        logging.info(self.salt+'回:'+self.oinfo.retRadioValue)
     #亚航直接走代理人生单
     def AgentDirectOrder(self):    
         agfPrice = 0.0 #代理人价格

+ 2 - 2
src/query/AkBigQuery.py

@@ -16,7 +16,7 @@ class AkBigQuery:
         self.fxRate = fxRate
     def StartQuery(self):
         #开始执行时间
-        salt = ''.join(random.sample(string.ascii_letters + string.digits, 8))
+        salt = ''.join(random.sample(string.ascii_letters + string.digits, 16))+'|AKWEB'
         start = time.clock()
         queryUrl = 'http://128.14.29.146/bigsearch/airasia/big/app/testsearch'
         headers = {'Content-Type': 'application/json'}
@@ -89,7 +89,7 @@ class AkBigQuery:
                                 typsJson['adultPrice'] = round(i['adultPrice']*self.fxRate,2)
                                 typsJson['adultTax'] = round(i['adultTax']*self.fxRate,2)
                                 typsJson['priceTotal'] = round((i['adultPrice']+i['adultTax'])*self.fxRate,2)
-                            typsJson['radioValue'] = '0~O~~O00H00~AAB1~~2024~X|QZ~ 555~ ~~KUL~04/29/2018 21:50~DPS~04/30/2018 00:55~@04/29/2018 13:50:00'
+                            typsJson['radioValue'] = ''
                             retJson[i['cabin']] =  typsJson
                         break
         else:

+ 4 - 4
src/query/AkWebQuery.py

@@ -16,7 +16,7 @@ class AkWebQuery:
         self.fxRate = fxRate
     def StartQuery(self):
         start = time.clock()
-        salt = ''.join(random.sample(string.ascii_letters + string.digits, 8))
+        salt = ''.join(random.sample(string.ascii_letters + string.digits, 16))+'|AKWEB'
         queryUrl = 'http://128.14.29.146/bigsearch/ariasiaweb/newsearch'
         headers = {'Content-Type': 'application/json'}
         fromJson = {}
@@ -93,9 +93,9 @@ class AkWebQuery:
 if __name__ == '__main__':
     begin = datetime.datetime.now()
     
-    queryInputJson = {"adultNum":1,"childNum":0,"formCity":"KUL","fromDate":"2018-04-29","id":0,"retDate":"2018-05-29","toCity":"DPS","tripType":"2","uuid":"AKBing","currency":"CNY"}
-    flightList = 'QZ555'
-    retFlights = 'AK377'
+    queryInputJson = {"adultNum":1,"childNum":0,"formCity":"NNG","fromDate":"2018-05-02","id":0,"retDate":"2018-05-13","toCity":"UTP","tripType":"2","uuid":"AKBing","currency":""}
+    flightList = 'FD304'
+    retFlights = 'AK303'
     akweb = AkWebQuery(queryInputJson,2,flightList,retFlights,1)
     fromQueryJson,retQuerJson,isOk = akweb.StartQuery()
     print(fromQueryJson)

+ 12 - 6
src/test/AgentQueryHtmlTest.py

@@ -7,12 +7,12 @@ queryHtml = f.read()
 b = pq(queryHtml) 
     
     
-# afromFlight = 'FD3168,'.split(',')
-# aretFlight = ''.split(',')
-
-afromFlight = 'D7798,'.split(',')
+afromFlight = 'D7798,'.split(',')  #D7798
 aretFlight = ''.split(',')
 
+# afromFlight = 'AK126'.split(',')
+# aretFlight = 'AK127'.split(',')
+
     
 cabinObj4 = [{'code':'EC','name':'促销'}
             ,{'code':'EP','name':'低航费'}
@@ -51,7 +51,10 @@ for tb in fromTableTr:
                     break
             if isFlight == False:
                 break
-            originalLowestFare = b(".price span", td).text().replace(',','').replace(' CNY','')
+            pspan = b(".price span", td)
+            price = pspan.eq(pspan.length-1).text()
+            price = price[0:price.find('CNY')]
+            originalLowestFare = price.replace(',','').replace(' ','')
             typsJson = {}
             typsJson['currency'] = 'CNY'
             typsJson['cabin'] = cabinObj[index-1]['code']
@@ -83,7 +86,10 @@ for tb in fromTableTr:
             cabinObj =cabinObj3
         else:
             cabinObj =cabinObj4
-        originalLowestFare = b(".price span", td).text().replace(',','').replace(' CNY','')
+        pspan = b(".price span", td)
+        price = pspan.eq(pspan.length-1).text()
+        price = price[0:price.find('CNY')]
+        originalLowestFare = price.replace(',','').replace(' ','')
         if radioValue != None:
             rv = radioValue.replace('~','').replace(' ','')
             isFlight = True

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 110 - 0
src/test/BiJiaTest.py


+ 1 - 1
src/utils/CallbackOrderUtils.py

@@ -34,7 +34,7 @@ class CallbackOrderUtils():
         url = self.callbackurl+"orOrdertb/ballbackPrice"
         self.salt = orderNo+'|'
         fromParam = {}
-        fromParam['orderNo'] =   '2018030915450779734174620'  #orderNo
+        fromParam['orderNo'] = orderNo
         fromParam['webPrice'] = str({'go':webPriceGo,'back':webPriceBack})
         fromParam['agentPrice'] = str({'go':agentPriceGo,'back':agentPriceBack})
         fromParam['bigPrice'] = str({'go':bigPriceGo,'back':bigPriceBack})