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("MO_Msg", None) mobile = self.get_argument("statphone", None) status = self.get_argument("stat", None) starttime = lang.now() endtime = starttime if cmdid == '02042': servicecode = "smsdb-gzyh1001-1" 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())