Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
xiaolang
/
expert
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6b477c9b
authored
Mar 23, 2020
by
xiaolang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图形验证码
parent
7ab2c292
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
119 additions
and
0 deletions
+119
-0
pom.xml
+6
-0
src/main/java/com/asset/controller/CaptchaController.java
+41
-0
src/main/java/com/asset/domain/system/Captcha.java
+24
-0
src/main/java/com/asset/mapper/system/CaptchaMapper.java
+9
-0
src/main/java/com/asset/service/impl/system/CaptchaServiceImpl.java
+19
-0
src/main/java/com/asset/service/system/CaptchaService.java
+12
-0
src/main/resources/mybatis/mapper/CaptchaMapper.xml
+8
-0
No files found.
pom.xml
View file @
6b477c9b
...
...
@@ -102,6 +102,12 @@
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
</dependency>
<!-- 验证码 -->
<dependency>
<groupId>
com.github.whvcse
</groupId>
<artifactId>
easy-captcha
</artifactId>
<version>
1.6.2
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/asset/controller/CaptchaController.java
0 → 100644
View file @
6b477c9b
package
com
.
asset
.
controller
;
import
com.asset.common.Common
;
import
com.asset.common.ResultUtil
;
import
com.asset.domain.Result
;
import
com.asset.domain.system.Captcha
;
import
com.asset.enums.CodeEnum
;
import
com.asset.service.system.CaptchaService
;
import
com.wf.captcha.SpecCaptcha
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.UUID
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/*
* @author xiaol
* @date 2020/3/23
*/
@RestController
@RequestMapping
(
value
=
"/captcha"
)
public
class
CaptchaController
{
@Autowired
CaptchaService
captchaService
;
@RequestMapping
(
"/captcha"
)
public
Result
captcha
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
Exception
{
SpecCaptcha
specCaptcha
=
new
SpecCaptcha
(
130
,
48
,
5
);
String
verCode
=
specCaptcha
.
text
().
toLowerCase
();
String
key
=
UUID
.
randomUUID
().
toString
();
// 存入表并设置过期时间为2分钟
Captcha
cap
=
new
Captcha
();
cap
.
setCaptcha_key
(
key
);
cap
.
setCaptcha_value
(
specCaptcha
.
toBase64
());
String
ex
=
Common
.
getDateToString
(
Common
.
getTime
()
+
120
);
cap
.
setExpire
(
ex
);
return
ResultUtil
.
success
(
CodeEnum
.
SUCCESS
,
cap
);
}
}
src/main/java/com/asset/domain/system/Captcha.java
0 → 100644
View file @
6b477c9b
package
com
.
asset
.
domain
.
system
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.ToString
;
import
lombok.experimental.Accessors
;
@Data
@EqualsAndHashCode
(
callSuper
=
false
)
@Accessors
(
chain
=
true
)
@TableName
(
"ex_captcha"
)
@ToString
public
class
Captcha
{
private
Integer
id
;
private
String
captcha_key
;
private
String
captcha_value
;
private
String
expire
;
}
src/main/java/com/asset/mapper/system/CaptchaMapper.java
0 → 100644
View file @
6b477c9b
package
com
.
asset
.
mapper
.
system
;
import
com.asset.domain.system.Captcha
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
public
interface
CaptchaMapper
extends
BaseMapper
<
Captcha
>
{
}
src/main/java/com/asset/service/impl/system/CaptchaServiceImpl.java
0 → 100644
View file @
6b477c9b
package
com
.
asset
.
service
.
impl
.
system
;
import
com.asset.domain.system.Captcha
;
import
com.asset.mapper.system.CaptchaMapper
;
import
com.asset.service.system.CaptchaService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
/*
* @author xiaol
* @date 2020/03/23
*/
@Service
@Transactional
public
class
CaptchaServiceImpl
extends
ServiceImpl
<
CaptchaMapper
,
Captcha
>
implements
CaptchaService
{
}
src/main/java/com/asset/service/system/CaptchaService.java
0 → 100644
View file @
6b477c9b
package
com
.
asset
.
service
.
system
;
import
com.asset.domain.system.Captcha
;
import
com.baomidou.mybatisplus.extension.service.IService
;
/*
* @author xiaol
* @date 2020/03/23
*/
public
interface
CaptchaService
extends
IService
<
Captcha
>
{
}
src/main/resources/mybatis/mapper/CaptchaMapper.xml
0 → 100644
View file @
6b477c9b
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.asset.mapper.system.CaptchaMapper"
>
</mapper>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment