Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
head_group
xyqb-user2
Commits
db6c31d5
Commit
db6c31d5
authored
Feb 06, 2018
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
补充
parent
dd883009
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
64 deletions
+29
-64
CaptchaNewValidateAdvisor.java
...tgroup/xyqb/aspect/captcha/CaptchaNewValidateAdvisor.java
+5
-3
ImageCaptchaController.java
...b/controller/external/captcha/ImageCaptchaController.java
+6
-47
NewCaptchaController.java
...yqb/controller/external/captcha/NewCaptchaController.java
+3
-8
ClientType.java
src/main/java/cn/quantgroup/xyqb/model/ClientType.java
+10
-1
GeetestCaptchaServiceImpl.java
.../xyqb/service/captcha/impl/GeetestCaptchaServiceImpl.java
+2
-2
GeetestCaptchaServiceTest.java
src/test/java/service/GeetestCaptchaServiceTest.java
+3
-3
No files found.
src/main/java/cn/quantgroup/xyqb/aspect/captcha/CaptchaNewValidateAdvisor.java
View file @
db6c31d5
...
@@ -73,12 +73,12 @@ public class CaptchaNewValidateAdvisor {
...
@@ -73,12 +73,12 @@ public class CaptchaNewValidateAdvisor {
* @throws Throwable
* @throws Throwable
*/
*/
private
boolean
gtValid
(
HttpServletRequest
request
)
{
private
boolean
gtValid
(
HttpServletRequest
request
)
{
String
phoneNo
=
request
.
getParameter
(
"phoneNo"
);
String
clientType
=
request
.
getParameter
(
"clientType"
);
String
challenge
=
request
.
getParameter
(
Constants
.
FN_GEETEST_CHALLENGE
);
String
challenge
=
request
.
getParameter
(
Constants
.
FN_GEETEST_CHALLENGE
);
String
validate
=
request
.
getParameter
(
Constants
.
FN_GEETEST_VALIDATE
);
String
validate
=
request
.
getParameter
(
Constants
.
FN_GEETEST_VALIDATE
);
String
seccode
=
request
.
getParameter
(
Constants
.
FN_GEETEST_SECCODE
);
String
seccode
=
request
.
getParameter
(
Constants
.
FN_GEETEST_SECCODE
);
String
phoneNo
=
request
.
getParameter
(
"phoneNo"
);
log
.
info
(
"Geetest - 极验二次校验, phoneNo:{}, clientType:{}, ip:{}, challenge:{}, validate:{}, seccode:{}"
,
phoneNo
,
clientType
,
IPUtil
.
getRemoteIP
(
request
),
challenge
,
validate
,
seccode
);
String
clientType
=
request
.
getParameter
(
"clientType"
);
log
.
info
(
"使用极验二次验证,phoneNo:{}, clientType:{}, challenge:{}, validate:{}, seccode:{}"
,
phoneNo
,
clientType
,
challenge
,
validate
,
seccode
);
return
geetestCaptchaService
.
validGeetestCaptcha
(
PasswordUtil
.
MD5
(
phoneNo
),
IPUtil
.
getRemoteIP
(
request
),
ClientType
.
valueByName
(
clientType
),
challenge
,
validate
,
seccode
);
return
geetestCaptchaService
.
validGeetestCaptcha
(
PasswordUtil
.
MD5
(
phoneNo
),
IPUtil
.
getRemoteIP
(
request
),
ClientType
.
valueByName
(
clientType
),
challenge
,
validate
,
seccode
);
}
}
...
@@ -89,8 +89,10 @@ public class CaptchaNewValidateAdvisor {
...
@@ -89,8 +89,10 @@ public class CaptchaNewValidateAdvisor {
* @throws Throwable
* @throws Throwable
*/
*/
private
boolean
qgValid
(
HttpServletRequest
request
)
{
private
boolean
qgValid
(
HttpServletRequest
request
)
{
String
phoneNo
=
request
.
getParameter
(
"phoneNo"
);
String
captchaId
=
Optional
.
ofNullable
(
request
.
getParameter
(
"captchaId"
)).
orElse
(
""
);
String
captchaId
=
Optional
.
ofNullable
(
request
.
getParameter
(
"captchaId"
)).
orElse
(
""
);
String
captchaValue
=
request
.
getParameter
(
"captchaValue"
);
String
captchaValue
=
request
.
getParameter
(
"captchaValue"
);
log
.
info
(
"Quantgroup - 图形验证码校验, phoneNo:{}, ip:{}, captchaId:{}, captchaValue:{}"
,
phoneNo
,
IPUtil
.
getRemoteIP
(
request
),
captchaId
,
captchaValue
);
return
quantgroupCaptchaService
.
validQuantgroupCaptcha
(
captchaId
,
captchaValue
);
return
quantgroupCaptchaService
.
validQuantgroupCaptcha
(
captchaId
,
captchaValue
);
}
}
...
...
src/main/java/cn/quantgroup/xyqb/controller/external/captcha/ImageCaptchaController.java
View file @
db6c31d5
package
cn
.
quantgroup
.
xyqb
.
controller
.
external
.
captcha
;
package
cn
.
quantgroup
.
xyqb
.
controller
.
external
.
captcha
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator
;
import
cn.quantgroup.xyqb.controller.IBaseController
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService
;
import
cn.quantgroup.xyqb.thirdparty.jcaptcha.AbstractManageableImageCaptchaService
;
import
com.octo.captcha.service.CaptchaServiceException
;
import
java.util.*
;
import
java.nio.charset.Charset
;
import
java.util.Optional
;
import
java.util.concurrent.TimeUnit
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageIO
;
...
@@ -27,9 +16,6 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -27,9 +16,6 @@ import javax.servlet.http.HttpServletRequest;
import
java.awt.image.BufferedImage
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.UUID
;
/**
/**
* 类名称:ImgCaptchaController
* 类名称:ImgCaptchaController
...
@@ -40,41 +26,21 @@ import java.util.UUID;
...
@@ -40,41 +26,21 @@ import java.util.UUID;
*/
*/
@RestController
@RestController
@RequestMapping
(
"/api"
)
@RequestMapping
(
"/api"
)
public
class
ImageCaptchaController
implements
IBaseController
{
public
class
ImageCaptchaController
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ImageCaptchaController
.
class
);
private
static
final
String
SUPER_CAPTCHA_ID
=
UUID
.
nameUUIDFromBytes
(
"__QG_APPCLIENT_AGENT__"
.
getBytes
(
Charset
.
forName
(
"UTF-8"
))).
toString
();
private
static
final
String
SUPER_CAPTCHA
=
"__SUPERQG__"
;
private
static
final
String
IMAGE_FORMAT_PNG
=
"png"
;
private
static
final
String
IMAGE_FORMAT_PNG
=
"png"
;
private
static
final
String
IMG_BASE64_PATTREN
=
"data:image/"
+
IMAGE_FORMAT_PNG
+
";base64,%s"
;
private
static
final
String
IMG_BASE64_PATTREN
=
"data:image/"
+
IMAGE_FORMAT_PNG
+
";base64,%s"
;
private
static
final
String
IMAGE_IP_COUNT
=
"image:ip"
;
private
static
final
String
IMAGE_PHONE_COUNT
=
"image:phone"
;
private
static
final
Long
FIVE_MIN
=
24
*
5L
;
@Autowired
@Autowired
@Qualifier
(
"customCaptchaService"
)
@Qualifier
(
"customCaptchaService"
)
private
AbstractManageableImageCaptchaService
imageCaptchaService
;
private
AbstractManageableImageCaptchaService
imageCaptchaService
;
@Autowired
@Qualifier
(
"stringRedisTemplate"
)
private
RedisTemplate
<
String
,
String
>
redisTemplate
;
@ModelAttribute
(
"clientIp"
)
public
String
initClientIp
()
{
return
getIp
();
}
/**
* 自动化测试忽略验证码
*/
@Value
(
"${xyqb.auth.captcha.autotest.enable:false}"
)
private
boolean
autoTestCaptchaEnabled
;
/**
/**
* 获取验证码
* 获取验证码
* 默认匹配 GET /captcha, 提供4位数字和字母混合图片验证码
* 默认匹配 GET /captcha, 提供4位数字和字母混合图片验证码
*/
*/
@RequestMapping
(
value
=
"/captcha"
)
@RequestMapping
(
value
=
"/captcha"
)
public
JsonResult
fetchCaptcha
(
HttpServletRequest
request
,
@ModelAttribute
(
"clientIp"
)
String
clientIp
)
{
public
JsonResult
fetchCaptcha
(
HttpServletRequest
request
)
{
String
imageId
=
UUID
.
randomUUID
().
toString
();
String
imageId
=
UUID
.
randomUUID
().
toString
();
BufferedImage
challenge
=
imageCaptchaService
.
getImageChallengeForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
imageId
,
request
.
getLocale
());
BufferedImage
challenge
=
imageCaptchaService
.
getImageChallengeForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
imageId
,
request
.
getLocale
());
ByteArrayOutputStream
jpegOutputStream
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
jpegOutputStream
=
new
ByteArrayOutputStream
();
...
@@ -92,12 +58,5 @@ public class ImageCaptchaController implements IBaseController {
...
@@ -92,12 +58,5 @@ public class ImageCaptchaController implements IBaseController {
data
.
put
(
"image"
,
String
.
format
(
IMG_BASE64_PATTREN
,
imageBase64
));
data
.
put
(
"image"
,
String
.
format
(
IMG_BASE64_PATTREN
,
imageBase64
));
return
JsonResult
.
buildSuccessResult
(
""
,
data
);
return
JsonResult
.
buildSuccessResult
(
""
,
data
);
}
}
/**
* 图片验证码验证
*/
@CaptchaValidator
@RequestMapping
(
"/verification_image_code"
)
public
JsonResult
verificationImageCode
()
{
return
JsonResult
.
buildSuccessResult
(
""
,
null
);
}
}
}
src/main/java/cn/quantgroup/xyqb/controller/external/captcha/NewCaptchaController.java
View file @
db6c31d5
...
@@ -36,14 +36,15 @@ public class NewCaptchaController {
...
@@ -36,14 +36,15 @@ public class NewCaptchaController {
@LogHttpCaller
@LogHttpCaller
@RequestMapping
(
value
=
"/captcha/new"
)
@RequestMapping
(
value
=
"/captcha/new"
)
public
JsonResult
getCaptcha
(
String
phoneNo
,
String
clientType
,
HttpServletRequest
request
)
{
public
JsonResult
getCaptcha
(
String
phoneNo
,
String
clientType
,
HttpServletRequest
request
)
{
String
remoteIp
=
IPUtil
.
getRemoteIP
(
request
);
log
.
info
(
"获取验证码, phoneNo:{}, clientType:{}, ip:{}"
,
phoneNo
,
clientType
,
remoteIp
);
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
log
.
info
(
"获取验证码失败,phoneNo:{}, clientType:{}"
,
phoneNo
,
clientType
);
return
JsonResult
.
buildErrorStateResult
(
"手机号格式错误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"手机号格式错误"
,
null
);
}
}
// 数据容器
// 数据容器
Map
<
String
,
String
>
data
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
data
=
new
HashMap
<
String
,
String
>();
// 优先获取极验
// 优先获取极验
Map
<
String
,
String
>
imgMap
=
geetestCaptchaService
.
fetchGeetestCaptcha
(
PasswordUtil
.
MD5
(
phoneNo
),
IPUtil
.
getRemoteIP
(
request
)
,
ClientType
.
valueByName
(
clientType
));
Map
<
String
,
String
>
imgMap
=
geetestCaptchaService
.
fetchGeetestCaptcha
(
PasswordUtil
.
MD5
(
phoneNo
),
remoteIp
,
ClientType
.
valueByName
(
clientType
));
data
.
put
(
Constants
.
VERIFY_PARAM
,
Constants
.
VERIFY_TYPE_GT
);
data
.
put
(
Constants
.
VERIFY_PARAM
,
Constants
.
VERIFY_TYPE_GT
);
// 备选方案:量化派图形验证码
// 备选方案:量化派图形验证码
if
(
Objects
.
isNull
(
imgMap
)
||
imgMap
.
isEmpty
()){
if
(
Objects
.
isNull
(
imgMap
)
||
imgMap
.
isEmpty
()){
...
@@ -59,10 +60,4 @@ public class NewCaptchaController {
...
@@ -59,10 +60,4 @@ public class NewCaptchaController {
return
JsonResult
.
buildSuccessResult
(
""
,
data
);
return
JsonResult
.
buildSuccessResult
(
""
,
data
);
}
}
@CaptchaNewValidator
@RequestMapping
(
"/new_verification_image_code"
)
public
JsonResult
verificationImageCode
()
{
return
JsonResult
.
buildSuccessResult
(
""
,
null
);
}
}
}
src/main/java/cn/quantgroup/xyqb/model/ClientType.java
View file @
db6c31d5
...
@@ -8,12 +8,21 @@ import java.util.Optional;
...
@@ -8,12 +8,21 @@ import java.util.Optional;
* @date 2018-02-02
* @date 2018-02-02
*/
*/
public
enum
ClientType
{
public
enum
ClientType
{
WEB
,
APP
,
H5
;
APP
(
"native"
),
H5
(
"h5"
),
WEB
(
"web"
);
ClientType
(
String
alias
){
this
.
alias
=
alias
;
}
private
String
alias
;
public
String
getAlias
(){
return
this
.
alias
;
}
public
final
static
ClientType
valueByName
(
String
name
)
{
public
final
static
ClientType
valueByName
(
String
name
)
{
name
=
Optional
.
ofNullable
(
name
).
orElse
(
""
).
toLowerCase
();
name
=
Optional
.
ofNullable
(
name
).
orElse
(
""
).
toLowerCase
();
switch
(
name
){
switch
(
name
){
case
"app"
:
case
"app"
:
case
"native"
:
return
APP
;
return
APP
;
case
"h5"
:
case
"h5"
:
return
H5
;
return
H5
;
...
...
src/main/java/cn/quantgroup/xyqb/service/captcha/impl/GeetestCaptchaServiceImpl.java
View file @
db6c31d5
...
@@ -60,9 +60,9 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService {
...
@@ -60,9 +60,9 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService {
HashMap
<
String
,
String
>
param
=
new
HashMap
<>();
HashMap
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"user_id"
,
markId
);
param
.
put
(
"user_id"
,
markId
);
if
(
Objects
.
isNull
(
clientType
))
{
if
(
Objects
.
isNull
(
clientType
))
{
param
.
put
(
"client_type"
,
ClientType
.
APP
.
name
().
toLowerCase
());
param
.
put
(
"client_type"
,
ClientType
.
APP
.
getAlias
());
}
else
{
}
else
{
param
.
put
(
"client_type"
,
clientType
.
name
().
toLowerCase
());
param
.
put
(
"client_type"
,
clientType
.
getAlias
());
}
}
param
.
put
(
"ip_address"
,
remoteIp
);
param
.
put
(
"ip_address"
,
remoteIp
);
return
param
;
return
param
;
...
...
src/test/java/service/GeetestCaptchaServiceTest.java
View file @
db6c31d5
...
@@ -38,9 +38,9 @@ public class GeetestCaptchaServiceTest {
...
@@ -38,9 +38,9 @@ public class GeetestCaptchaServiceTest {
@Test
@Test
public
void
testValidGeetestCaptcha
(){
public
void
testValidGeetestCaptcha
(){
String
challenge
=
"
c5372e93d6496f7bl096b7cl4fd6732c7
6"
;
String
challenge
=
"
86664ca9f3feba52c1d070343a9d10c
6"
;
String
validate
=
"
ba4df3e99129cal4893accb29b46bf8e
"
;
String
validate
=
"
9b80dd76a43e2608e54da9b865733b8c
"
;
String
seccode
=
"
ba4df3e99129cal4893accb29b46bf8e
|jordan"
;
String
seccode
=
"
9b80dd76a43e2608e54da9b865733b8c
|jordan"
;
Assert
.
assertTrue
(
geetestCaptchaService
.
validGeetestCaptcha
(
PasswordUtil
.
MD5
(
phoneNo
),
remoteIp
,
clientType
,
challenge
,
validate
,
seccode
));
Assert
.
assertTrue
(
geetestCaptchaService
.
validGeetestCaptcha
(
PasswordUtil
.
MD5
(
phoneNo
),
remoteIp
,
clientType
,
challenge
,
validate
,
seccode
));
}
}
}
}
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