从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

相关文章

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

基于Python开发PPTX压缩工具

《基于Python开发PPTX压缩工具》在日常办公中,PPT文件往往因为图片过大而导致文件体积过大,不便于传输和存储,所以本文将使用Python开发一个PPTX压缩工具,需要的可以了解下... 目录引言全部代码环境准备代码结构代码实现运行结果引言在日常办公中,PPT文件往往因为图片过大而导致文件体积过大,

使用DeepSeek API 结合VSCode提升开发效率

《使用DeepSeekAPI结合VSCode提升开发效率》:本文主要介绍DeepSeekAPI与VisualStudioCode(VSCode)结合使用,以提升软件开发效率,具有一定的参考价值... 目录引言准备工作安装必要的 VSCode 扩展配置 DeepSeek API1. 创建 API 请求文件2.

基于Python开发电脑定时关机工具

《基于Python开发电脑定时关机工具》这篇文章主要为大家详细介绍了如何基于Python开发一个电脑定时关机工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 简介2. 运行效果3. 相关源码1. 简介这个程序就像一个“忠实的管家”,帮你按时关掉电脑,而且全程不需要你多做

Java中的Opencv简介与开发环境部署方法

《Java中的Opencv简介与开发环境部署方法》OpenCV是一个开源的计算机视觉和图像处理库,提供了丰富的图像处理算法和工具,它支持多种图像处理和计算机视觉算法,可以用于物体识别与跟踪、图像分割与... 目录1.Opencv简介Opencv的应用2.Java使用OpenCV进行图像操作opencv安装j

基于Qt开发一个简单的OFD阅读器

《基于Qt开发一个简单的OFD阅读器》这篇文章主要为大家详细介绍了如何使用Qt框架开发一个功能强大且性能优异的OFD阅读器,文中的示例代码讲解详细,有需要的小伙伴可以参考一下... 目录摘要引言一、OFD文件格式解析二、文档结构解析三、页面渲染四、用户交互五、性能优化六、示例代码七、未来发展方向八、结论摘要

在 VSCode 中配置 C++ 开发环境的详细教程

《在VSCode中配置C++开发环境的详细教程》本文详细介绍了如何在VisualStudioCode(VSCode)中配置C++开发环境,包括安装必要的工具、配置编译器、设置调试环境等步骤,通... 目录如何在 VSCode 中配置 C++ 开发环境:详细教程1. 什么是 VSCode?2. 安装 VSCo

C#图表开发之Chart详解

《C#图表开发之Chart详解》C#中的Chart控件用于开发图表功能,具有Series和ChartArea两个重要属性,Series属性是SeriesCollection类型,包含多个Series对... 目录OverviChina编程ewSeries类总结OverviewC#中,开发图表功能的控件是Char

鸿蒙开发搭建flutter适配的开发环境

《鸿蒙开发搭建flutter适配的开发环境》文章详细介绍了在Windows系统上如何创建和运行鸿蒙Flutter项目,包括使用flutterdoctor检测环境、创建项目、编译HAP包以及在真机上运... 目录环境搭建创建运行项目打包项目总结环境搭建1.安装 DevEco Studio NEXT IDE

Python开发围棋游戏的实例代码(实现全部功能)

《Python开发围棋游戏的实例代码(实现全部功能)》围棋是一种古老而复杂的策略棋类游戏,起源于中国,已有超过2500年的历史,本文介绍了如何用Python开发一个简单的围棋游戏,实例代码涵盖了游戏的... 目录1. 围棋游戏概述1.1 游戏规则1.2 游戏设计思路2. 环境准备3. 创建棋盘3.1 棋盘类