def user_info(self, params): module = "account" method = "user_account" user_account = {} with get_rpc_conn(module) as proxy: try: user_account = proxy.call(method, params) except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_USER_ACCOUNT_FAIL) user_account = ujson.loads(user_account) module = "user" method = "user_info" user_info = {} with get_rpc_conn(module) as proxy: try: user_info = proxy.call(method, params) user_info = ujson.loads(user_info) except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_USER_INFO_FAIL) ret = {} ret.update(user_account) ret.update(user_info) return ret
def user_password_modify(self, mobile, code, checksum, oldpassword, newpassword): if checksum != hashlib.md5( str(mobile) + str(code) + define.DEFIND_SMS_SALT).hexdigest(): raise ews.EwsError(ews.STATUS_USER_MOBILE_VERIFY_ERROR) if oldpassword == newpassword: raise ews.EwsError(ews.STATUS_USER_PASSWORD_MODIFY_SAMEPWD) params = { "mobile": mobile, "oldpassword": hashlib.md5(oldpassword + define.DEFIND_LOGIN_SALT).hexdigest(), "newpassword": hashlib.md5(newpassword + define.DEFIND_LOGIN_SALT).hexdigest() } module = "user" method = "password_modify" with get_rpc_conn(module) as proxy: status = 0 try: status = proxy.call(method, params) except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_USER_PASSWORD_MODIFY_FAIL) if status < 1: raise ews.EwsError(ews.STATUS_USER_LOGIN_PASSWORD_ERROR) return status raise ews.EwsError(ews.STATUS_USER_PASSWORD_MODIFY_FAIL)
def get_by_ck(ck, ss_err=True): """通过ck获取session信息 @param ck: 通过登录得到的ck串 @return: session内容,dict类型 """ mc = db_pool.get_redis('session') try: uid = mc.get(MC_PREFIX_UID + str(ck)) if uid: # 校验当前用户是否在其他设备多点登录 uid_ck = mc.get(MC_PREFIX_CK + str(uid)) if ck != uid_ck: logger.debug('uid=%s^^^^^^ck=%s^^^^^uid_ck=%s', uid, ck, uid_ck) mc.delete(MC_PREFIX_UID + str(ck)) raise ews.EwsError(ews.STATUS_MULTI_LOGIN_ERR) # 刷新ck有效期并返回 set_ck_to_redis(ck, uid, refresh=True) return { 'ck': ck, 'uid': uid, 'usertype': mc.get(MC_UT_PREFIX + str(ck)), } if ss_err: logger.debug(detailtrace("DetailTrace:{}".format(ck))) raise ews.EwsError(ews.STATUS_SESSION_ERR) else: return None finally: pass
def check_ggtype(self, ggtype): try: ggtypes = ggtype.split(',') for ggtype in ggtypes: if int(ggtype) < 1 or int(ggtype) > 58: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '未知的过关类型') except: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '未知的过关类型')
def _check_number_region(self, balls): logger.debug(balls) for ball in balls: ball = ball.split(',') if len(ball) < 1 or len(ball) > 11: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '十一选五号码个数错误') for b in ball: if int(b) > 11 or int(b) < 1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '十一选五数字范围错误')
def check_split_tickets(self, params): try: #调用拆票服务 with get_rpc_conn("ticket") as proxy: try: params.update({'checksplit':True}) tickets = proxy.call("split_tickets", params) except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '投注金额错误') except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '投注金额错误')
def get_user_info_by_mobile(self, mobile): module = "user" method = "user_info_by_mobile" params = {"mobile": mobile} user_info = {} with get_rpc_conn(module) as proxy: try: user_info = proxy.call(method, params) except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_USER_INFO_FAIL) return user_info raise ews.EwsError(ews.STATUS_USER_INFO_FAIL)
def del_ck_from_redis(ck): """从redis删除ck """ if not ck: raise ews.EwsError(ews.STATUS_SESSION_ERR) uid_key = MC_PREFIX_UID + str(ck) mc = db_pool.get_redis('session') try: mc.delete(uid_key) except: raise ews.EwsError(ews.STATUS_SESSION_ERR) finally: pass
def _split_code_ds(self, code): redball, blueball = code.split('|') redball = redball.split(',') blueball = blueball.split(',') if len(redball) != 5: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透红球个数错误') if len(blueball) != 2: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透蓝球个数错误') for ball in redball: if int(ball) > 35 or int(ball) < 1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透红球数字范围错误') for ball in blueball: if int(ball) > 12 or int(ball) < 1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透蓝球数字范围错误')
def get_cardbind_list(uid): url = "https://queryapi.lianlianpay.com/bankcardbindlist.htm" params = { 'oid_partner': partner_num_web, 'user_id': uid, 'sign_type': 'RSA', 'offset': '0' } content = to_content(params, {}) h = HASH.new(content) sgn = esun_signer.sign(h) sign = base64.b64encode(sgn) params["sign"] = sign params = ujson.dumps(params) headers = {'content-type': 'application/json'} logger.info(content) r = requests.post(url, data=params, headers=headers) if r.status_code == 200: resp = ujson.loads(r.content) logger.info("get_cardbind_list %s", resp) ret_code = resp.get("ret_code") if ret_code == "0000": bank_list = resp.get("agreement_list") return bank_list elif ret_code in ["3007", "8901"]: return [] raise ews.EwsError(ews.STATUS_RECHARGE_SEARCH_FAIL)
def trade(handler, *args, **kwargs): ck = handler.json_args.get("ck", "") uid = session.get_by_ck(ck).get('uid') params = handler.json_args params.update({"uid": uid}) pid = None try: # 账户检查 paymoney = UserBean().check_account(params) # 下单 with get_rpc_conn("trade") as proxy: try: resp = proxy.call("place_order", params) except RpcException as ex: raise ews.EwsError(ews.STATUS_RPC_TRADE_ERROR, ex.message) except: logger.error(traceback.format_exc()) raise account = UserBean().user_account({"uid": uid}) ret = { "pid": resp.get("pid"), "balance": Decimal(account.get("balance")) - Decimal(paymoney), "balance_draw": account.get("balance_draw") } return handler.ok(ret)
def place_order(self, params): module = "account" method = "recharge_order" oid = None with get_rpc_conn(module) as proxy: try: oid = proxy.call(method, params) except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_USER_ACCOUNT_FAIL) if not oid: raise paychannel = params.get("paychannel") params.update({"oid": oid}) if paychannel == "1001": path = build_unifiedorder(params) return {"url": path} elif paychannel == "1002": ret = self.order_lianlian_web(params) return ret elif paychannel in ["1003", "1004"]: ret = self.order_lianlian_web(params) return ret elif paychannel == "1004": ret = self.order_lianlian_sdk(params) return ret return
def get(url, timeout=8, params=None, return_codeing="utf8"): ''' 注意,如果返回的报文内容较大, 请勿使用, 因为日志打印了resp @params: timeout 超时时间 @params: params 请求参数 ''' try: t1 = time.time() cc = curl.Curl() cc.set_timeout(timeout) resp = cc.get(str(url), params) if return_codeing != "utf8": resp = resp.decode(return_codeing) if not params: params = {} t2 = time.time() Log.logger.info( "curlHttpRequest|url=%s|timeout=%s|params=%s|resp=%s|spendtime=%f", url, timeout, urllib.urlencode(params), resp[:200], (t2 - t1)) return resp except: Log.logger.error("curl tcm api interface error %s |params %s", url, params) Log.logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_REQUEST_TIMEOUT) finally: cc.close()
def _split_code_zhi(self, code, wtype): balls = code.split('|') balls = [ball for ball in balls if ball != '-'] if len(balls) != int(wtype) - 243: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '直选玩法和号码位数不匹配') self._check_number_region(balls) self._check_number_repeat(balls)
def _split_code_fs(self, code): redball, blueball = code.split('|') redball = redball.split(',') blueball = blueball.split(',') if len(redball) < 5 or len(blueball) < 2: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透选号不满足复式格式') if len(redball) == 5 and len(blueball) == 2: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透选号不满足复式格式') for ball in redball: if int(ball) > 35 or int(ball) < 1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透红球数字范围错误') for ball in blueball: if int(ball) > 12 or int(ball) < 1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透蓝球数字范围错误')
def set_ck_to_redis(ck, uid, ttl=7 * 24 * 60 * 60, refresh=False): """设置memcached值 """ if not ck or not uid: raise ews.EwsError(ews.STATUS_SESSION_ERR) uid_key = MC_PREFIX_UID + str(ck) ck_key = MC_PREFIX_CK + str(uid) logger.debug('uid=%s^^^^^^ck=%s^^^^^uid_key=%s^^^^^^^^ck_key=%s', uid, ck, uid_key, ck_key) mc = db_pool.get_redis('session') try: mc.setex(uid_key, uid, ttl) mc.setex(ck_key, ck, ttl) except: raise ews.EwsError(ews.STATUS_SESSION_ERR) finally: pass
def check_fileorcode(self, fileorcode, wtype): try: if int(wtype) != 256: if fileorcode.find('#') != -1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '单一玩法投注格式不能包含玩法类型') else: if fileorcode.find('#') == -1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '混投玩法投注格式必须包含玩法类型') if int(wtype) in [244, 245, 246]: fileorcode = fileorcode.split('$') for code in fileorcode: self._split_code_zhi(code, wtype) elif int(wtype) in [247, 248]: fileorcode = fileorcode.split('$') for code in fileorcode: self._split_code_zu(code, wtype) elif int(wtype) in [249, 250, 251, 252, 253, 254, 255]: fileorcode = fileorcode.split('$') for code in fileorcode: self._split_code_ren(code, wtype) elif int(wtype) == 256: fileorcode = fileorcode.split('$') for code in fileorcode: code, wtype = code.split('#') if int(wtype) in [244, 245, 246]: self._split_code_zhi(code, wtype) elif int(wtype) in [247, 248]: self._split_code_zu(code, wtype) elif int(wtype) in [249, 250, 251, 252, 253, 254, 255]: self._split_code_ren(code, wtype) else: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '混投玩法中子玩法类型错误') else: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '未知的玩法类型') except ews.EwsError: raise except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '投注格式解析错误')
def get_ssq_expect_list(self): """双色球 """ try: ssq_expect = self.expect_obj.get_expect_info_list() except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_LOTTERY_ISSUE_ERROR) expects = [expect.get("expect") for expect in ssq_expect] opencodes = self.draw_obj.get_opencode_by_expects(expects) opencodes = {opencode.get("expect"): opencode for opencode in opencodes} ret = {} history_expect = [] flag = False for item in ssq_expect: iscurrent = item.get("isCurrent", "") # opencode = item.get("openCode", "") expect = item.get("expect", "") opencode = opencodes.get(expect, {}) if str(iscurrent) == "1": prizepool = opencode.get("prizePool", "0") prizepool = prizepool.replace(",", "") endtime = item.get("endTime", "") allow_num = int(prizepool) / (5 * 10 ** 7) prizepool = str(round(int(prizepool) / 10.0 ** 8, 2)) + "亿" if opencode else "-" diff = 0 if endtime: diff = int(time.mktime(time.strptime(endtime, '%Y-%m-%d %H:%M:%S')) - time.time()) ret.update({ "status": item.get("status", "0"), "endtime": endtime, "opencode": opencode.get("openCode", ""), "prizepool": prizepool, "iscurrent": iscurrent, "expect": expect, "opentime": opencode.get("openTime", ""), "diff": diff, "allow_num": allow_num }) continue if opencode.get("openCode", "") and opencode.get("openCode", "") != "": if not flag: ret.update({ "firstprize": opencode.get("firstPrize", ""), "firstnum": opencode.get("firstNum", "") }) flag = True history_expect.append({ "opencode": opencode.get("openCode", ""), "expect": expect }) ret.update({ "historical_code": history_expect }) return ret
def check_fileorcode(self, fileorcode, wtype): try: if int(wtype) != 389: if fileorcode.find('#') != -1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '单一玩法投注格式不能包含玩法类型') else: if fileorcode.find('#') == -1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '混投玩法投注格式必须包含玩法类型') if int(wtype) in [1, 98]: fileorcode = fileorcode.split('$') for code in fileorcode: self._split_code_ds(code) elif int(wtype) in [135, 143]: fileorcode = fileorcode.split('$') for code in fileorcode: self._split_code_dt(code) elif int(wtype) in [387, 388]: fileorcode = fileorcode.split('$') for code in fileorcode: self._split_code_fs(code) elif int(wtype) == 389: fileorcode = fileorcode.split('$') for code in fileorcode: code, wtype = code.split('#') if int(wtype) in [1, 98]: self._split_code_ds(code) elif int(wtype) in [135, 143]: self._split_code_dt(code) elif int(wtype) in [387, 388]: self._split_code_fs(code) else: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '混投玩法中子玩法类型错误') else: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '未知的玩法类型') except ews.EwsError: raise except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '投注格式解析错误')
def user_password_reset(self, mobile, code, checksum, password): if checksum != hashlib.md5( str(mobile) + str(code) + define.DEFIND_SMS_SALT).hexdigest(): raise ews.EwsError(ews.STATUS_USER_MOBILE_VERIFY_ERROR) password = hashlib.md5(password + define.DEFIND_LOGIN_SALT).hexdigest() params = {"mobile": mobile, "password": password} module = "user" method = "password_reset" with get_rpc_conn(module) as proxy: status = 0 try: status = proxy.call(method, params) except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_USER_PASSWORD_RESET_FAIL) return status raise ews.EwsError(ews.STATUS_USER_PASSWORD_RESET_FAIL)
def check_account(self, params): with get_rpc_conn("account") as proxy: payinfo = proxy.call("check_account", params) payinfo = ujson.loads(payinfo) paystatus = payinfo.get("paystatus") paymoney = payinfo.get("paymoney") if paystatus != define.ORDER_PAY_STATUS_SUCC: raise ews.EwsError(ews.STATUS_RPC_TRADE_ERROR, define.PAY_STATUS_REMARK[paystatus]) return paymoney
def verifyIdcard(self, idcard, truename): url = "http://aliyunverifyidcard.haoservice.com/idcard/VerifyIdcardv2?cardNo={cardNo}&realName={realName}" url = url.format(cardNo=idcard, realName=truename) header = { 'Authorization': 'APPCODE ' + "dc384ff70f79452dac4b3a7f5b107c5d" } r = requests.get(url, headers=header) logger.info(r.content) if r.status_code != 200: raise ews.EwsError(ews.STATUS_AUTH_TRUENAME_FAIL) resp = ujson.loads(r.content) error_code = resp.get("error_code") result = resp.get("result") isok = resp.get("isok") if error_code == 0: return True raise ews.EwsError(ews.STATUS_AUTH_NOT_MATCHING)
def user_account_detail(self, params): module = "account" method = "user_account_detail" account_detail = {} with get_rpc_conn(module) as proxy: try: account_detail = proxy.call(method, params) except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_USER_ACCOUNT_FAIL) account_detail = ujson.loads(account_detail) details = account_detail.get("details", []) count = account_detail.get("count", 0) user_list = [] #:"f_crtime":1520666344,"f_pid":57,"f_inout":1,"f_money":32.0,"f_id":23,"f_uptime":1520666344,"f_lotid":28,"f_uid":1,"f_balance":9648.0 for detail in details: inout = int(detail.get("f_inout")) if inout == define.ACCOUNT_LOG_TYPE_PAID: continue user_list.append({ "crtime": detail.get("f_crtime"), "pid": detail.get("f_oid"), "inout": detail.get("f_inout"), "money": detail.get("f_money"), "desc": define.ACCOUNT_LOG_DESC.get(inout), "id": detail.get("f_id"), "balance": float(detail.get("f_balance_recharge")) + float(detail.get("f_balance_draw")), "lotid": detail.get("f_lotid") }) ret = {} pageno = params.get("pageno") pagesize = params.get("pagesize") ret.update({ "list": user_list, "count": count, "all_page": (count / int(pagesize)) + 1, "curr_page": pageno }) return ret
def modify_password(self, params): module = "user" method = "modify_password" ret = {} with get_rpc_conn(module) as proxy: try: ret = proxy.call(method, params) except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_USER_ACCOUNT_FAIL) return
def _split_code_dt(self, code): redball, blueball = code.split('|') m = dt_re.match(code) if not m: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透选号不满足胆拖格式') red_d = m.group(1).split(',') if m.group(1) else [] red_t = m.group(2).split(',') if m.group(2) else [] blue_d = m.group(3).split(',') if m.group(3) else [] blue_t = m.group(4).split(',') if m.group(4) else [] if len(red_d + red_t) > len(set(red_d + red_t)): raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透红球胆拖号码有重复') if len(blue_d + blue_t) > len(set(blue_d + blue_t)): raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透蓝球胆拖号码有重复') for ball in red_d + red_t: if int(ball) > 35 or int(ball) < 1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透红球数字范围错误') for ball in blue_d + blue_t: if int(ball) > 12 or int(ball) < 1: raise ews.EwsError(ews.STATUS_LOTTOCHECK_ERROR, '大乐透蓝球数字范围错误')
def user_verify_sms(self, mobile, code): pt = re.compile('^0\d{2,3}\d{ 7,8}$|^1[3456789]\d{9}$|^147\d{8}') phonematch = pt.match(mobile) if not phonematch: raise ews.EwsError(ews.STATUS_USER_MOBILE_FORMAT_ERROR) if not code: raise ews.EwsError(ews.STATUS_USER_MOBILE_CODE_EMPTY) rds = db_pool.get_redis('main') _code = rds.get( rediskey.REDIS_USER_MOBILE_SMS_CODE.format(mobile=mobile)) or "" if not _code: raise ews.EwsError(ews.STATUS_USER_MOBILE_CODE_EXPIRE) if str(_code) != str(code): raise ews.EwsError(ews.STATUS_USER_MOBILE_CODE_ERROR) checksum = hashlib.md5( str(mobile) + str(code) + define.DEFIND_SMS_SALT).hexdigest() return {"checksum": checksum, "code": code, "mobile": mobile}
def __check_auth_idcard(self, idcard, truename): """ 检查身份证是否绑定 :return: """ check_idcard = idcaed_prog.match(idcard) check_char = string.digits + string.letters for char in truename: if char in check_char: raise ews.EwsError(ews.STATUS_AUTH_CHECK_TRUENAME) if not check_idcard: raise ews.EwsError(ews.STATUS_AUTH_CHECK_IDCARD) birthday = idcard[6:14] is_adult = self.check_is_adult( datetime.datetime.strptime(birthday, "%Y%m%d")) if is_adult == "0": raise ews.EwsError(ews.STATUS_NOT_ADULT) elif is_adult == "-1": raise ews.EwsError(ews.STATUS_AUTH_CHECK_IDCARD)
def chasecancel(handler, *args, **kwargs): ck = handler.json_args.get("ck") uid = session.get_by_ck(ck).get('uid') cid = handler.json_args.get("cid") try: with get_rpc_conn("trade") as proxy: try: params = {"uid": uid, "cid": cid} resp = proxy.call("cancel_chasenumber", params) except RpcException as ex: raise ews.EwsError(ews.STATUS_RPC_TRADE_ERROR, ex.message) except: logger.error(traceback.format_exc()) raise return handler.ok(resp)
def get_syxw_expect_list(self): """广西11x5 """ try: current_expect_info = self.expect_obj.get_current_expect_by_time() expect_info = self.draw_obj.get_history_opencode_list() except: logger.error(traceback.format_exc()) raise ews.EwsError(ews.STATUS_LOTTERY_ISSUE_ERROR) ret = {} history_expect = [] try: endtime = current_expect_info.get("stopTime", "") # prizepool = str(round(int(prizepool)/10.0 ** 9, 2)) + "亿" diff = int(time.mktime(time.strptime(endtime, '%Y-%m-%d %H:%M:%S')) - time.time()) except: logger.info(traceback.format_exc()) logger.info(current_expect_info) diff = 0 ret.update({ "status": current_expect_info.get("status", "0"), "iscurrent": "1", "expect": current_expect_info.get("expect", ""), "diff": diff, "opencode": current_expect_info.get("openCode", ""), "expect": current_expect_info.get("expect", ""), "starttime": current_expect_info.get("startTime", ""), "stoptime": current_expect_info.get("stopTime", ""), "opentime": current_expect_info.get("openTime", "") }) for item in expect_info: opencode = item.get("openCode", "") if opencode and opencode != "": history_expect.append({ "opencode": item.get("openCode", ""), "expect": item.get("expect", ""), "starttime": item.get("startTime", ""), "stoptime": item.get("stopTime", ""), "opentime": item.get("openTime", "") }) ret.update({ "historical_code": history_expect }) return ret
def apply_data_token(dt_type): """申请一个data_token """ rds = db_pool.get_redis('main') for i in range(4): dt_key = hashlib.md5(str(random.random())).hexdigest() dt_secret = hashlib.md5(str(random.random())).hexdigest() if rds.setnx(DATA_TOKEN_PREFIX + dt_key, dt_secret) <= 0: continue rds.expire(DATA_TOKEN_PREFIX + dt_key, DATA_TOKEN_TTL) return { 'key': dt_key, 'secret': dt_secret, 'ttl': DATA_TOKEN_TTL, 'type': dt_type, } else: raise ews.EwsError(ews.STATUS_STATUS_BUSY)