示例#1
0
def initBasic():
    global adownerDic, webownerScaleDic, whitelist, lock, webownerMsgCountDic
    log.info('init basic start')

    adownerList = db.query(
        'SELECT pid, gateway, servicefee, ownerfee, servicecode, ordercode, orderdest from lem_adowner_code where status = 1')
    lock.acquire()
    adownerDic.clear
    for adowner in adownerList:
        adownerDic[adowner.servicecode] = adowner
    lock.release()

    webownerScaleList = db.query('SELECT pid, wid, offbase, offno from lem_webowner_scale where status = 1')
    lock.acquire()
    webownerScaleDic.clear
    for webownerScale in webownerScaleList:
        webownerScaleDic["%s-%s" % (webownerScale.pid, webownerScale.wid)] = webownerScale
    lock.release()

    webownerServiceInfoList = db.query('SELECT wid, channel, serviceurl from lem_webowner_serviceinfo where status = 1')
    lock.acquire()
    webownerServiceInfoDic.clear
    for webownerServiceInfo in webownerServiceInfoList:
        webownerServiceInfoDic["%s-%s" % (webownerServiceInfo.wid, webownerServiceInfo.channel)] = webownerServiceInfo
    lock.release()

    msgCountList = db.query('select wid,msg_count from lem_webowner')
    lock.acquire()
    webownerMsgCountDic.clear()
    for msgCount in msgCountList:
        webownerMsgCountDic[msgCount.wid] = msgCount.msg_count
    webownerMsgCountDic[1000] = 0
    lock.release()
示例#2
0
def forwardToWebowner(wid, channel, serviceOrderId, mobile, orderdest, ordercode, fee):
    try:
        serviceurl = getWebownerServiceUrl(wid, channel)

        if serviceurl:
            serviceurl = '%s?linkid=%s&mobile=%s&orderdest=%s&cmdid=%s&fee=%s' % (
                serviceurl, serviceOrderId, mobile, orderdest, ordercode, fee)
            webRequestQueue.put(serviceurl)
            log.info('forwardToWebowner:[%s]' % (serviceurl))
    except:
        log.error("forwardTo1036 request error:%s" % lang.trace_back())
示例#3
0
    def post(self):
        servicecode = "ivr-lbxz1002"
        content = self.request.body
        try:
            remote_ip = self.request.remote_ip
            if remote_ip != '221.174.25.62' and remote_ip != '221.174.25.59' and remote_ip != '127.0.0.1':
                log.info("[%s], errorip:[%s], query:[%s]" % (servicecode, remote_ip, content))
                self.write('')
                return

            ssock = StringIO.StringIO(content)
            xmldoc = minidom.parse(ssock)
            ssock.close()
            callNum = xmldoc.getElementsByTagName('callNum')[0].firstChild.data
            calledNum = xmldoc.getElementsByTagName('calledNum')[0].firstChild.data
            #serviceId = xmldoc.getElementsByTagName('serviceId')[0].firstChild.data
            #fee = xmldoc.getElementsByTagName('fee')[0].firstChild.data
            #tradeId = xmldoc.getElementsByTagName('tradeId')[0].firstChild.data
            tradeId = lang.uuid()
            startTime = xmldoc.getElementsByTagName('startTime')[0].firstChild.data
            starttime = datetime.datetime.strptime(startTime, '%Y%m%d%H%M%S')
            endTime = xmldoc.getElementsByTagName('endTime')[0].firstChild.data
            endtime = datetime.datetime.strptime(endTime, '%Y%m%d%H%M%S')
            #md5str = xmldoc.getElementsByTagName('md5')[0].firstChild.data
            #siteType = xmldoc.getElementsByTagName('siteType')[0].firstChild.data
            #serviceKey = '3ecdad1d-40e0-4a5e-bc85-e35b649ef9a7'
            #verify = hashlib.md5('%s%s%s' % (callNum, endTime, serviceKey)).hexdigest()

            msg = dict(
                serviceOrderId=tradeId,
                servicecode=servicecode,
                status=1,
                statusstring='',
                mobile=callNum,
                orderdest=calledNum,
                starttime=starttime,
                endtime=endtime,
                ivrtotal=30,
                ivrunit=60,
            )
            orderlog.info("receive:[%s],[%s],[%s],[%s],ok" % (tradeId, servicecode, self.request.uri, content))
            unionapi.serviceProcess(msg)
        except:
            orderlog.error("receive:[%s],[%s],[%s],err" % (servicecode, content, lang.trace_back()))
        finally:
            self.finish('<?xml version = "1.0" encoding="utf-8"?><spserviceresp><status>ok</status></spserviceresp>')
示例#4
0
def doProvinceCheck(province, wid, mobile, serviceOrderId, feeFlag):
    s1 = "select ifnull(msg_count,0) from webowner_province where province2='%s' and wid=%s" % (province, wid)
    msgCount = db.getint(s1)
    if msgCount == 0:
        log.info("province province=%s is 0 .jump it .wid=%s mobile=%s serviceOrderId=%s" % (
            province, wid, mobile, serviceOrderId))
        sql2 = "update webowner_province set today_count=today_count+1 where wid=%s and province2='%s'" % (
            wid, province)
        db.execute(sql2)
        sql = "update lem_webowner set today_count=today_count+1 where wid=%s" % (wid,)
        db.execute(sql)
        return feeFlag;
    else:
        s2 = "select today_count from webowner_province where province2='%s' and wid=%s " % (province, wid)
        todayCount = db.getint(s2)
        if (todayCount >= msgCount):
            log.info(
                "province check fail. province=%s is msgCount=%s today=%s .reject it .wid=%s mobile=%s serviceOrderId=%s" % (
                    province, msgCount, todayCount, wid, mobile, serviceOrderId))
            return 0;
        sql2 = "update webowner_province set today_count=today_count+1 where wid=%s and province2='%s'" % (
            wid, province)
        db.execute(sql2)
        sql = "update lem_webowner set today_count=today_count+1 where wid=%s" % (wid,)
        db.execute(sql)
        log.info(
            "province add province=%s and wid=%s today_count=%s msg_count=%s mobile=%s serviceOrderId=%s" % (
                province, wid, todayCount + 1, msgCount, mobile, serviceOrderId))
        return feeFlag
示例#5
0
    def get(self):
        servicecode = "ivr-lbxz1002-1"
        try:
            remote_ip = self.request.remote_ip
            if remote_ip != '221.174.25.62' and remote_ip != '221.174.25.59' and remote_ip != '127.0.0.1':
                log.info("[%s], errorip:[%s], query:[%s]" % (servicecode, remote_ip, self.request.query))
                self.write('')
                return

            mobile = self.get_argument("ivrsrcnum", None)
            orderdest = self.get_argument("ivrdesnum", None)
            starttime = self.get_argument("stime", None)
            starttime = datetime.datetime.strptime(starttime, '%Y%m%d%H%M%S')
            ivrtotal = self.get_argument("feetime", None)
            ivrtotal = lang.num(ivrtotal)
            endtime = starttime + datetime.timedelta(minutes=ivrtotal)
            endtime = endtime.strftime('%Y-%m-%d %H:%M:%S')
            starttime = starttime.strftime('%Y-%m-%d %H:%M:%S')
            serviceOrderId = lang.uuid()

            msg = dict(
                serviceOrderId=serviceOrderId,
                servicecode=servicecode,
                status=1,
                statusstring='',
                mobile=mobile,
                orderdest=orderdest,
                starttime=starttime,
                endtime=endtime,
                ivrtotal=ivrtotal,
                ivrunit=60,
            )

            orderlog.info("receive:[%s],[%s],[%s],[%s],ok" % (serviceOrderId, servicecode, self.request.query))
            #unionapi.serviceProcess(msg)
        except:
            orderlog.error("receive:[%s],[%s],[%s],err" % (servicecode, self.request.query, lang.trace_back()))
        finally:
            self.finish('OK')
示例#6
0
 def get(self):
     sql = "update lem_webowner set today_count=0";
     db.execute(sql);
     sql = "update webowner_province set today_count=0";
     db.execute(sql);
     log.info(" clear data ok.")
示例#7
0
def serviceProcess(msg):
    try:
        pid = 10
        wid = 1000
        channel = ""
        adid = "1000"

        servicecode = msg.get('servicecode')
        mobile = msg.get('mobile')
        feeFlag = 1
        adownerCode = getAdownerCode(servicecode)
        if adownerCode is None:
            log.info("feecenter servicecode is null: " + servicecode + ". adownerDic = " + str(adownerDic))
            adownerCode = dict()

        pid = adownerCode.get("pid")
        gateway = adownerCode.get("gateway")
        ordercode = adownerCode.get('ordercode')
        orderdest = adownerCode.get('orderdest')
        serviceOrderId = msg["serviceOrderId"]
        serviceSubTime = lang.now()
        if pid == 10:
            orderdest = msg.get('orderdest')
            webowner = db.get("select i.wid, i.channel,a.adownerid from lem_ivr_info i,lem_adowner_code a where a.servicecode=i.servicecode and i.orderdest = %s", orderdest)
            if webowner:
                wid = webowner.wid
                channel = webowner.channel
                adid = webowner.adownerid
        elif pid == 11:
            webowner = db.get("select i.wid, i.channel,a.adownerid from lem_ivr_info i,lem_adowner_code a where a.servicecode=i.servicecode and i.orderdest = %s", orderdest + ordercode)
            if webowner:
                wid = webowner.wid
                channel = webowner.channel
                adid = webowner.adownerid
        else:
            order = None
            try:
                order = db.get(
                    "select * from Lez_sms_orderlog where mobile = ? and servicecode = ? order by subtime desc limit 1",
                    mobile, servicecode)
                if order:
                    orderid = order.get('id')
                    db.execute("update sms_order_log set flag = 1 where flag = 0 and id='" + orderid + "'")
            except:
                log.error("feecenter id error:%s" % lang.trace_back())

            if order:
                wid = order.get('wid')
                channel = order.get('channel')
                adid = order.get('adid')

        if not isWhiteMobile(mobile) and isWebNeedDeduct(pid, wid):
            feeFlag = 0

        servicefee = adownerCode.get("servicefee")
        ownerfee = adownerCode.get("ownerfee")
        totalincome = 0
        feeincome = 0

        if pid == 10:
            starttime = msg.get('starttime')
            endtime = msg.get('endtime')
            ivrtotal = msg.get('ivrtotal')
            records = int(math.ceil(float(ivrtotal) / msg.get('ivrunit', 180)))
            totalincome = records * servicefee
            feeincome = records * ownerfee
            sql = "insert lez_ivr_detail(id,wid,channel,mobile,servicecode,orderdest,starttime,endtime,total,totalincome, feeincome, feeflag, subtime) values('%s',%s,'%s','%s','%s','%s','%s','%s',%s,%s,%s,%s,'%s')" % (
                serviceOrderId, wid, channel, mobile, servicecode, orderdest, starttime, endtime, ivrtotal, totalincome,
                feeincome, feeFlag, serviceSubTime)

            db.execute(sql)

        if pid == 11:
            totalincome = servicefee
            feeincome = ownerfee

        # check the msg_count == today_count
        province = ''
        webownerMsgCount = webownerMsgCountDic[wid]
        if webownerMsgCount != 0:
            log.info(
                "webowner msg_count=%s.do check. wid=%s, servicecode=%s mobile=%s serviceOrderId=%s" % (
                    webownerMsgCount, wid, servicecode, mobile, serviceOrderId))
            sql = "select today_count from lem_webowner where wid='%s'" % (wid,);
            today_count = db.getint(sql);
            if today_count >= webownerMsgCount:
                log.info(
                    "webowner msg_count fail.reject it. %s 's msg_count=%s, today_count=%s mobile=%s serviceOrderId=%s" % (
                        wid, webownerMsgCount, today_count, mobile, serviceOrderId))
                feeFlag = 0
            else:
                province = getProvince(mobile)
                feeFlag = doProvinceCheck(province, wid, mobile, serviceOrderId, feeFlag)
        else:
            # log.info("msg_count=0. jump. wid=%s servicecode=%s feeFlag=%s" % (wid, servicecode, feeFlag))
            log.info(
                "webowner msg_count=0. do check province.wid=%s servicecode=%s mobile=%s serviceOrderId=%s" % (
                    wid, servicecode, mobile, serviceOrderId))
            province = getProvince(mobile)
            feeFlag = doProvinceCheck(province, wid, mobile, serviceOrderId, feeFlag)

        log.info("wid=%s mobile=%s province=%s feeFlag=%s serviceOrderId=%s" % (
        wid, mobile, province, feeFlag, serviceOrderId))
        sql = "insert into lez_service_log(id,wid,channel,servicecode,pid,mobile,adid,totalincome,feeincome,status,statusstring,feeflag,gateway,subtime,ordercode,orderdest) values('%s',%s,'%s','%s',%s,'%s','%s',%s,%s,'%s','%s',%s,%s,'%s','%s','%s')" % (
            serviceOrderId, wid, channel, servicecode, pid, mobile, adid, totalincome, feeincome, msg.get('status'),
            msg.get('statusstring'), feeFlag, gateway, serviceSubTime, ordercode, orderdest)
        db.execute(sql)

        if feeFlag == 1:
            forwardToWebowner(wid, lang.num(channel), serviceOrderId, mobile, orderdest, ordercode, feeincome)
    except:
        log.error("serviceprocess error:%s" % lang.trace_back())
示例#8
0
def getProvince(mobile):
    sql = "select ifnull(province,'未知') as province from api_haoduan where mobile=%s" % mobile[:7]
    province = db.getone(sql).province;
    log.info("mobile=%s province=%s " % (mobile, province.decode('utf-8')))
    return province
示例#9
0
    msgCountList = db.query('select wid,msg_count from lem_webowner')
    lock.acquire()
    webownerMsgCountDic.clear()
    for msgCount in msgCountList:
        webownerMsgCountDic[msgCount.wid] = msgCount.msg_count
    webownerMsgCountDic[1000] = 0
    lock.release()


whitelist = db.get('SELECT brief from lem_news where id = 162')
if whitelist:
    whitelist = whitelist.brief
else:
    whitelist = ''

log.info('init basic end')


def getAdownerCode(servicecode):
    return adownerDic.get(servicecode)


def getWebownerServiceUrl(wid, channel):
    serviceinfo = webownerServiceInfoDic.get('%s-%s' % (wid, channel))
    if serviceinfo:
        return serviceinfo.get('serviceurl')
    else:
        return None


def getWebownerScale(pid, wid):