Exemple #1
0
def get_bet_number(game_serial, amount):
    redis_tool = RedisTools()

    if redis_tool.exists(game_serial):
        lock = redis_lock.Lock(redis_tool.redis_conn, 'bet_number', expire=1)
        if lock.acquire():
            array_full = json.loads(redis_tool.get(game_serial))

            length = len(array_full)
            if length <= 0:
                return 3000
            if length < amount:
                return 3001

            award_number_arr = random.sample(array_full, amount)

            # print(award_number_arr)
            # print(type(award_number_arr))

            array_full = list(
                set(array_full).difference(set(award_number_arr)))

            if len(array_full) <= 0:
                redis_tool.delete(game_serial)
            else:
                redis_tool.set(game_serial, json.dumps(array_full))

            lock.release()
            return award_number_arr

    return 3002
Exemple #2
0
    def generator_user_tokens(self,
                              user_id,
                              user_type=_USER_TYPE_INVEST,
                              source=ApiTokenModel.source_type_1):
        """
        生成用的access_token和refresh_token
        :param user_id:
        :return:
        """
        self.check_api_token_source(source)
        with self.session_scope() as session:
            # 将之前的token删除
            self.delete_all_token(user_id, user_type, source)

            redis_tool = RedisTools()
            access_token_key = self.make_access_token_redis_key(
                user_id, user_type, source)
            redis_tool.delete(access_token_key)

            access_token_ex = self.get_access_token_ex(source)
            refresh_token_ex = self.get_refresh_token_ex(source)

            # 生成token
            access_token_expire_time = datetime.datetime.fromtimestamp(
                int(time.time()) + access_token_ex)
            refresh_token_expire_time = datetime.datetime.fromtimestamp(
                int(time.time()) + refresh_token_ex)
            access_token = self.generate_token(user_id, uuid.uuid4().hex)
            refresh_token = self.generate_token(user_id, uuid.uuid4().hex)

            access_token_model = ApiTokenModel(
                user_id=user_id,
                token_type=self.mysql_access_token_key,
                token=access_token,
                user_type=user_type,
                source=source,
                expire_at=access_token_expire_time)
            refresh_token_model = ApiTokenModel(
                user_id=user_id,
                token_type=self.mysql_refresh_token_key,
                token=refresh_token,
                user_type=user_type,
                source=source,
                expire_at=refresh_token_expire_time)
            session.add(access_token_model)
            session.add(refresh_token_model)
            session.commit()
            redis_tool.set(access_token_key, access_token, ex=access_token_ex)

            result = {
                "access_token": access_token,
                "access_token_expire_time": str(access_token_expire_time),
                "refresh_token": refresh_token,
                "refresh_token_expire_time": str(refresh_token_expire_time),
                "user_id": user_id,
            }

            return result
Exemple #3
0
 def check_register_signature(self, register_signature, direct_error=True):
     env = get_conf('env')
     if register_signature == "111111" and env == 'dev':
         return True
     redis_tools = RedisTools()
     if redis_tools.exists(register_signature):
         redis_tools.delete(register_signature)
         return True
     if direct_error:
         self.return_aes_error(30058)
     else:
         return False
 def check_sms_email_vcode(self, vcode_key, vcode):
     email_config = get_sms_email(vcode_key)
     if email_config == {}:
         self.return_error(35034)
     redis = RedisTools()
     redis_key = self.get_sms_email_key(email_config['redis_key'], vcode)
     redis_value = redis.get(redis_key)
     if not redis_value:
         self.return_error(30036)
     if str(redis_value, encoding='utf-8') != str(vcode):
         self.return_error(30036)
     redis.delete(redis_key)
     return True
Exemple #5
0
    def check_vcode(self,
                    vcode,
                    code_type,
                    mobile,
                    user_type=_USER_TYPE_INVEST,
                    register_by=None,
                    direct_return_error=True):
        if register_by in [_REGISTER_BY_MOBILE]:
            self.check_mobile_all(mobile)
        elif register_by in [_REGISTER_BY_EMAIL]:
            self.check_email(mobile)
        elif register_by in [
                _REGISTER_AUTHEN_MOBILE,
                _REGISTER_SET_PAYPD_MOBILE,
                _RESET_PWD_MOBILE,
                _REGISTER_AUTHEN_EMAIL,
                _REGISTER_SET_PAYPD_EMAIL,
                _RESET_PWD_EMAIL,
                _REGISTER_SET_EMAIL,
                _REGISTER_SET_MOBILE,
                _REGISTER_RESET_PAYPD_MOBILE,
                _REGISTER_RESET_PAYPD_EMAIL,
        ]:
            pass
        else:
            self.check_mobile(mobile)
        env = get_conf("env")
        if vcode == "111111" and env == 'dev':
            return True

        redis = RedisTools()
        redis_key = self.get_sms_key(mobile, code_type, user_type)
        check_result = redis.get(redis_key)
        if check_result:
            redis.delete(redis_key)
            return True
        else:
            if direct_return_error:
                self.return_aes_error(30059)
            else:
                return False
Exemple #6
0
 def check_vcode_picture(self,
                         vcode_str,
                         vcode_key='',
                         vcode_type=_REQUEST_TYPE_REGISTER,
                         user_type=_USER_TYPE_INVEST):
     env = get_conf('env')
     if vcode_str == "111111" and env == 'dev':
         return True
     if vcode_key == '':
         redis_key = self.vcode_picture_key + str(vcode_type) + ':' + str(
             user_type) + ':' + str(vcode_str).lower()
     else:
         redis_key = self.vcode_picture_key + str(vcode_type) + ':' + str(
             user_type) + ':' + str(vcode_key)
     redis_tools = RedisTools()
     redis_result = redis_tools.get(redis_key)
     raise_logger('check vcode' + ' ' + str(redis_key))
     if redis_result is None:
         self.return_aes_error(30052)
     if str(redis_result,
            encoding='utf-8').lower() != str(vcode_str).lower():
         self.return_aes_error(30060)
     redis_tools.delete(redis_key)
     return True