zhangqf пре 6 година
родитељ
комит
1636c6ffef
6 измењених фајлова са 180 додато и 59 уклоњено
  1. 63 9
      src/AirasiaWeb.py
  2. 36 18
      src/order/OrderServer.py
  3. 32 18
      src/query/AkBigQuery.py
  4. 3 2
      src/query/AkWebQuery.py
  5. 1 1
      src/test/PessHtmlTest.py
  6. 45 11
      src/utils/CallbackOrderUtils.py

+ 63 - 9
src/AirasiaWeb.py

@@ -19,11 +19,51 @@ def config_log():
     logging.getLogger('').addHandler(console)
 
 #定义处理类型
+class AirasiaWebTest(tornado.web.RequestHandler):
+    #添加一个处理get请求方式的方法
+    def get(self):
+        #向响应中,添加数据
+        respEntity = {'attachment':'生单任务启动','status':'200'}
+        self.write(respEntity)
+        
+    def post(self):
+        param = self.request.body.decode('utf-8')
+        logging.info('生单数据:'+param)
+        print('生单数据:'+param)
+        prarm = json.loads(param)
+        try:
+            _thread.start_new_thread(self.akorder,(prarm,))
+        except:
+            print('Error: 无法启动线程')
+        
+        respEntity = {'attachment':'生单任务启动','status':'200'}
+        self.write(respEntity)
+    def akorder(self,prarm):
+        #开始执行时间
+        start = time.clock()
+        orderStatus = '2' #生单成功
+        orderPnr = '' #下单成功后PNR
+        orderType = '代理人占座'
+        orderServer = OrderServer(prarm)
+        orderServer.LoadPrarm() 
+        cl = call()
+        logging.info('确定返回通道:'+str(orderServer.sign))
+        if orderServer.sign == True:
+            cl.brushOrderCallBack(orderServer.oinfo.cid, orderStatus, orderPnr, orderType, 'CNTRIPTOPK_ADMIN',orderServer.passengerIds)
+        else:
+            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))
+        
+#定义处理类型
 class AirasiaWeb(tornado.web.RequestHandler):
     #添加一个处理get请求方式的方法
     def get(self):
         #向响应中,添加数据
-        self.write('这里是亚航生单API。')
+        respEntity = {'attachment':'生单任务启动','status':'200'}
+        self.write(respEntity)
+        
     def post(self):
         param = self.request.body.decode('utf-8')
         logging.info('生单数据:'+param)
@@ -34,7 +74,8 @@ class AirasiaWeb(tornado.web.RequestHandler):
         except:
             print('Error: 无法启动线程')
         
-        self.write('Ok')
+        respEntity = {'attachment':'生单任务启动','status':'200'}
+        self.write(respEntity)
     def akorder(self,prarm):
         #开始执行时间
         try:
@@ -50,19 +91,24 @@ class AirasiaWeb(tornado.web.RequestHandler):
                 try:
                     #验证是否Web查询成功(3次重试机会) 
                     _thread.start_new_thread(orderServer.WebQuery,())
+                    _thread.start_new_thread(orderServer.BigQuery,())
+                    time.sleep(1)
                     _thread.start_new_thread(orderServer.WebQuery,())
+                    _thread.start_new_thread(orderServer.BigQuery,())
+                    time.sleep(1)
                     _thread.start_new_thread(orderServer.WebQuery,())
+                    _thread.start_new_thread(orderServer.BigQuery,())
+                    time.sleep(1)
                     _thread.start_new_thread(orderServer.WebQuery,())
+                    time.sleep(1)
                     _thread.start_new_thread(orderServer.WebQuery,())
                     #验证是否Big查询成功(3次重试机会)
-                    _thread.start_new_thread(orderServer.BigQuery,())
-                    _thread.start_new_thread(orderServer.BigQuery,())
-                    _thread.start_new_thread(orderServer.BigQuery,())
+                    
                 except:
                     logging.info('Error: 无法启动线程')
                 logging.info('-------------------查询发起成功,刷新执行结果-------')
                 counter = 1
-                while counter < 25:
+                while counter < 20:
                     if orderServer.checkQuery():
                         print('----------------亲,已经刷新到结果啦.......可以继续下一步了')
                         break
@@ -90,6 +136,8 @@ class AirasiaWeb(tornado.web.RequestHandler):
                         #积分生单,回调
                         orderStatus = '2' #生单失败
                         orderType = '积分占座'
+                else:
+                    orderStatus = '2' #生单失败
             else:
                 logging.info('-----生单失败')
                 logging.info('-----orderServer.isContinue'+str(orderServer.isContinue))
@@ -100,7 +148,12 @@ class AirasiaWeb(tornado.web.RequestHandler):
             logging.info('-----生单失败'+str(e))
             orderStatus = '2' #生单出错
         cl = call()
-        cl.BallbackOrder(orderServer.oinfo.cid, orderStatus, orderPnr, orderType, 'CNTRIPTOPK_ADMIN')
+        logging.info('确定返回通道:'+str(orderServer.sign))
+        if orderServer.sign == True:
+            cl.brushOrderCallBack(orderServer.oinfo.cid, orderStatus, orderPnr, orderType, 'CNTRIPTOPK_ADMIN',orderServer.passengerIds)
+        else:
+            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 +170,8 @@ class AirasiaAgentWeb(tornado.web.RequestHandler):
             _thread.start_new_thread(self.akorder,(prarm,))
         except:
             logging.info('Error: 无法启动线程')
-        self.write('Ok')
+        respEntity = {'attachment':'生单任务启动','status':'200'}
+        self.write(respEntity)
     def akorder(self,prarm):
         #开始执行时间
         start = time.clock()
@@ -153,7 +207,7 @@ class AirasiaAgentWeb(tornado.web.RequestHandler):
 if __name__ == '__main__':
     config_log()
     #创建一个应用对象
-    app = tornado.web.Application([(r'/akOrder',AirasiaWeb),(r'/akAgOrder',AirasiaAgentWeb)])
+    app = tornado.web.Application([(r'/akOrder',AirasiaWeb),(r'/akAgOrder',AirasiaAgentWeb),(r'/akOrderTest',AirasiaWebTest)])
     #绑定一个监听端口
     app.listen(8888)
     #启动web程序,开始监听端口的连接

+ 36 - 18
src/order/OrderServer.py

@@ -4,6 +4,7 @@ import urllib3
 import requests
 import time
 import datetime
+import threading
 import re
 from lxml import etree
 from pyquery import PyQuery as pq
@@ -11,7 +12,6 @@ from entity.OrderInfo import OrderInfo,Contact,Passengers,Segments
 from utils.CallbackOrderUtils import CallbackOrderUtils as call
 from query.AkWebQuery import AkWebQuery
 from query.AkBigQuery import AkBigQuery
-from imghdr import test_webp
 urllib3.disable_warnings()
 import logging
 
@@ -50,6 +50,12 @@ class OrderServer():
         self.passengers_infant = []#婴儿乘客
         #行李 PBAB:20Kg PBAC:25Kg PBAD:30Kg PBAF:40Kg
         self.luggageDict = {20:'PBAB',25:'PBAC',30:'PBAD',40:'PBAF'} 
+        
+        self._web_value_lock = threading.Lock() #实例化 Web查询
+        self._big_value_lock = threading.Lock() #实例化 Big查询
+        
+        self.sign = False  #是否刷单标记
+        self.passengerIds = [] #乘机人ID  List
     #获取订单信息
     def LoadPrarm(self):
         self.salt = self.json_str['cid']+'|'
@@ -64,6 +70,12 @@ class OrderServer():
         self.oinfo.adultNum =self.json_str['adultNum']   #成人乘客数
         self.oinfo.childNum =self.json_str['childNum']   #儿童乘客数
         
+        if 'data' in self.json_str.keys():
+            if 'sign' in self.json_str['data'].keys():
+                self.sign = self.json_str['data']['sign']
+                self.passengerIds = self.json_str['data']['passengerIds']
+                logging.info(self.salt+'特哥的,这里是刷单。谢林杰')
+        
         #获取联系人信息
         contact = Contact()
         contact.firstname = self.json_str['contactEntity']['firstName'] #名
@@ -179,29 +191,33 @@ class OrderServer():
     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
+#         self._web_value_lock.acquire()#web结果锁 开始
+#         if self.oinfo.webIsOk:
+#             return
         logging.info(self.salt+'WebQuer:'+str(isOk))
         logging.info(self.salt+'Web去程:'+json.dumps(akQueryWebFrom))
         logging.info(self.salt+'Web返程:'+json.dumps(akQueryWebRet))
+        self.oinfo.webIsOk = isOk
+        self.oinfo.webFromJson = akQueryWebFrom
+        self.oinfo.webRetJson = akQueryWebRet
         #判断对象是否为空
-        if self.oinfo.webIsOk == False:
-            self.oinfo.webIsOk = isOk
-            self.oinfo.webFromJson = akQueryWebFrom
-            self.oinfo.webRetJson = akQueryWebRet
+#         if self.oinfo.webIsOk == False:
+#         self._web_value_lock.release() #web结果锁 开始
     #发起Big查询
     def BigQuery(self):
         akbigQuer = AkBigQuery(self.queryInputJson,self.oinfo.tripType,self.oinfo.fromFlight,self.oinfo.retFlight,self.oinfo.fxRate)
         akQueryBigFrom,akQueryBigRet,isOk = akbigQuer.StartQuery()
-        if self.oinfo.bigIsOk:
-            return
+#         self._big_value_lock.acquire()#web结果锁 开始
+#         if self.oinfo.bigIsOk:
+#             return
+        self.oinfo.bigIsOk = isOk
+        self.oinfo.bigFromJson = akQueryBigFrom
+        self.oinfo.bigRetJson = 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
-            self.oinfo.bigRetJson = akQueryBigRet
+#         if self.oinfo.bigIsOk == False:
+#         self._big_value_lock.release() #web结果锁 开始
     def checkQuery(self):
         if self.oinfo.bigIsOk and self.oinfo.webIsOk:
             return True
@@ -212,7 +228,7 @@ class OrderServer():
         
         #添加代理IP
         cl = call()
-        proxyurl = cl.getProxyFixedIP()
+        proxyurl = cl.getProxyIP()
         proxy_handler = {
             'http': 'http://'+proxyurl,
             'https': 'https://'+proxyurl,
@@ -432,7 +448,7 @@ class OrderServer():
     def Parity(self):
         #先回调价格,其次比价EC EP   
         cl = call()
-        cl.BallbackPrice(self.oinfo.cid, str(self.oinfo.webFromJson),str(self.oinfo.webRetJson), str(self.oinfo.agentFromJson),str(self.oinfo.agentRetJson),str(self.oinfo.bigFromJson),str(self.oinfo.bigRetJson))
+        cl.BallbackPrice(self.oinfo.cid, str(self.oinfo.webFromJson),str(self.oinfo.webRetJson), str(self.oinfo.agentFromJson),str(self.oinfo.agentRetJson),str(self.oinfo.bigFromJson),str(self.oinfo.bigRetJson),self.sign)
         
         agfPrice = 0.0 #代理人价格
         agrPrice = 0.0 #代理人价格
@@ -495,10 +511,10 @@ class OrderServer():
         
         logging.info(self.salt+'Big积分去程价:'+str(bigfPrice))
         logging.info(self.salt+'Big积分回程价:'+str(bigrPrice))
-                
+        logging.info(self.salt+'Big积分加价55,然后再比价!')
         if bigfPrice != 0.0:        
             #一决雌雄  使用那种方式生单  AGENT_ORDER WEB_ORDER BIG_ORDER
-            bigp = bigfPrice + bigrPrice
+            bigp = bigfPrice + bigrPrice+55
             webp = webfPrice + webrPrice
             agp  = agfPrice + agrPrice
             if webp != 0.0:
@@ -671,6 +687,9 @@ class OrderServer():
         #舒适套件
         for row in page.xpath("//div[starts-with(@class,'uccomfortkitpanel-item-selection-form')]/input/@name"):
             passengerData[row] = '0'
+            
+        #行李 PBAB:20Kg PBAC:25Kg PBAD:30Kg PBAF:40Kg
+        #self.luggageDict = {20:'PBAB',25:'PBAC',30:'PBAD',40:'PBAF'}
         #行李选择
         for row in page.xpath("//div[starts-with(@class,'dropdown-styled')]/select/@name"):
             if '_previousSsr_' in row:
@@ -804,7 +823,6 @@ class OrderServer():
             '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))

+ 32 - 18
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, 16))+'|AKWEB'
+        salt = ''.join(random.sample(string.ascii_letters + string.digits, 16))+'|AKBIG'
         start = time.clock()
         queryUrl = 'http://128.14.29.146/bigsearch/airasia/big/app/testsearch'
         headers = {'Content-Type': 'application/json'}
@@ -24,14 +24,15 @@ class AkBigQuery:
         retJson = {}
         isOk = True
         session = requests.session()
-#         logging.info(salt+"|queryUrl:"+queryUrl)
-#         logging.info(salt+"|tripType:"+str(self.tripType))
-#         logging.info(salt+"|flightList:"+str(self.flightList))
-#         logging.info(salt+"|retFlights:"+str(self.retFlights))
-#         logging.info(salt+"|fxRate:"+str(self.fxRate))
-#         logging.info(salt+"|queryInputJson:"+str(self.queryInputJson))
+        logging.info(salt+"|queryUrl:"+queryUrl)
+        logging.info(salt+"|tripType:"+str(self.tripType))
+        logging.info(salt+"|flightList:"+str(self.flightList))
+        logging.info(salt+"|retFlights:"+str(self.retFlights))
+        logging.info(salt+"|fxRate:"+str(self.fxRate))
+        logging.info(salt+"|queryInputJson:"+str(self.queryInputJson))
         res = session.post(queryUrl, headers=headers, json=self.queryInputJson)
         #logging.info(salt+"|retJson:"+res.text)
+        #print(res.text)
         json_str = json.loads(res.text)
         if 200 == json_str['status']:
             fromSegments = json_str['attachment']['fromSegments']
@@ -48,7 +49,7 @@ class AkBigQuery:
                     airlinePriceInfos = routeInfoEntities = k['airlinePriceInfos']
                     for i in airlinePriceInfos:
                         typsJson = {}
-                        typsJson['currency'] = k['currency']
+                        typsJson['currency'] = 'CNY'
                         typsJson['cabin'] = i['cabin']
                         typsJson['cabinName'] = i['cabinName']
                         if k['currency'] == 'CNY':
@@ -59,9 +60,12 @@ 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'] = ''
-                        fromJson[i['cabin']] =  typsJson
+                        if i['cabin'] in fromJson.keys():
+                            if fromJson[i['cabin']]['priceTotal'] > typsJson['priceTotal']:
+                                fromJson[i['cabin']] =  typsJson
+                        else:
+                            fromJson[i['cabin']] =  typsJson
                     break
             if 2 == self.tripType:
                 retSegments = json_str['attachment']['retSegments']
@@ -78,7 +82,7 @@ class AkBigQuery:
                         airlinePriceInfos = routeInfoEntities = k['airlinePriceInfos']
                         for i in airlinePriceInfos:
                             typsJson = {}
-                            typsJson['currency'] = k['currency']
+                            typsJson['currency'] = 'CNY'
                             typsJson['cabin'] = i['cabin']
                             typsJson['cabinName'] = i['cabinName']
                             if k['currency'] == 'CNY':
@@ -90,7 +94,11 @@ class AkBigQuery:
                                 typsJson['adultTax'] = round(i['adultTax']*self.fxRate,2)
                                 typsJson['priceTotal'] = round((i['adultPrice']+i['adultTax'])*self.fxRate,2)
                             typsJson['radioValue'] = ''
-                            retJson[i['cabin']] =  typsJson
+                            if i['cabin'] in fromJson.keys():
+                                if fromJson[i['cabin']]['priceTotal'] > typsJson['priceTotal']:
+                                    retJson[i['cabin']] =  typsJson
+                            else:
+                                retJson[i['cabin']] =  typsJson
                         break
         else:
             isOk =False
@@ -102,17 +110,23 @@ class AkBigQuery:
         return (fromJson,retJson,isOk)
 if __name__ == '__main__':
     
-    
+#     aaa = {}
+#     
+#     aaa['EC'] = 123456
+#     if 'EP' in aaa.keys():
+#         aaa['EC'] = 258741
+#     
+#     print(aaa)
     
     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'
-    akbig = AkBigQuery(queryInputJson,2,flightList,retFlights,1)
+    queryInputJson = {"adultNum":1,"childNum":0,"formCity":"KUL","fromDate":"2018-05-13","id":0,"retDate":"","toCity":"CKG","tripType":"1","uuid":"AKBing","currency":"MYR"}
+    flightList = 'D7808'
+    retFlights = 'AK303'
+    akbig = AkBigQuery(queryInputJson,1,flightList,retFlights,1)
     fromQueryJson,retQuerJson,isOk = akbig.StartQuery()
     print(fromQueryJson)
     print(retQuerJson)
-        
+         
     end = datetime.datetime.now()
     k = end - begin
     print(k.total_seconds())

+ 3 - 2
src/query/AkWebQuery.py

@@ -7,6 +7,7 @@ import time
 import random
 import string
 
+
 class AkWebQuery:
     def __init__(self,queryInputJson,tripType,flightList,retFlights,fxRate):
         self.flightList = flightList
@@ -23,7 +24,7 @@ class AkWebQuery:
         retJson = {}
         isOk = True
         session = requests.session()
-#         logging.info(salt+"|queryUrl:"+queryUrl)
+        logging.info(salt+"|queryUrl:"+queryUrl)
 #         logging.info(salt+"|tripType:"+str(self.tripType))
 #         logging.info(salt+"|flightList:"+str(self.flightList))
 #         logging.info(salt+"|retFlights:"+str(self.retFlights))
@@ -32,7 +33,7 @@ class AkWebQuery:
         res = session.post(queryUrl, headers=headers, json=self.queryInputJson)
         #print(res.status_code)
         #logging.info(salt+"|retJson:"+res.text)
-        #print(res.text)
+        print(res.text)
         json_str = json.loads(res.text)
         if 200 == json_str['status']:
             fromSegments = json_str['attachment']['fromSegments']

+ 1 - 1
src/test/PessHtmlTest.py

@@ -3,7 +3,7 @@
 from pyquery import PyQuery as pq
 from lxml import etree
 
-f = open('E://testSelect.html',encoding='utf-8')
+f = open('E://ak/testSelect.html',encoding='utf-8')
 queryHtml = f.read()
 b = pq(queryHtml) 
 page = etree.HTML(queryHtml)

Разлика између датотеке није приказан због своје велике величине
+ 45 - 11
src/utils/CallbackOrderUtils.py