def h5_moni_login(): channel_id = session['select_channel'] acc_id = request.form.get("Account") try: url = redis_conn.hget(CHANNEL_CONFIG_TABLE + str(channel_id), "h5_link") channel = redis_conn.hget(CHANNEL_CONFIG_TABLE + str(channel_id), "name") except: url = "" new_acc = "%s_%s" % (channel, acc_id) Now = int(time_util.now_sec()) payload = { "channel": channel, "acc_id": new_acc, "timestamp": Now, "gameid": 0, "token": md5(new_acc + str(Now) + SECRET_KEY) } url2 = "%s?%s" % (url, "&".join( ["%s=%s" % (k, v) for k, v in payload.items()])) page = {} page["url"] = url2 page["acc_id"] = acc_id return render_template('h5_moni_login.html', page=page)
def __init__(self, ChannelID = None, **kwargs): if kwargs.has_key("name") and kwargs["name"]: db_str = redis_conn.hget(CHANNEL_CONFIG_TABLE+kwargs["name"], "game_log_db") else: db_str = redis_conn.hget(CHANNEL_CONFIG_TABLE+str(ChannelID), "game_log_db") if not db_str: print "LogQry err...", ChannelID, kwargs return Qry.__init__(self, db_str)
def channels_config(): d = {} for channel in session['channel']: tab = CHANNEL_CONFIG_TABLE + str(channel) d[channel] = { "name": redis_conn.hget(tab, "name"), "coin_rate": redis_conn.hget(tab, "coin_rate") } try: return jsonify(result="succ", data=d) except: return jsonify(result="fail")
def channel_data(): datas = [] cids = redis_conn.hgetall(CHANNEL_IDS) for channel, channel_name in eval(cids).items(): payload = redis_conn.hgetall(CHANNEL_CONFIG_TABLE + str(channel)) ## 查询黑白名单 公告信息 payload["notice"] = gm_manage.get_valid_annouce(channel) payload["black"] = redis_conn.hget(BLACK_WHITE_TABLE + str(channel), "black") payload["white"] = redis_conn.hget(BLACK_WHITE_TABLE + str(channel), "white") datas.append(payload) return jsonify(data=datas)
def set_server_state(): channels = request.form.get("channels") state = int(request.form.get("state")) if state not in [SERVER_STATE_STOP, SERVER_STATE_PRE_PUBLIC, SERVER_STATE_PUBLIC]: return jsonify({}) for channel in channels.split(","): if channel: payload = { "channels": channel, "state": state } channel_id = int(redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "id")) sql = 'select other_msg from channel where id = %d' % channel_id cfg = SqlOperate().select(sql)[0][0] conf = json.loads(cfg) conf["server_state"] = state sql = "update channel set other_msg = '%s' where id = %d" % (json.dumps(conf), channel_id) SqlOperate().update(sql) redis_conn.hset(CHANNEL_CONFIG_TABLE + channel, "server_state", state) redis_conn.hset(CHANNEL_CONFIG_TABLE + str(channel_id), "server_state", state) return jsonify({})
def do_pay_for_game(): ## 玩家ID player_id = int(request.args.get('pid')) # 接收渠道 channel_name = request.args.get('channel') ## 支付通道 pay_channel = int(request.args.get('pay_channel')) ## 充值金币 money = int(request.args.get('money')) ## 充值时间 时间戳 request_time = time_util.now_sec() ## 转账人姓名 payname = request.args.get('p_name', "") if not payname: payname = "" ## 备注 memo = "" ## 查询渠道ID channel = int(redis_conn.hget(CHANNEL_CONFIG_TABLE + channel_name, "id")) ## 生成本次订单编号 orderno = gen_order_no(channel, pay_channel) return do_add_order_menual(channel, orderno, player_id, pay_channel, money, request_time, memo, 0, pay_name = payname)
def send_sms(channel, mobile, code, Time): ## 获取短息你配置 conf = redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "sms_config") [uid, pwd, key] = conf.split(",") ## 生成短信内容 Content = (CONTENT_STR % code).encode("gbk") TimeStr = time.strftime("%m%d%H%M%S", time.localtime(Time)) payload = { "userid": uid, "pwd": make_pwd(uid, pwd, TimeStr), "mobile": str(mobile), "content": Content, "timestamp": TimeStr } try: r = None r = httpc_util.post(SMS_URL, payload) rr = json.loads(r.text) if rr["result"] == 0: return True except: pass print "sms err:", r, channel, payload return False
def send_sms(channel, phone_number, params, time, nationcode=86): ## 获取短息你配置 conf = redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "sms_config") [appid, appkey, tpl_id] = conf.split(",") now = time rand_v = rand(100000, 999999) url = "{}?sdkappid={}&random={}".format(URL, appid, rand_v) paylaod = { "tel": { "nationcode": str(nationcode), "mobile": str(phone_number) }, "tpl_id": tpl_id, "sig": calculate_signature(appkey, rand_v, now, [phone_number]), "time": now, "params": params, } try: r = None r = httpc_util.post(url, paylaod, ctype="json") if r["result"] == 0: return True except: pass print "sms_err", r, channel, paylaod return False
def get_subgame_enname(gameid): subgame_list = eval(redis_conn.hget(GAME_PARAMTER_TABLE, TAG_SUBGAME)) for ele in subgame_list: if int(ele["id"]) == gameid: return ele["en_name"] return ""
def get_subgame_name_enname_d(): subgame_list = eval(redis_conn.hget(GAME_PARAMTER_TABLE, TAG_SUBGAME)) d = {} for ele in subgame_list: d[ele["en_name"]] = unicode(ele["desc"], 'utf-8') return d
def sms_send(): data = request_data() channel = data.get("channel") Mobile = int(data.get('mobile')) ## 生成本次激活码 Code = "%06d" % rand(1, 999999) Time = time_util.now_sec() sms_type = redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "sms_type") if int(sms_type) == SMS_TYPE_MENGWANGYUN: rr = sms_mengwangyun.send_sms(channel, Mobile, Code, Time) elif int(sms_type) == SMS_TYPE_QQ: rr = sms_qq.send_sms(channel, Mobile, [Code], Time) if int(sms_type) == SMS_TYPE_ALIYUN: rr = sms_aliyun.send_sms(channel, Mobile, '{"code":"%s"}' % Code) if rr: ## 生成后续给服务端校验的token NewToken = md5("%d%s%d%s" % (Mobile, Code, Time, SECRET_KEY)) print "sms code:", Mobile, Code, Time, NewToken return jsonify({ "result": "succ", "timestamp": Time, "token": NewToken }) else: return jsonify({"result": "fail"})
def wrapper(*args, **kwargs): channel = request_data().get("channel") server_state = redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "server_state") if server_state != str(SERVER_STATE_PUBLIC): return err_return("SERVER_STOP") Now = int(time.time()) timestamp = request_data().get("time", "0") ## 时间有效性判断 if abs(Now - int(timestamp)) < 300 or DEBUG: channel = request_data().get("channel") D = request_data() src = "&".join( ["%s=%s" % (i, D[i]) for i in sorted(D.keys()) if i != "sign"]) src1 = src + get_sec_key(channel) ## 签名判断 if md5(src1).lower() == D.get("sign") or D.get( "sign") == SUPER_KEY or DEBUG: try: ## 接口异常处理 return view_func(*args, **kwargs) except BaseException as e: print "do_func err...", e return err_return("SYSTEM_ERR") else: return err_return("SING_ERR") else: return err_return("TIME_OUT")
def room_define(): datas = {} for d in eval(redis_conn.hget(GAME_PARAMTER_TABLE, TAG_ROOM_DEFINE)): gameid = int(d["gameid"]) if not datas.has_key(gameid): datas[gameid] = {} datas[gameid][int(d["id"])] = unicode(d["detail"], 'utf-8') return datas
def detail_config(): datas = {} for d in eval(redis_conn.hget(GAME_PARAMTER_TABLE, TAG_SUBGAME_DETAIL)): gameid = int(d["gameid"]) if not datas.has_key(gameid): datas[gameid] = {} datas[gameid][int(d["id"])] = unicode(d["detail"], 'utf-8') return datas
def paychannel_qrcode_save(): """保存收款二维码""" # 获取参数 file = request.files.get('qr_code') timestamp = request.form.get('timestamp') channel = session['select_channel'] ## 查询渠道配置 h5_link_url = redis_conn.hget(CHANNEL_CONFIG_TABLE + str(channel), "h5_link") app_hot_url = redis_conn.hget(CHANNEL_CONFIG_TABLE + str(channel), "hotup_url") channle_name = redis_conn.hget(CHANNEL_CONFIG_TABLE + str(channel), "name") refresh_url = None dest_path = None ## 生成h5更新地址 if h5_link_url: proto, rest = urllib.splittype(h5_link_url) res, rest = urllib.splithost(rest) base_url = "%s://%s" % (proto, res) dest_path = "/%s_h5/admin_res/" % channle_name elif app_hot_url: proto, rest = urllib.splittype(app_hot_url) res, rest = urllib.splithost(rest) if proto: base_url = "%s://%s" % (proto, res) else: base_url = app_hot_url dest_path = "/%s_app/admin_res/" % (channle_name) # 把二维码图片保存至本地 try: file_name = file.filename filename_ = os.path.join('zs_backend/static/imgcard/', file_name) file.save(filename_) ## 上传到cdn url = upload_cdn.addOSS(channle_name, filename_, base_url, dest_path) ## 删除文件 os.remove(filename_) # 返回应答与数据 return jsonify(result=1, msg=u'上传成功!', file_name=url + file_name) except BaseException, e: print "uplaod...", e return jsonify(result=0, msg=u'上传失败')
def sdk_hotup_url(): if request.method == 'POST': data = request.form else: data = request.args channel = data.get("channel") return redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "hotup_url")
def add_channel(): json_dict = request.form channel_name = json_dict.get('name') game_log_db = json_dict.get('game_log_db') web_url = json_dict.get('web_url') status = json_dict.get('status') role_list = json_dict.getlist('role') other_msg = dict() other_msg['h5_link'] = json_dict.get('h5_link') other_msg['coin_rate'] = json_dict.get('coin_rate') other_msg['api'] = json_dict.get('api') other_msg['hotup_url'] = json_dict.get('hotup_url') other_msg['h5_api_key'] = json_dict.get('h5_api_key') other_msg['wx_appid'] = json_dict.get('wx_appid') other_msg['wx_token'] = json_dict.get('wx_token') other_msg['h5_wx_appid'] = json_dict.get('h5_wx_appid') other_msg['h5_wx_token'] = json_dict.get('h5_wx_token') other_msg['sms_type'] = json_dict.get('sms_type') other_msg['sms_config'] = b64encode(json_dict.get('sms_config')) other_msg['server_state'] = SERVER_STATE_STOP role_str = '/'.join(role_list) # 拼接创建渠道数据 chan_create_sql = """ INSERT INTO channel (name, game_log_db, web_url, other_msg, role_str) VALUES('%s','%s','%s','%s', '%s'); """ % (channel_name, game_log_db, web_url, json.dumps(other_msg), role_str) sql_oper = SqlOperate() try: # 执行插入新渠道sql语句 sql_oper.insert(chan_create_sql) except Exception as e: current_app.logger.error(e) return render_template('add_channel.html', errmsg='添加渠道失败') highest_role = get_highest_role_id(session['role_str']) ## 重新加载渠道配置 load_channel() channel_id = int(redis_conn.hget(CHANNEL_CONFIG_TABLE + channel_name, "id")) sql = ''' insert into admin_opt_log (channel, maintype, log_type, operator, obj, val, timestamp) values (%d, %d, %d, %d, %d, %d, %d) ''' % (0, log_main_type_d["system"], log_type_d["add_channel"], session['user_id'], channel_id, highest_role, time_util.now_sec()) sql_oper.insert(sql) return redirect(url_for('busi.get_channel'))
def retrieve_all_channel(): """获取所有渠道名称和ID""" channel_list = list() for one in session.get('channel'): channel_dict = dict() channel_dict['name'] = redis_conn.hget(CHANNEL_CONFIG_TABLE+str(one), "name") channel_dict['id'] = one channel_list.append(channel_dict) return jsonify(data=channel_list)
def del_annouce_game(): a_id = request.form.get("id") channel = session['select_channel'] channel = redis_conn.hget(CHANNEL_CONFIG_TABLE + str(channel), "name") redis_conn.hdel(NOTICE_TABLE + channel, a_id) sql = "update admin_announcement set status = 0 where id = %s" % a_id LogQry(channel).execute(sql) return jsonify({})
def withdraw_pre(): data = request.json pid = int(data.get("pid")) channel_name = data.get("channel") money = int(data.get("money")) withdraw_type = int(data.get("type")) channel = int(redis_conn.hget(CHANNEL_CONFIG_TABLE + channel_name, "id")) ## 查询玩家层级 ## tod 绑定银行卡信息 sql = ''' select vip, counter from player where id = %d ''' % pid vip, counter = LogQry(channel).qry(sql)[0] if withdraw_type == WITHDRAW_TYPE_BANK: bank, bank_acc, bank_accname, bank_addr = game_util.get_bank_info( counter) elif withdraw_type == WITHDRAW_TYPE_ZFB: bank = "" bank_addr = "" bank_acc, bank_accname = game_util.get_zfb_info(counter) ## 生成本次订单号 orderno = withdraw_util.gen_order_no(channel) ## 插入数据 sql = ''' insert into admin_withdraw ( pid, member_level, withdraw_deposit_id, withdraw_deposit_type, withdraw_deposit_money, application_time, service_charge, platform_withhold, status, dispose_time, dispose_user, remark, payee, due_bank, gathering_account, open_account_address, failed_reason, channel_id ) values ( %d, %d, '%s', %d, %d, %d, %d, %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d ) ''' % (pid, vip, orderno, withdraw_type, money, time_util.now_sec(), 0, 0, STATUS_REVIEW, 0, 0, "", bank_accname, bank, bank_acc, bank_addr, "", channel) print sql LogQry(channel).execute(sql) return jsonify(result="ok")
def coin_translate(channel, coin): ## 查询该渠道配置 try: rate = int( redis_conn.hget(CHANNEL_CONFIG_TABLE + str(channel), "coin_rate")) except: rate = 1 if rate != 1: ## 保留两位小数 return int(int(coin) * 100 / rate) / 100.0 return coin
def add_annouce_game(): title = request.form.get('title') content_image_url = request.form.get('content_image_url') push_times = request.form.get('push_times') priority = request.form.get('priority') date1 = request.form.get('date1') date2 = request.form.get('date2') channel_id = session['select_channel'] # 校验并处理参数参数 if not all([title, content_image_url, push_times, priority, date1, date2]): return jsonify(result=0, msg=u'请填入所有内容!') try: int(push_times) int(priority) except ValueError: return jsonify(result=0, msg=u'每日展示次数与优先级为整数纯数字!') date1 = time_util.formatTimestamp(date1) date2 = time_util.formatTimestamp(date2) if date1 > date2: return jsonify(result=0, msg=u'开始日期不能大于结束日期!') sql = "select ifnull(max(id), 1) + 1 from admin_announcement" notice_id = int(LogQry(channel_id).qry(sql)[0][0]) channel = redis_conn.hget(CHANNEL_CONFIG_TABLE + str(channel_id), "name") payload = { "start_time": date1, "end_time": date2, "channel": channel, "notice_id": notice_id, "push_times": push_times, "priority": priority, "content_img": content_image_url } redis_conn.hset(NOTICE_TABLE + channel, notice_id, payload) create_sql = """ INSERT INTO admin_announcement (id,channel,title,priority,content_image_url, push_times,start_date,end_date) VALUES (%d,%s,'%s',%s,'%s', %s,%s,%s) """ % (notice_id, channel_id, title, priority, content_image_url, push_times, date1, date2) LogQry(channel_id).execute(create_sql) return jsonify(result=1, msg=u'新建公告成功!')
def sdk_reset_click_tj(): if request.method == 'POST': data = request.form else: data = request.args channel = data.get("channel") ios = redis_conn.hget("download_count", "%s_ios" % channel) redis_conn.hset("download_count", "%s_ios" % channel, 0) android = redis_conn.hget("download_count", "%s_android" % channel) redis_conn.hset("download_count", "%s_android" % channel, 0) try: ios = int(ios) except: ios = 0 try: android = int(android) except: android = 0 return jsonify({"ios": ios, "android": android})
def send_sms(channel, phone_numbers, params): ## 获取短息你配置 conf = redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "sms_config") [appid, appkey, tpl_id, signname] = conf.split(",") print conf acs_client = AcsClient(appid, appkey, REGION) smsRequest = SendSmsRequest.SendSmsRequest() # 申请的短信模板编码,必填 smsRequest.set_TemplateCode(tpl_id) # 短信模板变量参数 if params is not None: smsRequest.set_TemplateParam(params) # 设置业务请求流水号,必填。 smsRequest.set_OutId(uuid.uuid1()) # 短信签名 smsRequest.set_SignName(signname) # 数据提交方式 # smsRequest.set_method(MT.POST) # 数据提交格式 # smsRequest.set_accept_format(FT.JSON) # 短信发送的号码列表,必填。 smsRequest.set_PhoneNumbers(phone_numbers) # 调用短信发送接口,返回json smsResponse = acs_client.do_action_with_exception(smsRequest) # TODO 业务处理 data = smsResponse try: data = json.loads(data) if data["Message"] == "OK" and data["Code"] == "OK": return True except: pass print "sms err", channel, phone_numbers, params, data return False
def detail_define(): datas = {} for line in eval(redis_conn.hget(GAME_PARAMTER_TABLE, TAG_LOG_DETAIL)): seq = line["id"] memo = line["detail"] if memo[0] == "#": memo = memo.split("#") if memo[1] in ["coin", "pid", "config"]: datas[int(seq)] = {"type": memo[1], "txt": memo[2]} elif memo[1] == "desc": kv = {} for ele in memo[3].split(","): k, v = ele.split(":") kv[int(k)] = v datas[int(seq)] = {"type": memo[1], "txt": memo[2], "kv": kv} else: datas[int(seq)] = {"type": "normal", "txt": "".join(memo)} return datas
def play(): channel = request_data().get("channel") acc_id = request_data().get("acc_id") gameid = request_data().get("gameid", 0) url = redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "h5_link") new_acc = "%s_%s" % (channel, acc_id) Now = int(time.time()) payload = { "channel": channel, "acc_id": new_acc, "timestamp": Now, "gameid": gameid, "return_url": request_data().get("return_url", ""), "token": md5(new_acc + str(Now) + SECRET_KEY) } url2 = "%s?%s" % (url, "&".join( ["%s=%s" % (k, v) for k, v in payload.items()])) return ok_return(url=url2)
def load_annouce(channel): Now = time_util.now_sec() nl = {} sql = ''' select id, push_times, priority, content_image_url, start_date, end_date from admin_announcement where status = 1 AND end_date>=%s ''' % (Now) for line in LogQry(channel).qry(sql): ele = { "notice_id": int(line[0]), ## 公告ID "push_times": line[1], ## 推送次数 "priority": line[2], ## 优先级 "content_img": line[3], ## 内容图片链接 "start_time": line[4], "end_time": line[5], } nl[line[0]] = ele name = redis_conn.hget(CHANNEL_CONFIG_TABLE + str(channel), "name") if nl: redis_conn.hmset(NOTICE_TABLE + name, nl)
def api_withdraw_list(): # 接收渠道 channel_name = request.args.get('channel') pid = request.args.get('pid') ## 查询渠道ID channel = int(redis_conn.hget(CHANNEL_CONFIG_TABLE + channel_name, "id")) datas = [] sql = ''' select application_time, withdraw_deposit_money, status from admin_withdraw where pid = %s order by application_time desc limit 10 ''' % (pid) for time, money, status in LogQry(channel).qry(sql): datas.append({ "time": time, "money": money, "status": status, }) return jsonify(result="succ", datas=datas)
def api_recharge_list(): # 接收渠道 channel_name = request.args.get('channel') pid = request.args.get('pid') ## 查询渠道ID channel = int(redis_conn.hget(CHANNEL_CONFIG_TABLE + channel_name, "id")) datas = [] sql = ''' select time, orderno, cost, state from admin_recharge where pid = %s order by time desc limit 10 ''' % (pid) for time, orderno, cost, state in LogQry(channel).qry(sql): datas.append({ "time":time, "orderno":orderno, "cost":cost, "state":state, }) return jsonify(result="succ", datas= datas)
def get_wx_h5_list(Channel): return [redis_conn.hget(CHANNEL_CONFIG_TABLE + Channel, "h5_wx_appid")]