예제 #1
0
def runService(clientConfig, mallProductConfig, mallBoughts, code, configType):
    # for mallBought in mallBoughts:
    # if mallBought['client_id'] == 1257:
    # print clientConfig , code, mallBoughts,'==============================='

    #python
    if configType == 2:
        eval('Service' + code + '.MallService' + code)(clientConfig,
                                                       mallProductConfig,
                                                       mallBoughts)
    #java
    elif configType == 1:
        for mallBought in mallBoughts:
            requestData = {
                'type': 'mall',
                'key': '3e3bcd9d71d52132a9b413a57be173ca',
                'orderId': str(mallBought['order_id'])
            }
            # print urllib.urlencode(requestData);
            url = helper.confGet('host', 'nwxService') + 'api/order'
            reChar = helper.httpPost(url, requestData)
            res = json.loads(reChar)
            if res['isok']:
                #返回的验证码,如果下单失败,则为空
                if not res['codes']:
                    # print requestData
                    helper.getLog('重新下单失败 -- ' + url + ' -- ' + reChar +
                                  ' -- ' + urllib.urlencode(requestData))
                else:
                    helper.getLog('重新下单成功 -- ' + url + ' -- ' + reChar +
                                  ' -- ' + urllib.urlencode(requestData))
            else:
                helper.getLog('重新下单失败 -- ' + url + ' -- ' + reChar + ' -- ' +
                              urllib.urlencode(requestData))
    elif configType == 3:
        eval('Service' + code + '.MallService' + code)(clientConfig,
                                                       mallProductConfig,
                                                       mallBoughts)

    pass
예제 #2
0
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:
예제 #3
0
def addTicketToOuterKZZN(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'
    orderInfo = [
        {'cid': config['cid']},
        {'ccipher': config['ccipher']},
        {'cOrder': ticketBought['order_detail_id']},
        {'nHuman': ticketBought['count']},
        {'cName': visitorName[0:24]},
        {'cPhone': visitorMobile},
        {'nTicketType': config['nTicketType_' + str(ticketBought['ticket_id'])]},
        {'cTicketType': ticketName},
        {'dDateIn': str(ticketBought['plan_time'])[0:10]},
        {'cQrID': ticketBought['receiving_code']},
        {'nCustType': 1},
        {'cip': socket.gethostbyname(socket.gethostname())},
        {'fMoney': ticketBought['price']},
        {'cPayType': 'weixin'},
    ]
    data = helper.dict2xml('OnPreSellOrder', orderInfo, 'xmlns="http://localhost/WebSell/"')
    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>%s</soap:Body></soap:Envelope>' % data

    # print data;
    # exit();

    try:
        # 发起同步
        url = config['url']   #http://123.11.226.80:8118/service.asmx
        host = helper.subStr(url, 'http:/', 'service')
        host = helper.subStr(host, '/', ':')
        # print host
        webservice = httplib.HTTPConnection(host, 8118, timeout = 50)
        # webservice.set_debuglevel(1)

        # print response.getheaders() #获取头信息
        #连接到服务器后的第一个调用。它发送由request字符串到到服务器
        webservice.putrequest("POST", "/service.asmx")
        # webservice.putheader("Accept-Encoding", "text")
        # webservice.putheader("Host", "123.11.226.80")
        webservice.putheader("User-Agent", "WeijingtongService-python")
        webservice.putheader("Content-Type", "text/xml; charset=utf-8")
        # webservice.putheader("Connection", "Keep-Alive")
        webservice.putheader("Content-Length", "%d" % len(data))
        webservice.putheader("SOAPAction", '"http://localhost/WebSell/OnPreSellOrder"')
        # webservice.putheader("SOAPAction", '"http://tempuri.org/OnPreSellOrder"')
        # webservice.putheader("SOAPAction", '"http://123.11.226.80/OnPreSellOrder"')
        #发送空行到服务器,指示header的结束
        webservice.endheaders()
        #发送报文数据到服务器
        webservice.send(data)
        #获取返回HTTP 响应信息
        response = webservice.getresponse()
        responseBody = response.read()
        # print 'response:'
        # print response.read()
        # exit()
        res = []
        res.append('ReHttpStatus:' + str( response.status ))
        res.append('ReHttpReason:' + response.reason)
        res.append('ReHttpBody:' + responseBody)
        head = []
        for header in response.getheaders():
            head.append('%s: %s' % ( header[0], header[1] ))

        head = "\n".join(head)
        res.append('ReHttpHeader:' + head) #获取头信息
        # print res
        # exit()
        re = "\n".join(res)
        # re = re.decode('gb2312').encode('utf-8')

        webservice.close() #关闭链接

        reBody = helper.subStr(responseBody, '<OnPreSellOrderResult>', '</OnPreSellOrderResult>')
        # print reBody
        #成功同步
        if '1' == reBody:
            #生成二维码
            reMakeQrcode = helper.httpGet( helper.confGet('host', 'commonService') + 'Api/TicketQrcode/saveFile/?clientId=' + str( ticketBought['client_id'] ) + '&receivingCode=' + ticketBought['receiving_code'] )
            reMakeQrcodeMap = json.loads(reMakeQrcode)
            # print reMakeQrcodeMap['code']
            if reMakeQrcodeMap['code'] == 0:
                sql = "update t_ticket_bought set out_app_code = 'KZZN', temp_receiving_code = '%s', dimen_code_path = '%s' where id = %d" %  (ticketBought['receiving_code'], reMakeQrcodeMap['filePath'], ticketBought['id'])
                # print sql
                if not True == dbObj.update(sql):
                    helper.getLog(sql, 'addTicketToOuterKZZN.UpdateTicketboughtlistErr.log')
        else:
            re = "%s \nPostData:%s" % (re, data)
            pass
    except Exception, e:
        re = str(Exception) + ":" + str(e)
        re = "%s \nPostData:%s" %(re, data)
예제 #4
0
def serviceInit(types):
    # print types;

    #启动服务
    serviceUrl = helper.confGet('host',
                                'commonService') + 'Order/Index/reBuyDo'
    now = helper.now(-3600 * 2, '%Y-%m-%d %H:00:00')
    orderId = 0
    paybackId = 0
    ids = {}
    # print now;
    test = 0
    while True:
        ts = []  #线程列表
        #连接数据库
        # global dbObj
        dbObj = db.db()

        # 不用每次循环都查询配置
        if not now == helper.now(-3600 * 1, '%Y-%m-%d %H:00:00'):
            if test == 1:
                now = helper.now(-3600 * 20,
                                 '%Y-%m-%d %H:00:00')  #改变这个时间,重启,则重新开始扫描
            else:
                now = helper.now(-3600 * 1,
                                 '%Y-%m-%d %H:00:00')  #改变这个时间,重启,则重新开始扫描

            # print now;

            orderId = dbObj.getValue(
                'SELECT id FROM t_order WHERE create_time > "%s" ORDER BY id '
                % (now), 'id')
            if orderId == None:
                orderId = dbObj.getValue(
                    'SELECT id FROM t_order WHERE 1=1 ORDER BY id DESC limit 0, 1',
                    'id')
                if orderId == None:
                    orderId = 0

            paybackId = dbObj.getValue(
                'SELECT id FROM t_payback WHERE create_time > "%s" ORDER BY id '
                % (now), 'id')
            if paybackId == None:
                paybackId = dbObj.getValue(
                    'SELECT id FROM t_payback WHERE 1=1 ORDER BY id DESC limit 0, 1',
                    'id')
                if paybackId == None:
                    paybackId = 0

            # print orderId; print paybackId;
            helper.getLog('orderId:%d -- paybackId: %d' % (orderId, paybackId),
                          'serviceCheckPay.log')

            for type in types:
                ids[type] = dbObj.getValue(
                    "SELECT id FROM %s WHERE create_time > '%s' ORDER BY id " %
                    (types[type], now), 'id')
                if ids[type] == None:
                    ids[type] = dbObj.getValue(
                        "SELECT id FROM %s WHERE 1 =1 ORDER BY id DESC limit 0, 1"
                        % (types[type]), 'id')
                    if ids[type] == None:
                        ids[type] = 0
            # print ids;

        for type in types:
            # print str(type) + '/' + types[type]
            status = '1'
            if test == 1:
                status = '1, 9'
            sql = ' '.join([
                "SELECT id AS orderId, pay_status, type, client_id AS clientId, create_time FROM t_order WHERE id > %d AND type = %d AND status in (%s) AND pay_time BETWEEN '%s' AND '%s' "
                % (orderId, type, status, now, helper.now(-5)),
                "AND id IN ( SELECT order_id FROM t_payback WHERE id > %d AND order_id NOT IN ( SELECT order_id FROM %s WHERE id >= %d ) ) "
                % (paybackId, types[type], ids[type]),
                "ORDER BY id DESC LIMIT 0, 10"
            ])
            # print sql
            t = threading.Thread(target=findOrders,
                                 args=(
                                     serviceUrl,
                                     sql,
                                     type,
                                 ))
            t.start()
            ts.append(t)
        for t in ts:
            t.join()

        time.sleep(10)

        scanner.dump_all_objects('/logs/python/mem.log')