def isWebNeedDeduct(pid, wid): wid = int(wid) if wid == 1000 or wid == 1001: return True global statMap flag = False key = '%s-%s' % (pid, wid) try: offBase = 5 offNo = 2 webownerScale = getWebownerScale(pid, wid) if webownerScale is None: webownerScale = getWebownerScale(pid, 1000) if webownerScale: offBase = webownerScale.get("offbase") offNo = webownerScale.get("offno") total = statMap.get(key) total = total + 1 if total else 1 statMap[key] = total if (total % offBase + offNo) >= offBase: flag = True except: log.error("deduct error:%s" % lang.trace_back()) return flag
def run(self): while True: try: url = self.queue.get() headers = {'User-Agent': 'form lemon'} r = requests.get(url, headers=headers, timeout=15) orderlog.info('%s: forwardurl:[%s],[%s]' % (self.getName(), url, r.status_code)) except: log.error("forwardTo request error:%s" % lang.trace_back())
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())
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>')
def get(self): status = 1 try: remote_ip = self.request.remote_ip # if remote_ip != '211.151.66.84' and remote_ip != '127.0.0.1': # log.info("[%s], errorip:[%s], query:[%s]" % ('ivr-zyhl1001-2,5', remote_ip, self.request.query)) # self.write('') # return linkid = self.get_argument("linkid", None) cmdid = self.get_argument("content", None) mobile = self.get_argument("mobile", None) status = self.get_argument("state", None) starttime = lang.now() endtime = starttime if cmdid == 'DMM1': servicecode = "smsdb-hnjl001" elif cmdid == 'DMT1': servicecode = "smsdb-hnjl002" elif cmdid == 'DMM6': servicecode = "smsdb-hnjl003" elif cmdid == 'DMM7': servicecode = "smsdb-hnjl004" elif cmdid == 'DMM9': servicecode = "smsdb-hnjl005" elif cmdid == 'HYT4': servicecode = "smsdb-hnjl-2-1" elif cmdid == 'DMT3': servicecode = "smsdb-hnjl006" elif cmdid == 'HYT3': servicecode = "smsdb-hnjl-2-2" elif cmdid == 'HYT1': servicecode = "smsdb-hnjl-2-3" else: orderlog.info("receive:[%s],[%s],[%s],[%s],[%s],error" % ( linkid, 0, servicecode, self.request.uri, self.request.query)) return status = 1 if status == 'DELIVRD' else 0 if status != 1: orderlog.info("receive:[%s],[%s],[%s],[%s],[%s],error" % ( linkid, 0, servicecode, self.request.uri, self.request.query)) return serviceOrderId = lang.uuid() msg = dict( serviceOrderId=serviceOrderId, servicecode=servicecode, status=status, statusstring='', mobile=mobile, starttime=starttime, endtime=endtime, ivrtotal=1, ) orderlog.info("receive:[%s],[%s],[%s],[%s],[%s],ok" % ( linkid, serviceOrderId, servicecode, self.request.uri, self.request.query)) unionapi.serviceProcess(msg) except: orderlog.error("receive:[%s],[%s],err: %s" % (self.request.uri, self.request.query, lang.trace_back())) self.finish("0") finally: self.finish('ok')
def get(self): status = 1 try: remote_ip = self.request.remote_ip # if remote_ip != '211.151.66.84' and remote_ip != '127.0.0.1': # log.info("[%s], errorip:[%s], query:[%s]" % ('ivr-zyhl1001-2,5', remote_ip, self.request.query)) # self.write('') # return linkid = self.get_argument("linkid", None) cmdid = self.get_argument("cmdid", None) mobile = self.get_argument("mobileid", None) status = self.get_argument("state", None) starttime = lang.now() endtime = starttime if cmdid == 'HYT': servicecode = "smsdb-zyhl1001-2-1" elif cmdid == 'HYT2': servicecode = "smsdb-zyhl1001-2" elif cmdid == 'DMT2': servicecode = "smsdb-zyhl1001-5" elif cmdid == 'DMT4': servicecode = "smsdb-zyhl1001-5-2" elif cmdid == 'DMT5': servicecode = "smsdb-zyhl1001-5-3" elif cmdid == 'DMT6': servicecode = "smsdb-zyhl1001-5-4" elif cmdid == 'DMM4': servicecode = "smsdb-zyhl1001-5-5" elif cmdid == 'DMM3': servicecode = "smsdb-zyhl1001-5-6" elif cmdid == 'HYM3': servicecode = "smsdb-zyhl1001-2-2" elif cmdid == 'HYM4': servicecode = "smsdb-zyhl1001-2-3" elif cmdid == 'HYM5': servicecode = "smsdb-zyhl1001-2-4" elif cmdid == 'DMD1': servicecode = "smsdb-zyhl1001-5-7" elif cmdid == 'DMD2': servicecode = "smsdb-zyhl1001-5-8" elif cmdid == 'HYM9': servicecode = "smsdb-zyhl1001-2-5" elif cmdid == 'DMD3': servicecode = "smsdb-zyhl1001-5-9" elif cmdid == 'DMD4': servicecode = "smsdb-zyhl1001-5-10" elif cmdid == 'DMD5': servicecode = "smsdb-zyhl1001-5-11" elif cmdid == 'DMD6': servicecode = "smsdb-zyhl1001-5-12" elif cmdid == 'DMD7': servicecode = "smsdb-zyhl1001-5-13" elif cmdid == 'HYG1': servicecode = "smsdb-zyhl1001-2-6" elif cmdid == 'HYG2': servicecode = "smsdb-zyhl1001-2-7" elif cmdid == 'DMG1': servicecode = "smsdb-zyhl1001-5-14" elif cmdid == 'DMG2': servicecode = "smsdb-zyhl1001-5-15" elif cmdid == 'DMG3': servicecode = "smsdb-zyhl1001-5-16" elif cmdid == 'DMG4': servicecode = "smsdb-zyhl1001-5-17" elif cmdid == 'DMG5': servicecode = "smsdb-zyhl1001-5-18" elif cmdid == 'DMG6': servicecode = "smsdb-zyhl1001-5-19" elif cmdid == 'DMG7': servicecode = "smsdb-zyhl1001-5-20" elif cmdid == 'DMG8': servicecode = "smsdb-zyhl1001-5-21" elif cmdid == 'DMG9': servicecode = "smsdb-zyhl1001-5-22" elif cmdid == 'DMA1': servicecode = "smsdb-zyhl1001-5-23" elif cmdid == 'DMA2': servicecode = "smsdb-zyhl1001-5-24" elif cmdid == 'DMA3': servicecode = "smsdb-zyhl1001-5-25" else: orderlog.info("receive:[%s],[%s],[%s],[%s],[%s],error" % ( linkid, 0, servicecode, self.request.uri, self.request.query)) return status = 1 if status == 'DELIVRD' else 0 if status != 1: orderlog.info("receive:[%s],[%s],[%s],[%s],[%s],error" % ( linkid, 0, servicecode, self.request.uri, self.request.query)) return serviceOrderId = lang.uuid() msg = dict( serviceOrderId=serviceOrderId, servicecode=servicecode, status=status, statusstring='', mobile=mobile, starttime=starttime, endtime=endtime, ivrtotal=1, ) orderlog.info("receive:[%s],[%s],[%s],[%s],[%s],ok" % ( linkid, serviceOrderId, servicecode, self.request.uri, self.request.query)) unionapi.serviceProcess(msg) except: orderlog.error("receive:[%s],[%s],err: %s" % (self.request.uri, self.request.query, lang.trace_back())) finally: self.finish('1')
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())
def get(self): servicecode = "ivr-hnxl1003" try: report = self.get_argument("report", None) if (report != 'DELIVRD'): return mobile = self.get_argument("mobile", None) orderdest = self.get_argument("spnum", None) momsg = self.get_argument("msg", None) if len(momsg) > 5: momsg = momsg[5:] else: momsg = '0' orderdest = orderdest + momsg ivrtotal = 30 endtime = datetime.datetime.now() endtime = endtime.strftime('%Y-%m-%d %H:%M:%S') starttime = datetime.datetime.now() 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=9999, ) orderlog.info( "receive:[%s],[%s],[%s],[%s],ok" % (serviceOrderId, servicecode, orderdest, 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')
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')
def get(self): servicecode = "ivr-lbxz1002-2" try: remote_ip = self.request.remote_ip mobile = self.get_argument("mobile", None) orderdest = self.get_argument("spnumber", None) ivrtotal = self.get_argument("validtime", None) linkid = self.get_argument("linkid", None); ivrtotal = lang.num(ivrtotal) endtime = "1" starttime = "1" serviceOrderId = linkid 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],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')