merge
This commit is contained in:
@@ -8,9 +8,10 @@ import java.util.Map;
|
||||
* 说明: 公共数据类
|
||||
*/
|
||||
public class CommonDataUtil {
|
||||
private static Map<String, Object> token = new HashMap();
|
||||
private static Map<String, Object> token;
|
||||
|
||||
public CommonDataUtil() {
|
||||
private CommonDataUtil() {
|
||||
token=new HashMap<>();
|
||||
}
|
||||
|
||||
public static Object getToken(String key) {
|
||||
|
||||
@@ -15,8 +15,7 @@ import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* 说明: 创建验证码的servlet
|
||||
* 创建日期: 2016年8月29日 上午10:59:27
|
||||
* 作者: xiangwbd
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
public class CaptchaServlet extends HttpServlet {
|
||||
private static final long serialVersionUID = -8687266469702749102L;
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.util.Random;
|
||||
|
||||
/**
|
||||
* 说明:验证码工具类
|
||||
* 创建日期: 2016年8月29日 上午10:57:41
|
||||
* 作者: xiangwb
|
||||
*/
|
||||
public class CaptchaUtil {
|
||||
@@ -19,10 +18,10 @@ public class CaptchaUtil {
|
||||
private static final String FONT_NAME = "Fixedsys";
|
||||
private Random random = new Random();
|
||||
private static final int FONT_SIZE = 18;// 字体大小
|
||||
private static final int width = 80;// 图片宽
|
||||
private static final int height = 25;// 图片高
|
||||
private static final int lineNum = 50;// 干扰线数量
|
||||
private static final int strNum = 4;// 随机产生字符数量
|
||||
private static final int WIDTH = 80;// 图片宽
|
||||
private static final int HEIGHT = 25;// 图片高
|
||||
private static final int LINE_NUM = 50;// 干扰线数量
|
||||
private static final int STR_NUM = 4;// 随机产生字符数量
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,23 +29,23 @@ public class CaptchaUtil {
|
||||
*/
|
||||
public BufferedImage genRandomCodeImage(StringBuffer randomCode) {
|
||||
// BufferedImage类是具有缓冲区的Image类
|
||||
BufferedImage image = new BufferedImage(width, height,
|
||||
BufferedImage image = new BufferedImage(WIDTH, HEIGHT,
|
||||
BufferedImage.TYPE_INT_BGR);
|
||||
// 获取Graphics对象,便于对图像进行各种绘制操作
|
||||
Graphics g = image.getGraphics();
|
||||
// 设置背景色
|
||||
g.setColor(getRandColor(200, 250));
|
||||
// 填充矩形面积
|
||||
g.fillRect(0, 0, width, height);
|
||||
g.fillRect(0, 0, WIDTH, HEIGHT);
|
||||
// 设置干扰线的颜色
|
||||
g.setColor(getRandColor(110, 120));
|
||||
// 绘制干扰线
|
||||
for (int i = 0; i <= lineNum; i++) {
|
||||
for (int i = 0; i <= LINE_NUM; i++) {
|
||||
drowLine(g);
|
||||
}
|
||||
// 绘制随机字符
|
||||
g.setFont(new Font(FONT_NAME, Font.PLAIN, FONT_SIZE));
|
||||
for (int i = 1; i <= strNum; i++) {
|
||||
for (int i = 1; i <= STR_NUM; i++) {
|
||||
randomCode.append(drowString(g, i));
|
||||
}
|
||||
g.dispose();
|
||||
@@ -86,8 +85,8 @@ public class CaptchaUtil {
|
||||
* 绘制干扰线
|
||||
*/
|
||||
private void drowLine(Graphics g) {
|
||||
int x = random.nextInt(width);
|
||||
int y = random.nextInt(height);
|
||||
int x = random.nextInt(WIDTH);
|
||||
int y = random.nextInt(HEIGHT);
|
||||
int x0 = random.nextInt(16);
|
||||
int y0 = random.nextInt(16);
|
||||
g.drawLine(x, y, x + x0, y + y0);
|
||||
|
||||
Reference in New Issue
Block a user