def getOrderDetail(config, orderNo): helper.getLog('访问getOrderDetail!!!', 'responseOutCode.HQ2.log') url = config['url'] + '?op=OrderFinish' headers = hawkAuth(url) data = {} data['otaCode'] = config['account'] data['otaOrderNO'] = orderNo data['platformSend'] = 0 parameters = {} parameters['type'] = '00' parameters['parkCode'] = config['parkCode'] data['parameters'] = json.dumps(parameters).replace(' ', '') sign_str = config['account'] + config['privateKey'] + orderNo + '0' + data[ 'parameters'] data['sign'] = base64.encodestring(helper.md5( sign_str.strip()).upper()).strip() postData = '''<?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> <otaOrderNO>%s</otaOrderNO> <platformSend>%s</platformSend> <parameters>%s</parameters> <signature>%s</signature> </OrderFinish> </soap:Body> </soap:Envelope> ''' % (config['account'], orderNo, 0, data['parameters'], data['sign']) res = helper.httpPost(url, postData, headers) resBody = json.loads( helper.subStr(res, '<OrderFinishResult>', '</OrderFinishResult>')) return resBody
def getPayPassword(config): # 会话秘钥 sIV = "hellocxp" # 通信的key sha256key = config['privateKey'] + helper.md5(config['password']).upper() KEY = hashlib.sha256(sha256key.encode('utf8')) KEY = KEY.digest() KEY = KEY[0:24] # # KEY = str(KEY2) # 密钥 IV = sIV # 偏转向量 desObj = pyDes.triple_des(KEY, ECB, IV, pad=None, padmode=PAD_PKCS5) # 使用DES对称加密算法的CBC模式加密 str = desObj.encrypt(helper.md5(config['payPassword']).upper(), padmode=PAD_PKCS5) return base64.b64encode(str)
def buildParam(data, key, method): data = base64.b64encode(data).replace("\n", '') # print data;exit() sign = helper.md5(key + data).upper(); param = "method=" + method + "&requestParam=" + json.dumps({ "data" : data, "signed" : sign, "securityType" : "MD5", }).replace(' ', '') return param
def processOuterHQ2(config, ticketBought, data, processCount): # helper.getLog('访问processOuterHQ2!!!', 'responseOutCode.HQ2.log') dbObj = db.db() orderInfo = {} orderInfo['merchantCode'] = config['account'] #获取环企票务的编码 orderInfo['postOrder'] = json.dumps(data).replace(' ', '') tempOrder = config['account'] + config['privateKey'] + orderInfo[ 'postOrder'] orderInfo['signature'] = base64.encodestring( helper.md5(tempOrder.strip()).upper()).strip() try: # 发起同步 response = sendDataToOuterHQ2(config, orderInfo) # # 防止同时发起请求造成唯一ID插入错误 # 成功同步 if '00' == response['ResultCode']: # 获取订单详细信息 orderNo = ticketBought['order_detail_id'] orderDetail = getOrderDetail(config, str(orderNo)) # 获取订单信息成功 if orderDetail['ResultCode'] == '00': result = json.loads(orderDetail['ResultJson'].replace( '[', '').replace(']', '')) for item in result: if 'ECode' == item: qrcodeData = result[item] break qrcodeImgUrl = 'http://pwx.weijingtong.net/index.php/Api/Qrcode/?data=' + qrcodeData # 替换二维码 、订单号 、门票编码 sql = "update t_ticket_bought set out_app_code = 'HQ2', temp_receiving_code = '%s', receiving_code = '%s', dimen_code_path='%s', remark2='%s' where id = %d" % ( ticketBought['receiving_code'], qrcodeData, qrcodeImgUrl, qrcodeData, ticketBought['id']) try: re = dbObj.update(sql) if not True == re: helper.getLog( sql, 'addTicketToOuterHQ2.UpdateTicketboughtlistErr.log' ) else: re = "%s \npostdata:%s" % (response, orderInfo) except Exception, e: re = "%s " % e # 获取订单信息不成功 else: re = "%s \n %s \n postdata:%s" % ('获取订单详情失败,订单已占用', orderDetail, orderInfo) else:
def hawkAuth(url, config, methond='post'): urlInfo = urlparse.urlparse(url) hawkId = config['user'] key = config['privateKey'] hawkAuthKey = key + helper.md5(config['password']).upper() ts = str(time.time())[0:10] credential = {} credential['user'] = hawkId credential['algorithm'] = 'sha256' # 验证方式 credential['authKey'] = hawkAuthKey # 密码 nonce = uuid.uuid1() nonce = str(nonce)[0:32] mac = calculateMac(methond, url, '', ts, nonce, credential, "header") auth = 'Hawk id="%s", ts="%s", nonce="%s", mac="%s"' % (hawkId, ts, nonce, mac) headers = { 'Host': str(urlInfo.netloc), 'Content-Type': "application/json", 'Authorization': auth } if (methond == 'post'): headers['POST'] = str(urlInfo.path) return headers
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)
import time import requests from mohawk import Sender, Receiver from util import helper url = "http://121.41.6.55:8601/api/OrderAndPay/WithPrepayment" payload = "{\r\n \"orderinfo\": {\r\n \"orderdetails\": [\r\n {\r\n \"productid\": \"sample string 1\",\r\n \"amount\": 2,\r\n \"identificationnumber\": \"sample string 3\",\r\n \"fullname\": \"sample string 4\",\r\n \"identificationtype\": \"sample string 5\",\r\n \"mobile\": \"sample string 6\",\r\n \"gateinmode\": \"sample string 7\",\r\n \"seatitems\": [\r\n {\r\n \"seatid\": \"sample string 1\"\r\n },\r\n {\r\n \"seatid\": \"sample string 1\"\r\n }\r\n ]\r\n },\r\n {\r\n \"productid\": \"sample string 1\",\r\n \"amount\": 2,\r\n \"identificationnumber\": \"sample string 3\",\r\n \"fullname\": \"sample string 4\",\r\n \"identificationtype\": \"sample string 5\",\r\n \"mobile\": \"sample string 6\",\r\n \"gateinmode\": \"sample string 7\",\r\n \"seatitems\": [\r\n {\r\n \"seatid\": \"sample string 1\"\r\n },\r\n {\r\n \"seatid\": \"sample string 1\"\r\n }\r\n ]\r\n }\r\n ],\r\n \"mobile\": \"sample string 1\",\r\n \"otheruserid\": 2,\r\n \"identificationnumber\": \"sample string 3\",\r\n \"effectdate\": \"sample string 4\",\r\n \"needinvoice\": \"sample string 5\",\r\n \"invoicetitle\": \"sample string 6\",\r\n \"invoicecode\": \"sample string 7\",\r\n \"senderid\": \"sample string 8\",\r\n \"servicecode\": \"sample string 9\",\r\n \"timespanindex\": 10,\r\n \"tripbillcode\": \"sample string 11\",\r\n \"guidernumber\": \"sample string 12\",\r\n \"marketareaid\": \"sample string 13\"\r\n },\r\n \"payinfo\": {\r\n \"orderid\": \"sample string 1\",\r\n \"paypassword\": \"sample string 2\"\r\n }\r\n}" hawkId = 'ybxkj' key = '2b4747b3-788b-46ba-9ca4-c5d112a7c066' hawkAuthKey = key + helper.md5('123456').upper() ts = str(time.time())[0:10] method = 'POST' content_type = 'application/json' credential = {} credential['user'] = hawkId credential['algorithm'] = 'sha256' credential['authKey'] = hawkAuthKey sender = Sender({'id': credential['user'], 'key': credential['authKey'], 'algorithm': credential['algorithm']}, url, method, content_type=content_type, always_hash_content=False )
def UPPER_MD5(value): return helper.md5(value).upper()