Selaa lähdekoodia

提交测试版本

zhangqf 6 vuotta sitten
vanhempi
commit
e735392278

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 240 - 223
src/entity/OrderInfo.py


+ 21 - 0
src/entity/__init__.py

@@ -0,0 +1,21 @@
+#-*- coding:utf-8 -*-
+
+# print('AK117,AK72,'[0:-1])
+# print('AK117,'[0:-1])
+# print('AK117,AK72,AK72,'[0:-1])
+# 
+# 
+# afromFlight = 'AK117,AK72'.split(',')
+# 
+# for a in afromFlight:
+#     print('----'+a)
+#     
+# aa = '1~IF~~IF1F00H~AAB1~~39~^2~IF~~IF1F06H~AAB1~~1~X|AK~ 117~ ~~CAN~04/28/2018 22:00~KUL~04/29/2018 02:05~^AK~  72~ ~~KUL~04/29/2018 18:55~MLE~04/29/2018 20:10~@04/28/2018 14:00:00'
+# aa = aa.replace('~','').replace(' ','')
+# print(aa)
+# 
+# for a in afromFlight:
+#     if a not in aa:
+#         print('不在')
+#     else:
+#         print('在呢')

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 707 - 0
src/order/OrderServer.py


+ 1 - 0
src/order/Test.py

@@ -93,6 +93,7 @@ print(oinfo.toCity)
 print(oinfo.fromDate)
 print(oinfo.retDate)
 
+#调用货币查询结果
 stationCode = oinfo.formCity
 cl = call()
 currency = cl.cityToCurrency(oinfo.formCity)

+ 23 - 8
src/query/AkBigQuery.py

@@ -4,16 +4,18 @@ import requests
 import datetime
 
 class AkBigQuery:
-    def __init__(self,queryInputJson,tripType,flightList,retFlights):
+    def __init__(self,queryInputJson,tripType,flightList,retFlights,fxRate):
         self.flightList = flightList
         self.retFlights = retFlights
         self.tripType = tripType
         self.queryInputJson = queryInputJson
+        self.fxRate = fxRate
     def StartQuery(self):
         queryUrl = 'http://128.14.29.146/bigsearch/airasia/big/app/testsearch'
         headers = {'Content-Type': 'application/json'}
         fromJson = {}
         retJson = {}
+        isOk = True
         session = requests.session()
         res = session.post(queryUrl, headers=headers, json=self.queryInputJson)
         print(res.text)
@@ -36,9 +38,15 @@ class AkBigQuery:
                         typsJson['currency'] = k['currency']
                         typsJson['cabin'] = i['cabin']
                         typsJson['cabinName'] = i['cabinName']
-                        typsJson['adultPrice'] = i['adultPrice']
-                        typsJson['adultTax'] = i['adultTax']
-                        typsJson['priceTotal'] = round(i['adultPrice']+i['adultTax'],2)
+                        if k['currency'] == 'CNY':
+                            typsJson['adultPrice'] = i['adultPrice']
+                            typsJson['adultTax'] = i['adultTax']
+                            typsJson['priceTotal'] = round(i['adultPrice']+i['adultTax'],2)
+                        else:
+                            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
                     break
@@ -60,13 +68,20 @@ class AkBigQuery:
                             typsJson['currency'] = k['currency']
                             typsJson['cabin'] = i['cabin']
                             typsJson['cabinName'] = i['cabinName']
-                            typsJson['adultPrice'] = i['adultPrice']
-                            typsJson['adultTax'] = i['adultTax']
-                            typsJson['priceTotal'] = round(i['adultPrice']+i['adultTax'],2)
+                            if k['currency'] == 'CNY':
+                                typsJson['adultPrice'] = i['adultPrice']
+                                typsJson['adultTax'] = i['adultTax']
+                                typsJson['priceTotal'] = round(i['adultPrice']+i['adultTax'],2)
+                            else:
+                                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'
                             retJson[i['cabin']] =  typsJson
                         break
-        return (fromJson,retJson)
+        else:
+            isOk =False
+        return (fromJson,retJson,isOk)
 if __name__ == '__main__':
     begin = datetime.datetime.now()
 

+ 8 - 4
src/query/AkWebQuery.py

@@ -4,16 +4,18 @@ import requests
 import datetime
 
 class AkWebQuery:
-    def __init__(self,queryInputJson,tripType,flightList,retFlights):
+    def __init__(self,queryInputJson,tripType,flightList,retFlights,fxRate):
         self.flightList = flightList
         self.retFlights = retFlights
         self.tripType = tripType
         self.queryInputJson = queryInputJson
+        self.fxRate = fxRate
     def StartQuery(self):
-        queryUrl = 'http://128.14.30.106/spider/ariasiaweb/testsearch'
+        queryUrl = 'http://128.14.29.146/bigsearch/ariasiaweb/newsearch'
         headers = {'Content-Type': 'application/json'}
         fromJson = {}
         retJson = {}
+        isOk = True
         session = requests.session()
         res = session.post(queryUrl, headers=headers, json=self.queryInputJson)
         #print(res.status_code)
@@ -67,14 +69,16 @@ class AkWebQuery:
                             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'
                             retJson[i['cabin']] =  typsJson
                         break
-        return (fromJson,retJson)
+        else:
+            isOk =False
+        return (fromJson,retJson,isOk)
 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'
-    akweb = AkWebQuery(queryInputJson,2,flightList,retFlights)
+    akweb = AkWebQuery(queryInputJson,2,flightList,retFlights,1)
     fromQueryJson,retQuerJson = akweb.StartQuery()
     print(fromQueryJson)
     print(retQuerJson)

+ 21 - 0
src/query/__init__.py

@@ -0,0 +1,21 @@
+#-*- coding:utf-8 -*-
+# import _thread
+# import time
+# 
+# # 为线程定义一个函数
+# def print_time( threadName, delay):
+#    count = 0
+#    while count < 5:
+#       time.sleep(delay)
+#       count += 1
+#       print ("%s: %s" % ( threadName, time.ctime(time.time()) ))
+# 
+# # 创建两个线程
+# try:
+#    _thread.start_new_thread( print_time, ("Thread-1", 2, ) )
+#    _thread.start_new_thread( print_time, ("Thread-2", 4, ) )
+# except:
+#    print ("Error: 无法启动线程")
+# 
+# while 1:
+#    pass

+ 85 - 0
src/test/AgentQueryHtmlTest.py

@@ -0,0 +1,85 @@
+#-*- coding:utf-8 -*-
+
+from pyquery import PyQuery as pq
+
+f = open('E://testSelect.html',encoding='utf-8')
+queryHtml = f.read()
+b = pq(queryHtml) 
+    
+    
+afromFlight = 'AK119,D7178'.split(',')
+aretFlight = 'D7179,AK118'.split(',')
+
+    
+cabinObj = [{'code':'EC','name':'促销'}
+            ,{'code':'EP','name':'低航费'}
+            ,{'code':'HF','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)
+    index = 0
+    for td in resultFareCell:
+        input = b("div[id='fareRadio']", td)
+        radioValue = b("input", input).attr("value")
+        if radioValue != None:
+            rv = radioValue.replace('~','').replace(' ','')
+            isFlight = True
+            for a in afromFlight:
+                if a not in rv:
+                    isFlight = False
+                    break
+            if isFlight == False:
+                break
+            originalLowestFare = b("div[id='originalLowestFare']", td).text().replace(',','')
+            typsJson = {}
+            typsJson['currency'] = 'CNY'
+            typsJson['cabin'] = cabinObj[index]['code']
+            typsJson['cabinName'] = cabinObj[index]['name']
+            typsJson['adultPrice'] = originalLowestFare
+            typsJson['adultTax'] = 0
+            typsJson['priceTotal'] = originalLowestFare
+            typsJson['radioValue'] = radioValue
+            fromJson[cabinObj[index]['code']] =  typsJson
+        index +=1
+print(fromJson)
+print('............................................')
+    
+    
+print('-------------------返程数据---------------------')    
+retJson = {}
+fromTableTr =  b("tr[class='rgRow']", tablessss[1])
+for tb in fromTableTr:
+    resultFareCell = b("td[class='resultFareCell4']", tb)
+    index = 0
+    for td in resultFareCell:
+        input = b("div[id='fareRadio']", td)
+        radioValue = b("input", input).attr("value")
+        originalLowestFare = b("div[id='originalLowestFare']", td).text().replace(',','')
+        if radioValue != None:
+            rv = radioValue.replace('~','').replace(' ','')
+            isFlight = True
+            for a in aretFlight:
+                if a not in rv:
+                    isFlight = False
+                    break
+            if isFlight == False:
+                break
+            typsJson = {}
+            typsJson['currency'] = 'CNY'
+            typsJson['cabin'] = cabinObj[index]['code']
+            typsJson['cabinName'] = cabinObj[index]['name']
+            typsJson['adultPrice'] = originalLowestFare
+            typsJson['adultTax'] = 0
+            typsJson['priceTotal'] = originalLowestFare
+            typsJson['radioValue'] = radioValue
+            retJson[cabinObj[index]['code']] =  typsJson
+        index +=1
+print(retJson)
+print('............................................')
+
+f.close()

+ 27 - 0
src/test/GreatHtmlTest.py

@@ -0,0 +1,27 @@
+#-*- coding:utf-8 -*-
+
+from pyquery import PyQuery as pq
+from lxml import etree
+
+# f = open('E://testTraveler.html',encoding='utf-8')
+# queryHtml = f.read()
+# b = pq(queryHtml) 
+# page = etree.HTML(queryHtml)
+# 
+# for row in page.xpath("//div[starts-with(@class,'ctw-book')]/input/@name"):
+#     print(row)
+
+
+f = open('E://testAddOns.html',encoding='utf-8')
+queryHtml = f.read()
+b = pq(queryHtml) 
+page = etree.HTML(queryHtml)
+
+inputs = b.find("#passengerListBody input")
+for row in inputs:
+    name = pq(row)
+    print(name.attr("name"))
+    print(name.attr("value"))
+    
+# for row in page.xpath("//table[@class,'clearTableHeaders']/input/@name"):
+#     print(row)

+ 34 - 0
src/test/PessHtmlTest.py

@@ -0,0 +1,34 @@
+#-*- coding:utf-8 -*-
+
+from pyquery import PyQuery as pq
+from lxml import etree
+
+f = open('E://testSelect.html',encoding='utf-8')
+queryHtml = f.read()
+b = pq(queryHtml) 
+page = etree.HTML(queryHtml)
+
+print('--------------------选择行李')
+for row in page.xpath("//div[starts-with(@class,'dropdown-styled')]/select/@name"):
+    print(row)
+
+print('--------------------餐食选择')
+#餐食选择
+for row in page.xpath("//div[starts-with(@class,'ucmealpanel-item-selection-form')]/input/@name"):
+    print(row)
+
+print('--------------------选择舒适套件')
+
+#选择舒适套件
+for row in page.xpath("//div[starts-with(@class,'uccomfortkitpanel-item-selection-form')]/input/@name"):
+    print(row)
+
+
+
+HiFlyerFare = page.xpath("//input[@name='HiFlyerFare']/@value")
+print('HiFlyerFare:'+str(HiFlyerFare))
+HiddenFieldPageBookingData = page.xpath("//input[@name='HiddenFieldPageBookingData']/@value")
+print('HiddenFieldPageBookingData:'+str(HiddenFieldPageBookingData))
+
+print('----------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------------------')
+

+ 0 - 0
src/test/__init__.py


+ 12 - 10
src/utils/CallbackOrderUtils.py

@@ -5,8 +5,8 @@ from entity.OrderInfo import Currency
 
 class CallbackOrderUtils():
     
-    callbackurl = "http://203.130.42.247/mgr/"
-    #callbackurl = "http://192.168.1.5:11009/"
+    #callbackurl = "http://203.130.42.247/mgr/"
+    callbackurl = "http://192.168.1.5:11009/"
     
     def __init__(self):
         '''
@@ -25,14 +25,15 @@ class CallbackOrderUtils():
         res = session.post(url,data=fromParam)
         print(res.text)
     #回调价格
-    def BallbackPrice(self,orderNo,webPrice,agentPrice,bigPrice):
+    def BallbackPrice(self,orderNo,webPriceGo,webPriceBack,agentPriceGo,agentPriceBack,bigPriceGo,bigPriceBack):
         url = self.callbackurl+"orOrdertb/ballbackPrice"
-        print(url)
+        print('价格回调:'+url)
         fromParam = {}
-        fromParam['orderNo'] = orderNo
-        fromParam['webPrice'] = webPrice
-        fromParam['agentPrice'] = agentPrice
-        fromParam['bigPrice'] = bigPrice
+        fromParam['orderNo'] = '2018021015034810637110181' #orderNo
+        fromParam['webPrice'] = str({'go':webPriceGo,'back':webPriceBack})
+        fromParam['agentPrice'] = str({'go':agentPriceGo,'back':agentPriceBack})
+        fromParam['bigPrice'] = str({'go':bigPriceGo,'back':bigPriceBack})
+        print(str(fromParam))
         session = requests.session()
         res = session.post(url,data=fromParam)
         print(res.text)
@@ -45,6 +46,7 @@ class CallbackOrderUtils():
         session = requests.session()
         res = session.post(url,data=fromParam)
         json_str = json.loads(res.text)
+        print(json_str)
         if 200 == json_str['status']:
             json_str = json_str['attachment']
             currency = Currency()
@@ -61,7 +63,7 @@ class CallbackOrderUtils():
 if __name__ == '__main__':
     cout = CallbackOrderUtils()
     #cout.BallbackOrder('2018030915450779734174620', '1', 'YUNIHJ', '代理人占座', 'CNTRIPTOPK_ADMIN')
-    retText = cout.cityToCurrency('CAN')
-    print(retText)
+    currency = cout.cityToCurrency('CAN')
+    print(currency.currencyCode)
     
     

+ 114 - 0
src/webserver/AirasiaWeb.py

@@ -0,0 +1,114 @@
+#-*- coding:utf-8 -*-
+# !/usr/local/bin/python
+
+import tornado.web
+import tornado.ioloop
+import json
+import time
+import _thread
+from order.OrderServer import OrderServer
+from utils.CallbackOrderUtils import CallbackOrderUtils as call
+
+
+#定义处理类型
+class AirasiaWeb(tornado.web.RequestHandler):
+    #添加一个处理get请求方式的方法
+    def get(self):
+        #向响应中,添加数据
+        self.write('这里是亚航生单API。')
+    def post(self):
+        param = self.request.body.decode('utf-8')
+        prarm = json.loads(param)
+        try:
+            _thread.start_new_thread(self.akorder,(prarm,))
+        except:
+            print('Error: 无法启动线程')
+        
+        self.write('Ok')
+    def akorder(self,prarm):
+        #开始执行时间
+        start = time.clock()
+        orderServer = OrderServer(prarm)
+        orderServer.LoadPrarm()
+        orderServer.CurrencyQuery()
+        #-------------------查询官网价格与Big会员价格方法---------------------
+        try:
+            #验证是否Web查询成功(3次重试机会) 
+            _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,())
+            _thread.start_new_thread(orderServer.BigQuery,())
+        except:
+            print('Error: 无法启动线程')
+        print('-------------------查询发起成功,刷新执行结果-------')
+        counter = 1
+        while counter < 15:
+            if orderServer.checkQuery():
+                print('----------------亲,已经刷新到结果啦.......可以继续下一步了')
+                break
+            print('-----------我在这里刷新查询结果:'+str(counter))
+            time.sleep(1)
+            counter += 1
+        #-------------------Agent操作----------------------
+        if orderServer.AagenLogin():
+            orderServer.AgentSearch()#发起查询
+            orderServer.Parity()#比价
+            orderServer.FlightSelected()#提交选择航班
+        print('-------------------end time(s)-------------------')
+        end = time.clock()
+        print ("read: %f s" % (end - start))
+#定义亚航代理人直接生单
+class AirasiaAgentWeb(tornado.web.RequestHandler):
+    #添加一个处理get请求方式的方法
+    def get(self):
+        #向响应中,添加数据
+        self.write('这里是亚航代理人生单API。')
+    def post(self):
+        param = self.request.body.decode('utf-8')
+        prarm = json.loads(param)
+        try:
+            _thread.start_new_thread(self.akorder,(prarm,))
+        except:
+            print('Error: 无法启动线程')
+        self.write('Ok')
+    def akorder(self,prarm):
+        #开始执行时间
+        start = time.clock()
+        orderStatus = '1' #生单成功
+        orderPnr = '' #下单成功后PNR
+        try:
+            orderServer = OrderServer(prarm)
+            orderServer.LoadPrarm() #组装数据
+            orderServer.CurrencyQuery()#查询币种
+            #-------------------Agent操作----------------------
+            if orderServer.AagenLogin():
+                orderServer.AgentSearch()#发起查询
+                orderServer.AgentDirectOrder()#设置为代理人占座
+                flightHtml = orderServer.FlightSelected()#提交选择航班
+                passHtml = orderServer.Passenger(flightHtml) #提交乘机人信息
+                unitMapHtml = orderServer.AddOns(passHtml) #提交租车信息
+                payHtml = orderServer.UnitMap(unitMapHtml) #选座
+                PNR = orderServer.Payment(payHtml)#进行支付并且获取PNR码
+                print("-------哈哈,得到结果啦PNR:"+PNR)
+                if len(PNR) == 6:
+                    orderPnr = PNR
+                else:
+                    orderStatus = '2' #生单失败
+        except:
+            print('-----生单失败')
+            orderStatus = '2' #生单出错
+        cl = call()
+        cl.BallbackOrder(orderServer.oinfo.cid, orderStatus, orderPnr, '代理人占座', 'CNTRIPTOPK_ADMIN')
+        print('-------------------end time(s)-------------------')
+        end = time.clock()
+        print ("read: %f s" % (end - start))
+if __name__ == '__main__':
+    #创建一个应用对象
+    app = tornado.web.Application([(r'/akOrder',AirasiaWeb),(r'/akAgOrder',AirasiaAgentWeb)])
+    #绑定一个监听端口
+    app.listen(8888)
+    #启动web程序,开始监听端口的连接
+    tornado.ioloop.IOLoop.current().start()

+ 0 - 24
src/webserver/IndexHandler.py

@@ -1,24 +0,0 @@
-#-*- coding:utf-8 -*-
-import tornado.web
-import tornado.ioloop
-import json
-
-#定义处理类型
-class IndexHandler(tornado.web.RequestHandler):
-    #添加一个处理get请求方式的方法
-    def get(self):
-        #向响应中,添加数据
-        self.write('好看的皮囊千篇一律,有趣的灵魂万里挑一。')
-
-    def post(self):
-        param = self.request.body.decode('utf-8')
-        prarm = json.loads(param)
-        print(param)
-        self.write('Ok')
-if __name__ == '__main__':
-    #创建一个应用对象
-    app = tornado.web.Application([(r'/',IndexHandler)])
-    #绑定一个监听端口
-    app.listen(8888)
-    #启动web程序,开始监听端口的连接
-    tornado.ioloop.IOLoop.current().start()

+ 4 - 0
src/webserver/__init__.py

@@ -0,0 +1,4 @@
+dtime = '2018-03-13'
+print(dtime[0:4])
+print(dtime[-2:])
+print(dtime[5:7])