从0~1开发财务软件

2024-06-08 16:52
文章标签 开发 财务软件

本文主要是介绍从0~1开发财务软件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 1.获取图形验证码接口

功能要求

1、随机生成6位字符

2、将字符生成base64位格式的图片,返回给前端

3、将生成的字符存储到redis中,用匿名身份id(clientId)作为key,验证码作为value。

clientId通过/login/getClientId接口获取

4、验证码15分钟后过期

依赖包
<!-- 工具类 -->
<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.10</version>
</dependency><!-- redis -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><version>2.7.5</version>
</dependency>

redis缓存配置并完善图形验证码接口 

# redis配置
redis:database: 0port: 6379lettuce:pool:#连接池中最大空闲连接数为 30。这意味着连接池可以保持最多 30 个空闲的 Redis 连接,以便在需要时重用。max-idle: 30#连接池中最小空闲连接数为 10。这表示连接池至少会保持 10 个空闲连接,以便在需要时快速获取可用连接。min-idle: 10#连接池中的最大活动连接数为 30。这是指连接池在同一时间可以支持的最大活动(使用中)连接数量。max-active: 30#当连接池已用尽且达到最大活动连接数时,从连接池获取连接的最大等待时间为 10,000 毫秒(10 秒)。如果在等待时间内没有可用连接,将抛出连接超时异常。max-wait: 10000# 应用程序关闭时Lettuce 将等待最多 3 秒钟来完成关闭操作。如果超过这个时间仍未完成,则会强制关闭连接。shutdown-timeout: 3000host: 127.0.0.1

RedisTemplateDefaultConfig.java 

package com.bage.common.config;import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;/*** Redis Template 配置**/
@ConditionalOnProperty(prefix = "sys",name = "redis-template-config",havingValue = "true")
@Configuration
@Slf4j
public class RedisTemplateDefaultConfig<T> {/*** redisTemplate相关配置** @param factory* @return*/@Beanpublic RedisTemplate<String, T> redisTemplate(RedisConnectionFactory factory) {log.info("RedisTemplateConfig init start ...");RedisTemplate<String, T> template = new RedisTemplate<>();// 配置连接工厂template.setConnectionFactory(factory);//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)Jackson2JsonRedisSerializer<Object> jacksonSerializer = new Jackson2JsonRedisSerializer<>(Object.class);ObjectMapper om = new ObjectMapper();// 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和publicom.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);jacksonSerializer.setObjectMapper(om);// 值采用json序列化template.setValueSerializer(jacksonSerializer);// 使用StringRedisSerializer来序列化和反序列化redis的key值template.setKeySerializer(new StringRedisSerializer());// 设置hash key 和value序列化模式template.setHashKeySerializer(new StringRedisSerializer());template.setHashValueSerializer(jacksonSerializer);template.afterPropertiesSet();log.info("RedisTemplateConfig init end");return template;}
}

 

 

LoginController.java

import com.bage.finance.biz.dto.form.GetBase64CodeForm;
import com.bage.finance.biz.service.MemberLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** @author 啟王朝* date2024/6/6 18:24*/
@Api(tags = "用户登录模块")
@RestController
@RequestMapping("/login")
@RequiredArgsConstructor
/**  @RequiredArgsConstructor final* 作用: 可以省略 @Autowired 和 @Rescuorce  需要注入包的前面必须加上final*/
@Slf4j
public class LoginController {final MemberLoginService memberLoginService;//  获得游客登录的getClientId@ApiOperation(value = "获取客户端id")@GetMapping("/getClientId")public com.bage.common.dto.ApiResponse<String> getClientId() {String clientId = memberLoginService.getClientId();return com.bage.common.dto.ApiResponse.success(clientId);}/*** 作用:*/@ApiOperation(value = "生成base64位格式的图片")@GetMapping("/getBase6Code")/*** 作用:    GetBase64CodeForm form  是将生成的字符存储到redis中,用匿名身份id(clientId)作为key,验证码作为value。* 0*///   @Validated  必须加统一拦截才能起作用public com.bage.common.dto.ApiResponse<String> getBase64Code(@Validated @ModelAttribute GetBase64CodeForm form) {//  返回的是code 为Base64的验证码图片String code = memberLoginService.getBase64Code(form);return com.bage.common.dto.ApiResponse.success(code);}
}

MemberLoginService.java

import com.bage.finance.biz.dto.form.GetBase64CodeForm;/*** @Author:啟王朝* @name:MemberLoginService* @Date:2024/6/6 18:18* @Filename:MemberLoginService*/
public interface MemberLoginService {//  获取客户端idString getClientId();/*** 作用:获得Base64的图形编码*/String getBase64Code(GetBase64CodeForm form);
}

MemberLoginServiceImpl.java 

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import com.bage.finance.biz.dto.form.GetBase64CodeForm;
import com.bage.finance.biz.service.MemberLoginService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;import java.util.UUID;
import java.util.concurrent.TimeUnit;import static com.bage.finance.biz.constant.RedisKeyConstant.GRAPHIC_VERIFICATION_CODE;/*** @author 啟王朝* date2024/6/6 18:19*/
@Service
@Slf4j
@RequiredArgsConstructor //  构造参数的注解
public class MemberLoginServiceImpl implements MemberLoginService {final RedisTemplate<String, String> redisTemplate;/*** @Date:获取客户端id // date变量下面会用内置函数进行赋值* @Author:* @return:*/@Overridepublic String getClientId() {return UUID.randomUUID().toString().replace("-", "");}/*** 作用:获取图形验证码界面*/@Overridepublic String getBase64Code(GetBase64CodeForm form) {//  TODO  CaptchaUtil  用工具形成验证码图片/*** 作用:* <dependency>*   <groupId>cn.hutool</groupId>*   <artifactId>hutool-all</artifactId>*   <version>5.8.10</version>* </dependency>*   300,192代表长和宽   5 代表5个字符   lineCount的数字越大,代表的数字越模糊 1000*/LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(300, 192, 5, 1000);//  将验证码内容读出来String code = lineCaptcha.getCode();//  todo 将验证码保存到redis中redisTemplate.opsForValue().set(GRAPHIC_VERIFICATION_CODE + form.getClientId(), code,15, TimeUnit.MINUTES);//  返回base64的图形验证码return lineCaptcha.getImageBase64();}
}

这篇关于从0~1开发财务软件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1042757

相关文章

基于Python开发Windows屏幕控制工具

《基于Python开发Windows屏幕控制工具》在数字化办公时代,屏幕管理已成为提升工作效率和保护眼睛健康的重要环节,本文将分享一个基于Python和PySide6开发的Windows屏幕控制工具,... 目录概述功能亮点界面展示实现步骤详解1. 环境准备2. 亮度控制模块3. 息屏功能实现4. 息屏时间

Python实例题之pygame开发打飞机游戏实例代码

《Python实例题之pygame开发打飞机游戏实例代码》对于python的学习者,能够写出一个飞机大战的程序代码,是不是感觉到非常的开心,:本文主要介绍Python实例题之pygame开发打飞机... 目录题目pygame-aircraft-game使用 Pygame 开发的打飞机游戏脚本代码解释初始化部

使用Python开发一个现代化屏幕取色器

《使用Python开发一个现代化屏幕取色器》在UI设计、网页开发等场景中,颜色拾取是高频需求,:本文主要介绍如何使用Python开发一个现代化屏幕取色器,有需要的小伙伴可以参考一下... 目录一、项目概述二、核心功能解析2.1 实时颜色追踪2.2 智能颜色显示三、效果展示四、实现步骤详解4.1 环境配置4.

Python使用smtplib库开发一个邮件自动发送工具

《Python使用smtplib库开发一个邮件自动发送工具》在现代软件开发中,自动化邮件发送是一个非常实用的功能,无论是系统通知、营销邮件、还是日常工作报告,Python的smtplib库都能帮助我们... 目录代码实现与知识点解析1. 导入必要的库2. 配置邮件服务器参数3. 创建邮件发送类4. 实现邮件

基于Python开发一个有趣的工作时长计算器

《基于Python开发一个有趣的工作时长计算器》随着远程办公和弹性工作制的兴起,个人及团队对于工作时长的准确统计需求日益增长,本文将使用Python和PyQt5打造一个工作时长计算器,感兴趣的小伙伴可... 目录概述功能介绍界面展示php软件使用步骤说明代码详解1.窗口初始化与布局2.工作时长计算核心逻辑3

python web 开发之Flask中间件与请求处理钩子的最佳实践

《pythonweb开发之Flask中间件与请求处理钩子的最佳实践》Flask作为轻量级Web框架,提供了灵活的请求处理机制,中间件和请求钩子允许开发者在请求处理的不同阶段插入自定义逻辑,实现诸如... 目录Flask中间件与请求处理钩子完全指南1. 引言2. 请求处理生命周期概述3. 请求钩子详解3.1

如何基于Python开发一个微信自动化工具

《如何基于Python开发一个微信自动化工具》在当今数字化办公场景中,自动化工具已成为提升工作效率的利器,本文将深入剖析一个基于Python的微信自动化工具开发全过程,有需要的小伙伴可以了解下... 目录概述功能全景1. 核心功能模块2. 特色功能效果展示1. 主界面概览2. 定时任务配置3. 操作日志演示

JavaScript实战:智能密码生成器开发指南

本文通过JavaScript实战开发智能密码生成器,详解如何运用crypto.getRandomValues实现加密级随机密码生成,包含多字符组合、安全强度可视化、易混淆字符排除等企业级功能。学习密码强度检测算法与信息熵计算原理,获取可直接嵌入项目的完整代码,提升Web应用的安全开发能力 目录

一文教你如何解决Python开发总是import出错的问题

《一文教你如何解决Python开发总是import出错的问题》经常朋友碰到Python开发的过程中import包报错的问题,所以本文将和大家介绍一下可编辑安装(EditableInstall)模式,可... 目录摘要1. 可编辑安装(Editable Install)模式到底在解决什么问题?2. 原理3.

Python+PyQt5开发一个Windows电脑启动项管理神器

《Python+PyQt5开发一个Windows电脑启动项管理神器》:本文主要介绍如何使用PyQt5开发一款颜值与功能并存的Windows启动项管理工具,不仅能查看/删除现有启动项,还能智能添加新... 目录开篇:为什么我们需要启动项管理工具功能全景图核心技术解析1. Windows注册表操作2. 启动文件