def processOuterKZZN2(config, mallBought, data, processCount): dbObj = db.db() try: # 发起同步 url = config['url'] #http://123.11.226.80:8118/service.asmx url = helper.subStr(url, 'http://', '/service') host = helper.subStr(url, '', ':') port = int(helper.subStr(url, ':', '')) responseBody, re = sendDataToOuterKZZN2(host, port, data) reBody = helper.subStr(responseBody, '<nStatus>', '</nStatus>') # print responseBody # print re #成功同步 if '1' == reBody: cQrCode = helper.subStr(responseBody, '<cQrCode>', '</cQrCode>') cUrl = 'http://' + host + ':' + str(port) + helper.subStr( responseBody, '<cUrl>', '</cUrl>') cStatus = helper.subStr(responseBody, '<cStatus>', '</cStatus>') sql = "update t_mall_bought set out_app_code = 'KZZN2', out_app_no = '%s', dimen_code_path='%s', remark2='%s' where id = '%d'" % ( cQrCode, cUrl, cStatus, mallBought['id']) # sql = "update t_mall_bought set out_app_code = '_WJT', out_app_no = '%s' where id = '%d'" % (mallBought['receiving_code'], mallBought['id']) # sql = "update t_ticket_bought set out_app_code = 'KZZN2', temp_receiving_code = '%s', receiving_code = '%s', dimen_code_path='%s', remark2='%s' where id = %d" % (mallBought['receiving_code'], cQrCode, cUrl, cStatus, mallBought['id']) # print sql # print mallBought if not True == dbObj.update(sql): helper.getLog('update t_mall_bought error:' + sql, 'mall.kzzn2.log') # 发送消息 textMessage = '微景通验证码:' + mallBought[ 'receiving_code'] + ' \n票务验证码:' + cQrCode + ' \n购票张数:' + str( mallBought['buy_count']) + ' \n购票时间:' + str( mallBought['create_time']) time = int(helper.thisTime()) re = re + "\nsendMessageToUser:"******"%s \nPostData:%s" % (re, data) # print 'processCount:' + str(processCount) if processCount < 2: processCount += 1 processOuterKZZN2(config, mallBought, data, processCount) return else: re = "%s \nprocessCount:%s" % (re, str(processCount)) except Exception, e: re = str(Exception) + ":" + str(e) re = "%s \nPostData:%s" % (re, data)
def addTicketToOuterDK(config, ticketBought): # global dbObj # dbObj = globalVar.getDbObj() dbObj = db.db() #查询游客信息 # userInfo = '' userInfo = dbObj.select( "select user_id, name, mobile, id_number from t_user_identity_info where id = %d" % ticketBought['identity_info_id']) # userInfo = [] # userInfo.append({ # 'name': '微景通', # 'mobile' : '18523876001' # }) if userInfo == False or len(userInfo) < 1: visitorName = 'weijingtongVisitor' visitorMobile = '18523876001' else: userInfo = userInfo[0] visitorMobile = userInfo['mobile'] ## visitorName = userInfo['user_id'] visitorName = userInfo['name'] visitorName = repr(visitorName.decode('UTF-8'))[2:-1] ## visitorName = '\u5f20\u8001\u5927' ## visitorName = urllib.urlencode({1:visitorName})[2:] # visitorName = 'wjtVisitor' ticketName = dbObj.getValue( "select name from t_ticket where id = %d" % ticketBought['ticket_id'], 'name') # ticketName = '成人票' ticketName = repr(ticketName.decode('UTF-8'))[2:-1][0:48] # ticketName = 'test' Order = {} Order['OrderNO'] = str(ticketBought['order_detail_id']) Order['LinkName'] = visitorName Order['LinkPhone'] = visitorMobile Order['LinkICNO'] = userInfo['id_number'] Order['TotalAmount'] = str( round(ticketBought['price'] * ticketBought['count'], 2)) Order['CreateTime'] = str(ticketBought['create_time']) Visitor = {} Visitor['VisitorName'] = visitorName Visitor['VisitorPhone'] = visitorMobile Visitor['VisitorICNO'] = userInfo['id_number'] Details = {} Details['OrderNO'] = ticketBought['order_detail_id'] Details['ItemID'] = ticketBought['order_detail_id'] Details['ProductCode'] = config['ProductCode_' + str(ticketBought['ticket_id'])] Details['ProductID'] = config['ProductID_' + str(ticketBought['ticket_id'])] Details['ProductPackID'] = config['ProductPackID_' + str(ticketBought['ticket_id'])] Details['ProductMarketPrice'] = str(round(ticketBought['list_price'], 2)) Details['ProductPrice'] = str(round(ticketBought['price'], 2)) Details['ProductSellPrice'] = str(round(ticketBought['price'], 2)) Details['ProductCount'] = ticketBought['count'] Details['ProductSDate'] = str(ticketBought['plan_time'])[0:10] Details['ProductEDate'] = str(ticketBought['plan_time'])[0:10] Details['Visitor'] = json.dumps(Visitor) postOrder = {} postOrder['Ptime'] = helper.now() postOrder['parkCode'] = config['parkCode'] postOrder['timestamp'] = helper.now() postOrder['Order'] = json.dumps(Order) postOrder['Details'] = json.dumps([Details]) # print postOrder # print json.dumps(postOrder) postOrder = json.dumps(postOrder) # exit() sign = base64.encodestring( helper.md5(config['merchantCode'] + config['privateKey'] + postOrder + str(int(helper.thisTime()))).upper()).strip() # sign = '1' # print sign;exit() data = '''<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <OrderOccupies xmlns="http://tempuri.org/"> <merchantCode>%s</merchantCode> <postOrder>%s</postOrder> <signature>%s</signature> </OrderOccupies> </soap:Body> </soap:Envelope>''' % (config['merchantCode'], postOrder, sign) # print data; # exit(); try: # 发起同步 ''' responseBody = helper.httpPost(config['url'] + '/OrderOccupies', data, {'Content-Type' : 'application/x-www-form-urlencoded'}) ''' url = config['url'] #http://123.11.226.80:8118/service.asmx # url = 'http://112.74.131.57:10006/service.asmx' host = helper.subStr(url, 'http:/', 'service') host = helper.subStr(host, '/', ':') port = helper.subStr(url, '://', 'service') port = helper.subStr(port, ':', '/') # print host;exit() #占用定单 res = helper.webservice(host, int(port), "/service.asmx", data, "http://tempuri.org/OrderOccupies", 0) responseBody = res[0] re = res[1] reBody = json.loads( helper.subStr(responseBody, '<OrderOccupiesResult>', '</OrderOccupiesResult>')) # print reBody #成功同步 if '00' == reBody['ResultCode']: #支付定单 parameters = {} parameters['otaOrderNO'] = str(ticketBought['order_detail_id']) parameters['parkCode'] = config['parkCode'] parameters['timestamp'] = helper.now() parameters = json.dumps(parameters) sign = base64.encodestring( helper.md5(config['merchantCode'] + config['privateKey'] + parameters + str(int(helper.thisTime()))).upper()).strip() data2 = '''<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <OrderFinish xmlns="http://tempuri.org/"> <otaCode>%s</otaCode> <parameters>%s</parameters> <signature>%s</signature> </OrderFinish> </soap:Body> </soap:Envelope>''' % (config['merchantCode'], parameters, sign) res = helper.webservice(host, int(port), "/service.asmx", data2, "http://tempuri.org/OrderFinish", True) responseBody2 = res[0] re2 = res[1] reBody = json.loads( helper.subStr(responseBody2, '<OrderFinishResult>', '</OrderFinishResult>')) # print reBody if '00' == reBody['ResultCode']: re = re + "\n\n" + re2 #生成二维码 resultJson = json.loads(reBody['ResultJson'])[0] qrcodeImg = 'http://pwx.weijingtong.net/index.php/Api/Qrcode/?data=' + resultJson[ 'ECode'] sql = "update t_ticket_bought set out_app_code = 'DK', temp_receiving_code = '%s', receiving_code='%s', dimen_code_path = '%s' where id = %d" % ( ticketBought['receiving_code'], resultJson['ECode'], qrcodeImg, ticketBought['id']) # print sql if not True == dbObj.update(sql): helper.getLog( sql, 'addTicketToOuterDK.UpdateTicketboughtlistErr.log') else: re = "%s\nPostData1:%s\n\n%s\nPostData2:%s" % (re, data, re2, data2) pass else: re = "%s \nPostData:%s" % (re, data) pass except Exception, e: re = str(Exception) + ":" + str(e) re = "%s \nPostData:%s" % (re, data)
def addTicketToOuterJKB(config, ticketBought): # global dbObj # dbObj = globalVar.getDbObj() dbObj = db.db() #查询游客信息 # userInfo = '' userInfo = dbObj.select( "select user_id, name, mobile, id_number from t_user_identity_info where id = %d" % ticketBought['identity_info_id']) # userInfo = [] # userInfo.append({ # 'name': '微景通', # 'mobile' : '18523876001' # }) if userInfo == False or len(userInfo) < 1: visitorName = 'weijingtongVisitor' visitorMobile = '18523876001' else: userInfo = userInfo[0] visitorMobile = userInfo['mobile'] ## visitorName = userInfo['user_id'] visitorName = userInfo['name'] visitorName = urllib.quote(visitorName.encode('utf-8')) # visitorName = repr(visitorName.decode('UTF-8'))[2:-1] ## visitorName = '\u5f20\u8001\u5927' ## visitorName = urllib.urlencode({1:visitorName})[2:] # visitorName = 'wjtVisitor' ticketName = dbObj.getValue( "select name from t_ticket where id = %d" % ticketBought['ticket_id'], 'name') ticketName = urllib.quote(ticketName.encode('utf-8')) # ticketName = '成人票' # ticketName = repr(ticketName.decode('UTF-8'))[2:-1][0:48] # ticketName = 'test' visitPerson = {} visitPerson['visitName'] = visitorName visitPerson['visitMobile'] = visitorMobile visitPerson['credentials'] = userInfo['id_number'] visitPerson['credentialsType'] = 'Idcard' body = {} body['productName'] = ticketName body['contactMobile'] = visitorMobile body['contactName'] = visitorName body['orderPrice'] = str(round(ticketBought['price'], 2)) body['orderQuantity'] = ticketBought['count'] body['orderRemark'] = 'weijingtong' body['outOrderId'] = ticketBought['order_detail_id'] body['resourceId'] = config['resourceId_' + str(ticketBought['ticket_id'])] body['sellPrice'] = str(round(ticketBought['list_price'], 2)) body['useDate'] = str(ticketBought['plan_time'])[0:10] body['visitPerson'] = [visitPerson] data = {} data['body'] = body data['appKey'] = config['AppKey'] data = json.dumps(data, ensure_ascii=False) # data = json.dumps(data) # print data # exit() # time = str(helper.thisTime())[0:10] + str(int(str(helper.thisTime())[12:])*100) time = str(int(round(helper.thisTime() * 1000))) # time = '1' print config['AppKey'] + data + time + config['SecretKey'] sign = helper.md5(config['AppKey'] + data + time + config['SecretKey']).upper().strip() # sign = '1' httpHeader = { 'Content-Type': 'application/json;charset=utf-8', 'APPKEY': config['AppKey'], 'TIMESTAMP': time, 'SIGN': sign, } # print httpHeader; print sign # exit() try: # 发起同步 re = helper.httpPost(config['url'] + '?method=createOrder', data, httpHeader) reBody = json.loads(re) # print reBody ;exit() #成功同步 if 200 == reBody['rspCode']: #支付定单 body = {} body['orderId'] = outOrderId = reBody['body']['orderId'] body['paymentSerialno'] = ticketBought['id'] data2 = {} data2['body'] = body data2['appKey'] = config['AppKey'] data2 = json.dumps(data2) # print data2;exit() sign = helper.md5(config['AppKey'] + data2 + time + config['SecretKey']).upper().strip() httpHeader = { 'Content-Type': 'application/json;charset=utf-8', 'APPKEY': config['AppKey'], 'TIMESTAMP': time, 'SIGN': sign, } re2 = helper.httpPost(config['url'] + '?method=payOrder', data2, httpHeader) reBody = json.loads(re2) print reBody if 200 == reBody['rspCode']: re = re + "\n\n" + re2 print re #生成二维码 qrcodeImg = reBody['body']['qrcodeUrl'] sql = "update t_ticket_bought set out_app_code = 'JKB', temp_receiving_code = '%s', receiving_code='%s', dimen_code_path = '%s', remark2 = '%s' where id = %d" % ( ticketBought['receiving_code'], reBody['body']['eticket'], qrcodeImg, '{"outOrderId":"' + outOrderId + '"}', ticketBought['id']) print sql if not True == dbObj.update(sql): helper.getLog( sql, 'addTicketToOuterJKB.UpdateTicketboughtlistErr.log') else: re = "%s\nPostData1:%s\n\n%s\nPostData2:%s" % (re, data, re2, data2) print re pass else: re = "%s \nPostData:%s\nPostHead:%s" % (re, data, json.dumps(httpHeader)) pass except Exception, e: re = str(Exception) + ":" + str(e) re = "%s \nPostData:%s" % (re, data)
def runService(): t1 = helper.thisTime() re = urllib2.urlopen('http://192.168.1.119/testhtml/test/test.php').read() t2 = helper.thisTime() re = re + ' -- ' + str(t1) + ' -- ' + str(t2) + ' -- ' + str( t2 - t1 ) helper.getLog(re)
def addMallToOuterXiRuan(config, productConfig, mallBought): # print config;print productConfig;print mallBought;exit() # conf = ConfigParser.ConfigParser() # conf.read("%s/config/config.ini" % sys.path[0]) # print "%s/config/config.ini" % sys.path[0] url = helper.confGet( 'host', 'commonService') + 'OuterApp/XiRuan/login/?clientId=' + str( mallBought['client_id']) print url helper.getLog(url) session = json.loads(helper.httpGet(url)) if not session['status']: helper.getLog(session['data']) return # print session;exit() #查询游客信息 # userInfo = '' # dbObj = globalVar.getDbObj() dbObj = db.db() userInfo = dbObj.select( "select user_id, name, mobile, id_number from t_user_identity_info where id = %d" % mallBought['identity_info_id']) if userInfo == False or len(userInfo) < 1: visitorName = 'weijingtongVisitor' visitorMobile = '18523876001' else: userInfo = userInfo[0] visitorMobile = userInfo['mobile'] visitorName = userInfo['user_id'] visitorName = userInfo['name'] # visitorName = 'visitor' visitorName = repr(visitorName.decode('UTF-8'))[2:-1] # visitorName = '\u5f20\u8001\u5927' ## visitorName = urllib.urlencode({1:visitorName})[2:] #使用日期 useDate = mallBought['remark2'].split(',') data = '''{ "sign":"3E365195E5A5CFA2ABC5F5B302182F73", "ts":%s, "session":"%s", "hotelid":"%s", "appkey":"%s", "loc":"zh_CN", "method":"xmsopen.reservation.xopsavereservation", "ver":"1.0.0", "params":[ { "rmtype":"%s", "holdname":"%s", "rmnum":"%s", "hotelid":"%s", "contact_name":"%s", "arr":"%s", "mobile":"%s", "ratecode":"%s", "sex":"", "rate":"%s", "contact_mobile":"%s", "name":"%s", "dep":"%s", "gstno":"%s", "ref":"weixin", "channel":"weixin", "restype":"%s" } ], "cmmcode":"%s" }''' % (str(helper.thisTime()).replace( '.', ''), session['data'], config['hotelid'], config['appkey'], productConfig['rmtype'], visitorName, mallBought['buy_count'], productConfig['hotelid'], visitorName, useDate[0], visitorMobile, productConfig['ratecode'], mallBought['price'], visitorMobile, visitorName, useDate[1], mallBought['buy_count'], productConfig['restype'], config['cmmcode']) # print data re = re2 = '' try: if mallBought['remark']: outappCodes = mallBought['remark'].split(',') rsvno = outappCodes[0] accnt = outappCodes[1] res = {} res['success'] = True else: re = helper.httpPost(config['host'], data) # print re #成功同步 res = json.loads(re) if res['success'] == True: rsvno = res['results'][0]['rsvno'] accnt = res['results'][0]['accnt'] sql = "update t_mall_bought set remark = '%s,%s' where id = '%d'" % ( rsvno, accnt, mallBought['id']) if not True == dbObj.update(sql): helper.getLog( sql, 'addMallToOuterXiRuan.UpdateMallboughtlistErr.log') # print res if res['success'] == True: data2 = '''{ "sign":"3E365195E5A5CFA2ABC5F5B302182F73", "ts":%s, "session":"%s", "hotelid":"%s", "appkey":"%s", "loc":"zh_CN", "method":"xmsopen.accounts.xopdopaymentaccount", "ver":"1.0.0", "params":[ { "pay_money":"%s", "pay_code":"%s", "payno":"%s", "remark":"%s", "hotelid":"%s", "rsvno":"%s", "accnt":"%s" } ], "cmmcode":"%s" }''' % (str(helper.thisTime()).replace( '.', ''), session['data'], config['hotelid'], config['appkey'], mallBought['total_pay_price'], '9034', mallBought['order_detail_id'], 'weixin order', productConfig['hotelid'], rsvno, accnt, config['cmmcode']) # print data2 try: re2 = helper.httpPost(config['host'], data2) # print re2 #成功同步 res = json.loads(re2) if res['success'] == True: sql = "update t_mall_bought set out_app_code = 'XiRuan', out_app_no = '%s' where id = '%d'" % ( rsvno, mallBought['id']) if not True == dbObj.update(sql): helper.getLog( sql, 'addMallToOuterXiRuan.UpdateMallboughtlistErr.log') #失败后,也更新一下bought,不再重复 else: sql = "update t_mall_bought set out_app_code = 'XiRuan' where id = '%d'" % mallBought[ 'id'] if not True == dbObj.update(sql): helper.getLog( sql, 'addMallToOuterXiRuan.UpdateMallboughtlistErr.log') re2 = "resmsg2:%s \npostdata2:%s" % (re2, data2) except Exception, e: re2 = str(Exception) + ":" + str(e) re2 = "errmsg2:%s \npostdata2:%s" % (re2, data2) pass #失败后,也更新一下bought,不再重复 else: