|
@@ -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()
|