def pay(): sessionid = flask.request.values.get('sessionid') money = flask.request.values.get('money') if not sessionid or not money: data = {"code": -1, 'msg': '不能为空'} elif not tools.is_price(money): data = {"code": -1, 'msg': '不能为空'} else: r = tools.get_redis() sessionid_key = r.keys('*%s' % sessionid) if sessionid_key: sessionid = sessionid_key[0] else: return json.dumps({"code": -1, "msg": "请登录"}) user_info = tools.my_redis(sessionid) if user_info: user_info = json.loads(user_info) user_id = user_info.get("user_id") sql = 'select balance from app_myuser where id=%s;' % user_id balance = tools.op_mysql(sql, False).get("balance") money = float(money) if balance >= money: # balance-=money update_sql = "update app_myuser set balance = balance-%s where id = %s" % ( money, user_id) print(update_sql) tools.op_mysql(update_sql) data = {"code": 0, "msg": "支付成功"} else: data = {"code": 0, "msg": "余额不足"} else: data = {"code": -1, "msg": "请登录"} return json.dumps(data, ensure_ascii=False, indent=4)
def login(): username = flask.request.values.get('username') password = flask.request.values.get('password') if not username or not password: data = {"code": -1, 'msg': '不能为空'} else: # new_password = tools.md5(password) new_password = password sql = 'select id,username,passwd,error_count from app_myuser where username="******";' % ( username) result = tools.op_mysql(sql, False) if result: if result.get('error_count') > 5: data = {"code": -1, 'msg': '账号已经被锁定'} elif new_password == result.get('passwd'): up_sql = 'update app_myuser set error_count=0 where username="******";' % username tools.op_mysql(up_sql) r = tools.get_redis() user_keys = r.keys('%s*' % username) if user_keys: sessionid = user_keys[0].lstrip(username) else: sessionid = tools.get_sessionid(username) user_info = json.dumps({ "user_id": result.get('id'), "username": username }) tools.my_redis(username + sessionid, user_info) data = {"code": 0, "msg": "登录成功", "session_id": sessionid} else: up_sql = 'update app_myuser set error_count=error_count+1 where username="******";' % username tools.op_mysql(up_sql) data = {"code": -1, 'msg': '密码错误'} else: data = {"code": -1, 'msg': '用户不存在'} return json.dumps(data, ensure_ascii=False, indent=4)
# -*- coding: utf-8 -*- import sys import tools import time reload(sys) sys.setdefaultencoding('utf-8') redis_conn = tools.get_redis() # init statistics redis_conn.set('last_get_time', time.time()) redis_conn.setnx('request_num', 0) redis_conn.setnx('response_num', 0) redis_conn.setnx('page_num', 0) redis_conn.setnx('item_num', 0) redis_conn.setnx('error_num', 0) def get_request_num(): return int(redis_conn.get('request_num')) def add_request_num(): return int(redis_conn.incr('request_num')) def get_response_num(): return int(redis_conn.get('response_num'))
import time import tools import traceback import json from threading import Thread from config import global_config as config log = tools.logger('fl') agentId = config.get('fl', 'agentId') businessId = config.get('fl', 'businessId') tradePwd = config.get('fl', 'tradePwd') charge_url = config.get('fl', 'charge_url') appKey = config.get('fl', 'appKey') thread_num = int(config.get('fl', 'thread_num')) sleep_time = int(config.get('fl', 'sleep_time')) redis = tools.get_redis('fl') def charge(phone, face): resp = '' param = { "agentId": agentId, "businessId": businessId, "reqStreamId": "fd{}{}".format(str(round(time.time() * 1000)), random.randint(100, 1000)), "phone": str(phone), "face":
import defaultsettings # build-in import sys try: import cPickle as pickle except ImportError: import pickle import time # need import gevent reload(sys) sys.setdefaultencoding('utf-8') logger = get_logger(__name__) redis_conn = get_redis() class EmptyError(Exception): pass def log_push(func): def _log(request, spider): func(request, spider) logger.debug('Push request<%s> into queue', request) return _log class RequestQueue(object): """存储请求的队列"""
import time import tools import traceback import json from threading import Thread from config import global_config as config log = tools.logger('bn') agentId = config.get('bn', 'agentId') businessId = config.get('bn', 'businessId') tradePwd = config.get('bn', 'tradePwd') charge_url = config.get('bn', 'charge_url') appKey = config.get('bn', 'appKey') thread_num = int(config.get('bn', 'thread_num')) sleep_time = int(config.get('bn', 'sleep_time')) redis = tools.get_redis('bn') def charge(phone, face): resp = '' param = { "agentId": agentId, "businessId": businessId, "reqStreamId": "fd{}{}".format(str(round(time.time() * 1000)), random.randint(100, 1000)), "phone": str(phone), "face":
import random import json from threading import Thread charge_url = config.get('xt', 'charge_url') PlatID = config.get('xt', 'PlatID') API_KEY = config.get('xt', 'API_KEY') db_host = config.get('xt', 'db_host') db_host = config.get('xt', 'db_host') db_port = int(config.get('xt', 'db_port')) db_user = config.get('xt', 'db_user') db_password = config.get('xt', 'db_password') db_name = config.get('xt', 'db_name') thread_num = int(config.get('xt', 'thread_num')) log = tools.logger('xt') redis = tools.get_redis('xt') def pre_charge(phone, face): flag = False try: con = pymysql.Connect(host=db_host, port=db_port, user=db_user, passwd=db_password, db=db_name) cursor = con.cursor() month = time.strftime('%Y%m')[2:] time_str = time.strftime('%Y%m%d%H%M%S') sql = "insert into phonerepository{}(phone,face,tradetime,chgtime,state) values({},{},{},{},0)".format(month, phone, face, time_str, time_str) cursor.execute(sql) con.commit() cursor.close() con.close() flag = True
import time import tools import traceback import json from threading import Thread from config import global_config as config log = tools.logger('bx') agentId = config.get('bx', 'agentId') businessId = config.get('bx', 'businessId') tradePwd = config.get('bx', 'tradePwd') charge_url = config.get('bx', 'charge_url') appKey = config.get('bx', 'appKey') thread_num = int(config.get('bx', 'thread_num')) sleep_time = int(config.get('bx', 'sleep_time')) redis = tools.get_redis('bx') def charge(phone, face): resp = '' param = { "agentId": agentId, "businessId": businessId, "reqStreamId": "fd{}{}".format(str(round(time.time() * 1000)), random.randint(100, 1000)), "phone": str(phone), "face":