-
大小: 12.08MB文件類型: .zip金幣: 1下載: 0 次發(fā)布日期: 2023-07-06
- 語(yǔ)言: 其他
- 標(biāo)簽: springboot??登陸??驗(yàn)證碼??maven??
資源簡(jiǎn)介
一步一步實(shí)現(xiàn)web程序信息管理系統(tǒng)之三----登陸業(yè)務(wù)邏輯實(shí)現(xiàn)(驗(yàn)證碼功能+參數(shù)獲取)
代碼片段和文件信息
package?springboot.study.common;
import?java.awt.Color;
import?java.awt.Font;
import?java.awt.Graphics;
import?java.awt.image.BufferedImage;
import?java.io.IOException;
import?java.io.OutputStream;
import?java.util.Random;
import?javax.imageio.ImageIO;
public?class?AuthImageCodeUtils?{
private?static?final?Color?Color?=?null;
private?static?char?mapTable[]?=?{?‘a(chǎn)‘?‘b‘?‘c‘?‘d‘?‘e‘?‘f‘?‘g‘?‘h‘?‘i‘?‘j‘?‘k‘?‘l‘?‘m‘?‘n‘?‘o‘?‘p‘?‘q‘
‘r‘?‘s‘?‘t‘?‘u‘?‘v‘?‘w‘?‘x‘?‘y‘?‘z‘?‘0‘?‘1‘?‘2‘?‘3‘?‘4‘?‘5‘?‘6‘?‘7‘?‘8‘?‘9‘?};
/**
?*?功能:生成彩色驗(yàn)證碼圖片?參數(shù)width為生成圖片的寬度參數(shù)height為生成圖片的高度參數(shù)os為頁(yè)面的輸出流
?*/
public?static?String?getCerPic(int?width?int?height?OutputStream?os)?{
if?(width?60)?{
width?=?60;
}
if?(height?<=?0)?{
height?=?20;
}
BufferedImage?image?=?new?BufferedImage(width?height?BufferedImage.TYPE_3BYTE_BGR);
//?獲取圖形上下文
Graphics?graphics?=?image.getGraphics();
//?設(shè)定背景顏色
graphics.setColor(new?Color(0xDCDCDC));
graphics.fillRect(0?0?width?height);
//?邊框
graphics.setColor(Color.black);
graphics.drawRect(0?0?width?-?1?height?-?1);
//?隨機(jī)產(chǎn)生驗(yàn)證碼
String?strEnsure?=?““;
//?4代表4位驗(yàn)證碼
for?(int?i?=?1;?i?<=?4;?i++)?{
strEnsure?+=?mapTable[(int)?(mapTable.length?*?Math.random())];
}
//?將圖形驗(yàn)證碼顯示在圖片中
graphics.setColor(Color.black);
graphics.setFont(new?Font(“Atlantic?Inline“?Font.PLAIN?20));
String?str?=?strEnsure.substring(0?1);
graphics.drawString(str?8?17);//?8:左右距離17:上下距離
str?=?strEnsure.substring(1?2);
graphics.drawString(str?20?15);
str?=?strEnsure.substring(2?3);
graphics.drawString(str?35?18);
str?=?strEnsure.substring(3?4);
graphics.drawString(str?45?15);
//?隨機(jī)產(chǎn)生10個(gè)干擾點(diǎn)
Random?random?=?new?Random();
for?(int?i?=?0;?i?<=?10;?i++)?{
int?x?=?random.nextInt(width);
int?y?=?random.nextInt(height);
graphics.drawOval(x?y?1?1);
}
//?釋放圖形上下文
graphics.dispose();
try?{
ImageIO.write(image?“JPEG“?os);
}?catch?(IOException?e)?{
e.printStackTrace();
return?““;
}
return?strEnsure;
}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-11-09?10:21??spring-boot-study\
?????文件?????????397??2018-11-08?10:57??spring-boot-study\.project
?????目錄???????????0??2018-11-08?10:57??spring-boot-study\.settings\
?????文件??????????90??2018-11-08?10:57??spring-boot-study\.settings\org.eclipse.m2e.core.prefs
?????文件?????????957??2018-11-09?10:21??spring-boot-study\pom.xm
?????目錄???????????0??2018-11-09?10:21??spring-boot-study\spring-boot-common\
?????文件????????1517??2018-11-09?10:21??spring-boot-study\spring-boot-common\.classpath
?????文件?????????570??2018-11-09?10:21??spring-boot-study\spring-boot-common\.project
?????目錄???????????0??2018-11-09?10:21??spring-boot-study\spring-boot-common\.settings\
?????文件?????????191??2018-11-09?10:21??spring-boot-study\spring-boot-common\.settings\org.eclipse.core.resources.prefs
?????文件?????????356??2018-11-09?10:21??spring-boot-study\spring-boot-common\.settings\org.eclipse.jdt.core.prefs
?????文件??????????90??2018-11-09?10:21??spring-boot-study\spring-boot-common\.settings\org.eclipse.m2e.core.prefs
?????文件?????????456??2018-11-09?10:21??spring-boot-study\spring-boot-common\pom.xm
?????目錄???????????0??2018-11-09?10:21??spring-boot-study\spring-boot-common\src\
?????目錄???????????0??2018-11-09?10:21??spring-boot-study\spring-boot-common\src\main\
?????目錄???????????0??2018-11-09?10:22??spring-boot-study\spring-boot-common\src\main\java\
?????目錄???????????0??2018-11-09?10:22??spring-boot-study\spring-boot-common\src\main\java\springboot\
?????目錄???????????0??2018-11-09?10:22??spring-boot-study\spring-boot-common\src\main\java\springboot\study\
?????目錄???????????0??2018-11-09?11:17??spring-boot-study\spring-boot-common\src\main\java\springboot\study\common\
?????文件????????2342??2018-11-09?10:23??spring-boot-study\spring-boot-common\src\main\java\springboot\study\common\AuthImageCodeUtils.java
?????文件????????1289??2018-11-09?11:13??spring-boot-study\spring-boot-common\src\main\java\springboot\study\common\JsonResult.java
?????文件?????????612??2018-11-09?11:19??spring-boot-study\spring-boot-common\src\main\java\springboot\study\common\LoginResult.java
?????目錄???????????0??2018-11-09?11:25??spring-boot-study\spring-boot-common\src\main\resources\
?????目錄???????????0??2018-11-09?10:21??spring-boot-study\spring-boot-common\src\test\
?????目錄???????????0??2018-11-09?11:25??spring-boot-study\spring-boot-common\src\test\java\
?????目錄???????????0??2018-11-09?11:25??spring-boot-study\spring-boot-common\src\test\resources\
?????目錄???????????0??2018-11-09?10:21??spring-boot-study\spring-boot-common\target\
?????目錄???????????0??2018-11-09?10:22??spring-boot-study\spring-boot-common\target\classes\
?????目錄???????????0??2018-11-09?10:21??spring-boot-study\spring-boot-common\target\classes\me
?????文件?????????372??2018-11-09?10:21??spring-boot-study\spring-boot-common\target\classes\me
?????目錄???????????0??2018-11-09?10:21??spring-boot-study\spring-boot-common\target\classes\me
............此處省略722個(gè)文件信息
評(píng)論
共有 條評(píng)論