Skip to content

Commit

Permalink
Merge branch 'master' into dev-1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
raodeming committed May 21, 2020
2 parents 0595ee4 + d67da9e commit 0f626dc
Show file tree
Hide file tree
Showing 49 changed files with 974 additions and 9,793 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ I Your application is running here: http://localhost:8081
####   6.2 增加ReactNative示例

# 6 技术支持微信群
<img src="https://images.gitee.com/uploads/images/2020/0511/091107_b81b631c_1728982.jpeg" width = "200" height = "200" div align=left />
<img src="https://images.gitee.com/uploads/images/2020/0518/092037_e8431f14_1728982.jpeg" width = "200" height = "200" div align=left />

测试多Git源-1

Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@
import com.anji.captcha.service.CaptchaService;
import com.anji.captcha.util.AESUtil;
import com.anji.captcha.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.PostConstruct;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.util.Base64;
import java.util.Map;

/**
* Created by raodeming on 2019/12/25.
*/
public abstract class AbstractCaptchaservice implements CaptchaService {
public abstract class AbstractCaptchaservice implements CaptchaService, InitializingBean {


protected static final String URL_PREFIX_HTTP = "http://";
Expand Down Expand Up @@ -53,8 +51,10 @@ public abstract class AbstractCaptchaservice implements CaptchaService {
protected CaptchaCacheService captchaCacheService;

//判断应用是否实现了自定义缓存,没有就使用内存
@PostConstruct
public void init(){


@Override
public void afterPropertiesSet() throws Exception {
Map<String, CaptchaCacheService> map = Container.getBeanOfType(CaptchaCacheService.class);
if(map == null || map.isEmpty()){
captchaCacheService = Container.getBean("captchaCacheServiceMemImpl", CaptchaCacheService.class);
Expand Down Expand Up @@ -113,8 +113,9 @@ protected String getImageToBase64Str (BufferedImage templateImage){
e.printStackTrace();
}
byte[] bytes = baos.toByteArray();
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encodeBuffer(bytes).trim();

Base64.Encoder encoder = Base64.getEncoder();
return encoder.encodeToString(bytes).trim();
}


Expand Down Expand Up @@ -153,10 +154,11 @@ public static boolean base64StrToImage(String imgStr, String path) {
if (imgStr == null) {
return false;
}
BASE64Decoder decoder = new BASE64Decoder();

Base64.Decoder decoder = Base64.getDecoder();
try {
// 解密
byte[] b = decoder.decodeBuffer(imgStr);
byte[] b = decoder.decode(imgStr);
// 处理数据
for (int i = 0; i < b.length; ++i) {
if (b[i] < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.anji.captcha.service.impl;

import com.alibaba.fastjson.JSONObject;

import com.anji.captcha.model.common.RepCodeEnum;
import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
Expand All @@ -20,12 +19,12 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import sun.misc.BASE64Encoder;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.util.Base64;
import java.util.Random;

/**
Expand Down Expand Up @@ -154,20 +153,18 @@ public CaptchaVO pictureTemplatesCut(BufferedImage originalImage, BufferedImage
graphics.drawImage(newJigsawImage, 0, 0, null);
graphics.dispose();


ByteArrayOutputStream os = new ByteArrayOutputStream();//新建流。
ImageIO.write(newJigsawImage, IMAGE_TYPE_PNG, os);//利用ImageIO类提供的write方法,将bi以png图片的数据模式写入流。
byte[] jigsawImages = os.toByteArray();

ByteArrayOutputStream oriImagesOs = new ByteArrayOutputStream();//新建流。
ImageIO.write(originalImage, IMAGE_TYPE_PNG, oriImagesOs);//利用ImageIO类提供的write方法,将bi以jpg图片的数据模式写入流。
byte[] oriCopyImages = oriImagesOs.toByteArray();

BASE64Encoder encoder = new BASE64Encoder();
dataVO.setOriginalImageBase64(encoder.encode(oriCopyImages).replaceAll("\r|\n", ""));
Base64.Encoder encoder = Base64.getEncoder();
dataVO.setOriginalImageBase64(encoder.encodeToString(oriCopyImages).replaceAll("\r|\n", ""));
//point信息不传到前端,只做后端check校验
// dataVO.setPoint(point);
dataVO.setJigsawImageBase64(encoder.encode(jigsawImages).replaceAll("\r|\n", ""));
dataVO.setJigsawImageBase64(encoder.encodeToString(jigsawImages).replaceAll("\r|\n", ""));
dataVO.setToken(RandomUtils.getUUID());
// BASE64Decoder decoder = new BASE64Decoder();
// base64StrToImage(encoder.encode(oriCopyImages), "D:\\原图.png");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import com.anji.captcha.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -33,7 +33,7 @@
@Component(value = "defaultCaptchaServiceImpl")
@Primary
@Order(Ordered.LOWEST_PRECEDENCE)
public class DefaultCaptchaServiceImpl implements CaptchaService {
public class DefaultCaptchaServiceImpl implements CaptchaService, InitializingBean {

private static Logger logger = LoggerFactory.getLogger(DefaultCaptchaServiceImpl.class);

Expand All @@ -48,8 +48,8 @@ public class DefaultCaptchaServiceImpl implements CaptchaService {
protected CaptchaCacheService captchaCacheService;

private Map<String,CaptchaService> instances = new HashMap();
@PostConstruct
public void init(){
@Override
public void afterPropertiesSet() throws Exception {
initCache();

Object t = this;
Expand Down
4 changes: 2 additions & 2 deletions core/captcha/src/main/java/com/anji/captcha/util/AESUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


//import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
Expand Down Expand Up @@ -57,7 +56,8 @@ public static String base64Encode(byte[] bytes){
* @throws Exception
*/
public static byte[] base64Decode(String base64Code) throws Exception{
return StringUtils.isEmpty(base64Code) ? null : new BASE64Decoder().decodeBuffer(base64Code);
Base64.Decoder decoder = Base64.getDecoder();
return StringUtils.isEmpty(base64Code) ? null : decoder.decode(base64Code);
}


Expand Down
13 changes: 7 additions & 6 deletions core/captcha/src/main/java/com/anji/captcha/util/ImageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.util.Base64Utils;
import org.springframework.util.FileCopyUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -101,8 +100,10 @@ public static String getImageToBase64Str(BufferedImage templateImage) {
e.printStackTrace();
}
byte[] bytes = baos.toByteArray();
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encodeBuffer(bytes).trim();

Base64.Encoder encoder = Base64.getEncoder();

return encoder.encodeToString(bytes).trim();
}

/**
Expand All @@ -113,8 +114,8 @@ public static String getImageToBase64Str(BufferedImage templateImage) {
*/
public static BufferedImage getBase64StrToImage(String base64String) {
try {
BASE64Decoder base64Decoder = new BASE64Decoder();
byte[] bytes = base64Decoder.decodeBuffer(base64String);
Base64.Decoder decoder = Base64.getDecoder();
byte[] bytes = decoder.decode(base64String);
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
return ImageIO.read(inputStream);
} catch (IOException e) {
Expand Down
3 changes: 2 additions & 1 deletion core/captcha/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
##支持项目路径,以classpath:开头,取resource目录下路径,例:classpath:images/pic-click
#captcha.captchaOriginalPath.pic-click=/app/product/dist/captchabg

#汉字统一使用Unicode,保证程序通过@value读取到是中文,可通过这个在线转换 https://tool.chinaz.com/tools/unicode.aspx 中文转Unicode
#如果使用properties格式配置文件,汉字统一使用Unicode,保证程序通过@value读取到是中文,可通过这个在线转换 https://tool.chinaz.com/tools/unicode.aspx 中文转Unicode
#如果使用yml格式配置文件,请直接写中文,不用转Unicode
#右下角水印文字(我的水印)
#captcha.water.mark=\u6211\u7684\u6c34\u5370
#右下角水印字体(宋体)
Expand Down
17 changes: 14 additions & 3 deletions view/html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
准备初始化的容器,以及id值

<div id="content"></div>
// mode="pop"模式配置点击
<button id="btn">点击出现验证码</button>

滑动式调用$('#content').slideVerify(option)初始化;
点选式调用$('#content').pointsVerify(option)初始化;
Expand All @@ -19,8 +21,9 @@

<script>
$('#content').slideVerify({
baseUrl:'https://mirror.anji-plus.com/captcha-api' //服务器请求地址, 默认地址为安吉服务器;
mode:'fixed', //展示模式
baseUrl:'https://mirror.anji-plus.com/captcha-api', //服务器请求地址, 默认地址为安吉服务器;
containerId:'btn',//pop模式 必填 被点击之后出现行为验证码的元素id
mode:'pop', //展示模式
imgSize : { //图片的大小对象,有默认值{ width: '310px',height: '155px'},可省略
width: '400px',
height: '200px',
Expand All @@ -29,6 +32,11 @@
width: '400px',
height: '40px',
},
beforeCheck:function(){ //检验参数合法性的函数 mode ="pop"有效
let flag = true;
//实现: 参数合法性的判断逻辑, 返回一个boolean值
return flag
},
ready : function() {}, //加载完毕的回调
success : function(params) { //成功的回调
// params为返回的二次验证参数 需要在接下来的实现逻辑回传服务器
Expand All @@ -46,13 +54,16 @@
| success(params) | funciton | 验证码匹配成功后的回调函数,params为返回需回传服务器的二次验证参数 |
| error | funciton | 验证码匹配失败后的回调函数 |
| ready | funciton | 验证码初始化成功的回调函数 |
| beforeCheck | funciton |mode="pop"模式有效, 调用验证码前检验参数合法性的函数,返回值为boolean值,默认返回ture |


### 3.验证码参数

| 参数 | 类型 | 说明 |
| ------------ | ------------ | ------------ |1
| ------------ | ------------ | ------------ |
| baseUrl | String | 请求后端的服务器地址,默认:'https://mirror.anji-plus.com/captcha-api' 安吉服务器地址 |
| mode | String | 验证码的显示方式,弹出式pop,固定fixed,默认:mode : ‘pop’ |
| containerId | String |mode="pop" 模式必填,被点击之后出现行为验证码的元素id |
| vSpace | String | 验证码图片和移动条容器的间隔,默认单位是px。如:间隔为5px,默认:vSpace:5 |
| explain | String | 滑动条内的提示,不设置默认是:'向右滑动完成验证' |
| imgSize | Object | 其中包含了width、height两个参数,分别代表图片的宽度和高度,如:{width:'400px',height:'200px'}
Expand Down
36 changes: 28 additions & 8 deletions view/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ <h3>点选弹出式(point-popup)</h3>
<script>
// 初始化验证码 嵌入式
$('#mpanel1').slideVerify({
baseUrl:'https://mirror.anji-plus.com/captcha-api', //服务器请求地址, 默认地址为安吉服务器;
mode:'fixed',
imgSize : { //图片的大小对象
width: '400px',
Expand All @@ -74,24 +75,42 @@ <h3>点选弹出式(point-popup)</h3>
},
success : function(params) { //成功的回调
// 返回的二次验证参数 合并到验证通过之后的逻辑 参数中回传服务器
console.log(params,"params");

},
error : function() { //失败的回调
}
});

// 初始化验证码 弹出式
$('#mpanel2').slideVerify({
mode:'pop',
baseUrl:'https://mirror.anji-plus.com/captcha-api', //服务器请求地址, 默认地址为安吉服务器;
mode:'pop', //展示模式
containerId:'btn',//pop模式 必填 被点击之后出现行为验证码的元素id
ready : function() { //加载完毕的回调
},
success : function(params) { //成功的回调
// 返回的二次验证参数 合并到验证通过之后的逻辑 参数中回传服务器
},
error : function() { //失败的回调
}
imgSize : { //图片的大小对象,有默认值{ width: '310px',height: '155px'},可省略
width: '400px',
height: '200px',
},
barSize:{ //下方滑块的大小对象,有默认值{ width: '310px',height: '50px'},可省略
width: '400px',
height: '40px',
},
beforeCheck:function(){ //检验参数合法性的函数 mode ="pop"有效
let flag = true;
//实现: 参数合法性的判断逻辑, 返回一个boolean值
return flag
},
ready : function() {}, //加载完毕的回调
success : function(params) { //成功的回调
// params为返回的二次验证参数 需要在接下来的实现逻辑回传服务器
例如: login($.extend({}, params))
},
error : function() {} //失败的回调
});

// 初始化验证码 嵌入式
$('#mpanel3').pointsVerify({
baseUrl:'https://mirror.anji-plus.com/captcha-api', //服务器请求地址, 默认地址为安吉服务器;
mode:'fixed',
imgSize : {
width: '500px',
Expand All @@ -108,6 +127,7 @@ <h3>点选弹出式(point-popup)</h3>
});
// 初始化验证码 弹出式
$('#mpanel4').pointsVerify({
baseUrl:'https://mirror.anji-plus.com/captcha-api', //服务器请求地址, 默认地址为安吉服务器;
containerId:'btn2', // pop模式 必填 被点击之后出现行为验证码的元素id
mode:'pop',
imgSize : { //图片的大小对象
Expand Down
Loading

0 comments on commit 0f626dc

Please sign in to comment.