Skip to content

Commit

Permalink
chore: update 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
xingyuv committed Jan 29, 2023
1 parent 3d6198c commit 531f627
Show file tree
Hide file tree
Showing 22 changed files with 113 additions and 109 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ spring mvc
<dependency>
<groupId>com.xingyuv</groupId>
<artifactId>captcha-plus</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
```
spring boot 2
```xml
<dependency>
<groupId>com.xingyuv</groupId>
<artifactId>spring-boot-starter-captcha-plus</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
```
spring boot 3
```xml
<dependency>
<groupId>com.xingyuv</groupId>
<artifactId>spring-boot-starter-captcha-plus</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion core/captcha-plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ a.引入jar,已上传至maven中央仓库。
<dependency>
<groupId>com.xingyuv</groupId>
<artifactId>captcha-plus</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
```
b.修改application.properties,自定义底图和水印,启动后前端就可以请求接口了。[社区底图库](https://gitee.com/anji-plus/AJ-Captcha-Images)
Expand Down
2 changes: 1 addition & 1 deletion core/captcha-plus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.xingyuv</groupId>
<artifactId>captcha-plus</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>

<name>${project.groupId}:${project.artifactId}</name>
<description>captcha-plus.jar</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public enum RepCodeEnum {
API_REQ_INVALID("6206", "无效请求,请重新获取验证码"),
API_REQ_LOCK_GET_ERROR("6202", "接口验证失败数过多,请稍后再试"),
API_REQ_LIMIT_CHECK_ERROR("6204", "check接口请求次数超限,请稍后再试!"),
API_REQ_LIMIT_VERIFY_ERROR("6205", "verify请求次数超限!"),
;
API_REQ_LIMIT_VERIFY_ERROR("6205", "verify请求次数超限!");
private String code;
private String desc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,30 @@ public abstract class AbstractCaptchaService implements CaptchaService {

protected static String waterMarkFontStr = "WenQuanZhengHei.ttf";

protected Font waterMarkFont;//水印字体
/**
* 水印字体
*/
protected Font waterMarkFont;

protected static String slipOffset = "5";

protected static Boolean captchaAesStatus = true;

protected static String clickWordFontStr = "WenQuanZhengHei.ttf";

protected Font clickWordFont;//点选文字字体
/**
* 点选文字字体
*/
protected Font clickWordFont;

protected static String cacheType = "local";

protected static int captchaInterferenceOptions = 0;

//判断应用是否实现了自定义缓存,没有就使用内存
/**
* 判断应用是否实现了自定义缓存,没有就使用内存
* @param config config
*/
@Override
public void init(final Properties config) {
//初始化底图
Expand Down Expand Up @@ -242,9 +251,10 @@ public static boolean base64StrToImage(String imgStr, String path) {
/**
* 解密前端坐标aes加密
*
* @param point
* @return
* @throws Exception
* @param point 前端坐标
* @param key key
* @return 前端坐标aes加密
* @throws Exception E
*/
public static String decrypt(String point, String key) throws Exception {
return AESUtil.aesDecrypt(point, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ public ResponseModel verification(CaptchaVO captchaVO) {

/**
* 根据模板切图
*
* @throws Exception
* @param originalImage originalImage
* @param jigsawImage jigsawImage
* @param jigsawImageBase64 jigsawImageBase64
* @return CaptchaVO
*/
public CaptchaVO pictureTemplatesCut(BufferedImage originalImage, BufferedImage jigsawImage, String jigsawImageBase64) {
try {
Expand All @@ -167,7 +169,6 @@ public CaptchaVO pictureTemplatesCut(BufferedImage originalImage, BufferedImage
//随机生成拼图坐标
PointVO point = generateJigsawPoint(originalWidth, originalHeight, jigsawWidth, jigsawHeight);
int x = point.getX();
int y = point.getY();

//生成新的拼图图像
BufferedImage newJigsawImage = new BufferedImage(jigsawWidth, jigsawHeight, jigsawImage.getType());
Expand Down Expand Up @@ -241,15 +242,13 @@ public CaptchaVO pictureTemplatesCut(BufferedImage originalImage, BufferedImage
}
}


/**
* 随机生成拼图坐标
*
* @param originalWidth
* @param originalHeight
* @param jigsawWidth
* @param jigsawHeight
* @return
* @param originalWidth originalWidth
* @param originalHeight originalHeight
* @param jigsawWidth jigsawWidth
* @param jigsawHeight jigsawHeight
* @return PointVO
*/
private static PointVO generateJigsawPoint(int originalWidth, int originalHeight, int jigsawWidth, int jigsawHeight) {
Random random = new Random();
Expand Down Expand Up @@ -279,7 +278,6 @@ private static PointVO generateJigsawPoint(int originalWidth, int originalHeight
* @param newImage 新抠出的小图
* @param x 随机扣取坐标X
* @param y 随机扣取坐标y
* @throws Exception
*/
private static void cutByTemplate(BufferedImage oriImage, BufferedImage templateImage, BufferedImage newImage, int x, int y) {
//临时数组遍历用于高斯模糊存周边像素值
Expand Down Expand Up @@ -327,7 +325,6 @@ private static void cutByTemplate(BufferedImage oriImage, BufferedImage template
* @param templateImage 模板图
* @param x 随机扣取坐标X
* @param y 随机扣取坐标y
* @throws Exception
*/
private static void interferenceByTemplate(BufferedImage oriImage, BufferedImage templateImage, int x, int y) {
//临时数组遍历用于高斯模糊存周边像素值
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @author lide1202@hotmail.com
* @Title: 默认使用内存当缓存
* @date 2020-05-12
* @Date 2020-05-12
*/
public class CaptchaCacheServiceMemImpl implements CaptchaCacheService {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static CaptchaCacheService getCache(String cacheType) {
return cacheService.get(cacheType);
}

public volatile static Map<String, CaptchaService> instances = new HashMap();
public volatile static Map<String, CaptchaCacheService> cacheService = new HashMap();
public volatile static Map<String, CaptchaService> instances = new HashMap<>();
public volatile static Map<String, CaptchaCacheService> cacheService = new HashMap<>();

static {
ServiceLoader<CaptchaCacheService> cacheServices = ServiceLoader.load(CaptchaCacheService.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public ResponseModel get(CaptchaVO captchaVO) {
return ResponseModel.errorMsg(RepCodeEnum.API_CAPTCHA_BASEMAP_NULL);
}
CaptchaVO imageData = getImageData(bufferedImage);
if (imageData == null
|| StringUtils.isBlank(imageData.getOriginalImageBase64())) {
if (StringUtils.isBlank(imageData.getOriginalImageBase64())) {
return ResponseModel.errorMsg(RepCodeEnum.API_CAPTCHA_ERROR);
}
return ResponseModel.successData(imageData);
Expand Down Expand Up @@ -139,7 +138,7 @@ public ResponseModel check(CaptchaVO captchaVO) {
}
//校验成功,将信息存入缓存
String secretKey = point.get(0).getSecretKey();
String value = null;
String value;
try {
value = AESUtil.aesEncrypt(captchaVO.getToken().concat("---").concat(pointJson), secretKey);
} catch (Exception e) {
Expand Down Expand Up @@ -296,7 +295,7 @@ private Set<String> getRandomWords(int wordCount) {
* @param imageHeight 图片高度
* @param wordSortIndex 字体循环排序下标(i)
* @param wordCount 字数量
* @return
* @return PointVO
*/
private static PointVO randomWordPoint(int imageWidth, int imageHeight, int wordSortIndex, int wordCount) {
int avgWidth = imageWidth / (wordCount + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ public interface FrequencyLimitHandler {
/**
* get 接口限流
*
* @param captchaVO
* @return
* @param captchaVO captchaVO
* @return ResponseModel
*/
ResponseModel validateGet(CaptchaVO captchaVO);

/**
* check接口限流
*
* @param captchaVO
* @return
* @param captchaVO captchaVO
* @return ResponseModel
*/
ResponseModel validateCheck(CaptchaVO captchaVO);

/**
* verify接口限流
*
* @param captchaVO
* @return
* @param captchaVO captchaVO
* @return ResponseModel
*/
ResponseModel validateVerify(CaptchaVO captchaVO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import java.util.Base64;

public class AESUtil {
//算法
/**
* 算法
*/
private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding";

/**
* 获取随机key
*
* @return
* @return 随机key
*/
public static String getKey() {
return RandomUtils.getRandomString(16);
Expand All @@ -36,7 +38,8 @@ public static String getKey() {
* @return 转换后的字符串
*/
public static String binary(byte[] bytes, int radix) {
return new BigInteger(1, bytes).toString(radix);// 这里的1代表正数
// 这里的1代表正数
return new BigInteger(1, bytes).toString(radix);
}

/**
Expand All @@ -46,7 +49,6 @@ public static String binary(byte[] bytes, int radix) {
* @return 编码后的base 64 code
*/
public static String base64Encode(byte[] bytes) {
//return Base64.encodeBase64String(bytes);
return Base64.getEncoder().encodeToString(bytes);
}

Expand All @@ -55,7 +57,7 @@ public static String base64Encode(byte[] bytes) {
*
* @param base64Code 待解码的base 64 code
* @return 解码后的byte[]
* @throws Exception
* @throws Exception e
*/
public static byte[] base64Decode(String base64Code) throws Exception {
Base64.Decoder decoder = Base64.getDecoder();
Expand All @@ -69,7 +71,7 @@ public static byte[] base64Decode(String base64Code) throws Exception {
* @param content 待加密的内容
* @param encryptKey 加密密钥
* @return 加密后的byte[]
* @throws Exception
* @throws Exception e
*/
public static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
Expand All @@ -87,7 +89,7 @@ public static byte[] aesEncryptToBytes(String content, String encryptKey) throws
* @param content 待加密的内容
* @param encryptKey 加密密钥
* @return 加密后的base 64 code
* @throws Exception
* @throws Exception e
*/
public static String aesEncrypt(String content, String encryptKey) throws Exception {
if (StringUtils.isBlank(encryptKey)) {
Expand All @@ -102,7 +104,7 @@ public static String aesEncrypt(String content, String encryptKey) throws Except
* @param encryptBytes 待解密的byte[]
* @param decryptKey 解密密钥
* @return 解密后的String
* @throws Exception
* @throws Exception e
*/
public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
Expand All @@ -121,7 +123,7 @@ public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) t
* @param encryptStr 待解密的base 64 code
* @param decryptKey 解密密钥
* @return 解密后的string
* @throws Exception
* @throws Exception e
*/
public static String aesDecrypt(String encryptStr, String decryptKey) throws Exception {
if (StringUtils.isBlank(decryptKey)) {
Expand All @@ -133,15 +135,15 @@ public static String aesDecrypt(String encryptStr, String decryptKey) throws Exc
/**
* 测试
*/
public static void main(String[] args) throws Exception {
String randomString = RandomUtils.getRandomString(16);
String content = "hahhahaahhahni";
System.out.println("加密前:" + content);
System.out.println("加密密钥和解密密钥:" + randomString);
String encrypt = aesEncrypt(content, randomString);
System.out.println("加密后:" + encrypt);
String decrypt = aesDecrypt(encrypt, randomString);
System.out.println("解密后:" + decrypt);
}
// public static void main(String[] args) throws Exception {
// String randomString = RandomUtils.getRandomString(16);
// String content = "hahhahaahhahni";
// System.out.println("加密前:" + content);
// System.out.println("加密密钥和解密密钥:" + randomString);
// String encrypt = aesEncrypt(content, randomString);
// System.out.println("加密后:" + encrypt);
// String decrypt = aesDecrypt(encrypt, randomString);
// System.out.println("解密后:" + decrypt);
// }

}
Loading

0 comments on commit 531f627

Please sign in to comment.