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
a48d5905
Commit
a48d5905
authored
Feb 02, 2018
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成验证码重构,未联调
parent
e9a51fa7
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
99 additions
and
70 deletions
+99
-70
CaptchaNewValidateAdvisor.java
...tgroup/xyqb/aspect/captcha/CaptchaNewValidateAdvisor.java
+3
-2
NewCaptchaController.java
...yqb/controller/external/captcha/NewCaptchaController.java
+27
-20
ClientType.java
src/main/java/cn/quantgroup/xyqb/model/ClientType.java
+27
-0
GeetestLib.java
...n/java/cn/quantgroup/xyqb/service/captcha/GeetestLib.java
+10
-21
IGeetestCaptchaService.java
...antgroup/xyqb/service/captcha/IGeetestCaptchaService.java
+6
-2
IQuantgroupCaptchaService.java
...group/xyqb/service/captcha/IQuantgroupCaptchaService.java
+2
-2
GeetestCaptchaServiceImpl.java
.../xyqb/service/captcha/impl/GeetestCaptchaServiceImpl.java
+18
-16
QuantgroupCaptchaServiceImpl.java
...qb/service/captcha/impl/QuantgroupCaptchaServiceImpl.java
+6
-7
No files found.
src/main/java/cn/quantgroup/xyqb/aspect/captcha/CaptchaNewValidateAdvisor.java
View file @
a48d5905
package
cn
.
quantgroup
.
xyqb
.
aspect
.
captcha
;
package
cn
.
quantgroup
.
xyqb
.
aspect
.
captcha
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.model.ClientType
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService
;
import
cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService
;
import
cn.quantgroup.xyqb.service.captcha.IQuantgroupCaptchaService
;
import
cn.quantgroup.xyqb.service.captcha.IQuantgroupCaptchaService
;
...
@@ -78,7 +79,7 @@ public class CaptchaNewValidateAdvisor {
...
@@ -78,7 +79,7 @@ public class CaptchaNewValidateAdvisor {
String
phoneNo
=
request
.
getParameter
(
"phoneNo"
);
String
phoneNo
=
request
.
getParameter
(
"phoneNo"
);
String
clientType
=
request
.
getParameter
(
"clientType"
);
String
clientType
=
request
.
getParameter
(
"clientType"
);
log
.
info
(
"使用极验二次验证,phoneNo:{}"
,
phoneNo
);
log
.
info
(
"使用极验二次验证,phoneNo:{}"
,
phoneNo
);
return
geetestCaptchaService
.
isCaptchaValidateSuccess
(
clientType
,
PasswordUtil
.
MD5
(
phoneNo
),
IPUtil
.
getRemoteIP
(
request
),
challenge
,
validate
,
seccode
);
return
geetestCaptchaService
.
validGeetestCaptcha
(
ClientType
.
valueByName
(
clientType
)
,
PasswordUtil
.
MD5
(
phoneNo
),
IPUtil
.
getRemoteIP
(
request
),
challenge
,
validate
,
seccode
);
}
}
/**
/**
...
@@ -90,7 +91,7 @@ public class CaptchaNewValidateAdvisor {
...
@@ -90,7 +91,7 @@ public class CaptchaNewValidateAdvisor {
private
boolean
qgValid
(
HttpServletRequest
request
)
{
private
boolean
qgValid
(
HttpServletRequest
request
)
{
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"
);
return
quantgroupCaptchaService
.
validCaptcha
(
captchaId
,
captchaValue
);
return
quantgroupCaptchaService
.
valid
Quantgroup
Captcha
(
captchaId
,
captchaValue
);
}
}
}
}
src/main/java/cn/quantgroup/xyqb/controller/external/captcha/NewCaptchaController.java
View file @
a48d5905
package
cn
.
quantgroup
.
xyqb
.
controller
.
external
.
captcha
;
package
cn
.
quantgroup
.
xyqb
.
controller
.
external
.
captcha
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaNewValidator
;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaNewValidator
;
import
cn.quantgroup.xyqb.aspect.logcaller.LogHttpCaller
;
import
cn.quantgroup.xyqb.aspect.logcaller.LogHttpCaller
;
import
cn.quantgroup.xyqb.model.ClientType
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService
;
import
cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService
;
import
cn.quantgroup.xyqb.service.captcha.IQuantgroupCaptchaService
;
import
cn.quantgroup.xyqb.service.captcha.IQuantgroupCaptchaService
;
...
@@ -9,11 +11,16 @@ import cn.quantgroup.xyqb.util.IPUtil;
...
@@ -9,11 +11,16 @@ import cn.quantgroup.xyqb.util.IPUtil;
import
cn.quantgroup.xyqb.util.PasswordUtil
;
import
cn.quantgroup.xyqb.util.PasswordUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.json.JSONObject
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
/**
/**
* @author xufei on 2018/1/30.
* @author xufei on 2018/1/30.
...
@@ -22,35 +29,36 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -22,35 +29,36 @@ import javax.servlet.http.HttpServletRequest;
@RestController
@RestController
@RequestMapping
(
"/api"
)
@RequestMapping
(
"/api"
)
public
class
NewCaptchaController
{
public
class
NewCaptchaController
{
@Resource
@Resource
private
IGeetestCaptchaService
geetestCaptchaService
;
private
IGeetestCaptchaService
geetestCaptchaService
;
@Resource
@Resource
private
IQuantgroupCaptchaService
quantgroupCaptchaService
;
private
IQuantgroupCaptchaService
quantgroupCaptchaService
;
@LogHttpCaller
@LogHttpCaller
@RequestMapping
(
value
=
"/
newCaptcha
"
)
@RequestMapping
(
value
=
"/
captcha/new
"
)
public
JsonResult
getCaptcha
(
HttpServletRequest
request
,
String
phoneNo
)
{
public
JsonResult
getCaptcha
(
String
phoneNo
,
String
clientType
,
HttpServletRequest
request
)
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
log
.
info
(
"获取验证码失败,phoneNo:{}, clientType:{}"
,
phoneNo
,
clientType
);
return
JsonResult
.
buildErrorStateResult
(
"手机号格式错误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"手机号格式错误"
,
null
);
}
}
// 数据容器
log
.
info
(
"[newCaptcha]获取验证码,phoneNo:{}"
,
phoneNo
);
Map
<
String
,
String
>
data
=
new
HashMap
<
String
,
String
>();
String
geetestCaptcha
=
geetestCaptchaService
.
fetchGeetestCaptcha
(
PasswordUtil
.
MD5
(
phoneNo
),
// 优先获取极验
IPUtil
.
getRemoteIP
(
request
),
request
.
getParameter
(
"clientType"
));
Map
<
String
,
String
>
imgMap
=
geetestCaptchaService
.
fetchGeetestCaptcha
(
PasswordUtil
.
MD5
(
phoneNo
),
IPUtil
.
getRemoteIP
(
request
),
ClientType
.
valueByName
(
clientType
));
log
.
info
(
"结果geetestCaptcha:{},phoneNo:{}"
,
geetestCaptcha
,
phoneNo
);
data
.
put
(
Constants
.
TEST_PARAM
,
Constants
.
TEST_TYPE_GT
);
if
(
null
!=
geetestCaptcha
)
{
// 备选方案:量化派图形验证码
return
JsonResult
.
buildSuccessResult
(
""
,
geetestCaptcha
);
if
(
Objects
.
isNull
(
imgMap
)
||
imgMap
.
isEmpty
()){
}
else
{
imgMap
=
quantgroupCaptchaService
.
fetchQuantgroupCaptcha
(
request
.
getLocale
());
try
{
data
.
put
(
Constants
.
TEST_PARAM
,
Constants
.
TEST_TYPE_QG
);
return
JsonResult
.
buildSuccessResult
(
""
,
quantgroupCaptchaService
.
fetchCaptcha
(
request
.
getLocale
()));
}
catch
(
Exception
e
)
{
log
.
error
(
"获取验证码失败e:{}"
,
e
);
return
JsonResult
.
buildErrorStateResult
(
""
,
"fail"
);
}
}
}
// 返回结果
if
(
Objects
.
isNull
(
imgMap
)
||
imgMap
.
isEmpty
()){
return
JsonResult
.
buildErrorStateResult
(
"获取验证码失败"
,
""
);
}
// 填充数据并返回
data
.
putAll
(
imgMap
);
return
JsonResult
.
buildSuccessResult
(
""
,
data
);
}
}
@CaptchaNewValidator
@CaptchaNewValidator
...
@@ -59,5 +67,4 @@ public class NewCaptchaController {
...
@@ -59,5 +67,4 @@ public class NewCaptchaController {
return
JsonResult
.
buildSuccessResult
(
""
,
null
);
return
JsonResult
.
buildSuccessResult
(
""
,
null
);
}
}
}
}
src/main/java/cn/quantgroup/xyqb/model/ClientType.java
0 → 100644
View file @
a48d5905
package
cn
.
quantgroup
.
xyqb
.
model
;
import
java.util.Optional
;
/**
* 验证码验证类型
* @author renwc
* @date 2018-02-02
*/
public
enum
ClientType
{
WEB
,
APP
,
H5
;
public
final
static
ClientType
valueByName
(
String
name
)
{
name
=
Optional
.
ofNullable
(
name
).
orElse
(
""
).
toLowerCase
();
switch
(
name
){
case
"app"
:
return
APP
;
case
"h5"
:
return
H5
;
case
"web"
:
return
WEB
;
default
:
return
APP
;
}
}
}
src/main/java/cn/quantgroup/xyqb/service/captcha/GeetestLib.java
View file @
a48d5905
...
@@ -11,6 +11,7 @@ import java.net.URL;
...
@@ -11,6 +11,7 @@ import java.net.URL;
import
java.security.MessageDigest
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
/**
* Java SDK
* Java SDK
...
@@ -46,7 +47,7 @@ public class GeetestLib {
...
@@ -46,7 +47,7 @@ public class GeetestLib {
/**
/**
* 返回字符串
* 返回字符串
*/
*/
private
String
responseStr
;
private
Map
<
String
,
String
>
responseStr
;
/**
/**
* 调试开关,是否输出调试日志
* 调试开关,是否输出调试日志
...
@@ -73,7 +74,7 @@ public class GeetestLib {
...
@@ -73,7 +74,7 @@ public class GeetestLib {
*
*
* @return 初始化结果
* @return 初始化结果
*/
*/
public
String
getResponseStr
(
HashMap
<
String
,
String
>
param
)
{
public
Map
<
String
,
String
>
getResponseStr
(
HashMap
<
String
,
String
>
param
)
{
preProcess
(
param
);
preProcess
(
param
);
return
responseStr
;
return
responseStr
;
}
}
...
@@ -84,32 +85,20 @@ public class GeetestLib {
...
@@ -84,32 +85,20 @@ public class GeetestLib {
*
*
* @return
* @return
*/
*/
private
String
getFailPreProcessRes
()
{
private
Map
<
String
,
String
>
getFailPreProcessRes
()
{
return
null
;
return
null
;
}
}
/**
/**
* 预处理成功后的标准串
* 预处理成功后的标准串
*/
*/
private
String
getSuccessPreProcessRes
(
String
challenge
)
{
private
Map
<
String
,
String
>
getSuccessPreProcessRes
(
String
challenge
)
{
gtlog
(
"challenge:"
+
challenge
);
gtlog
(
"challenge:"
+
challenge
);
Map
<
String
,
String
>
data
=
new
HashMap
<
String
,
String
>(
3
);
JSONObject
jsonObject
=
new
JSONObject
();
data
.
put
(
"success"
,
"0"
);
try
{
data
.
put
(
"gt"
,
this
.
captchaId
);
data
.
put
(
"challenge"
,
challenge
);
jsonObject
.
put
(
"success"
,
"0"
);
return
data
;
jsonObject
.
put
(
"gt"
,
this
.
captchaId
);
jsonObject
.
put
(
"challenge"
,
challenge
);
}
catch
(
JSONException
e
)
{
gtlog
(
"json dumps error"
);
}
return
jsonObject
.
toString
();
}
}
/**
/**
...
...
src/main/java/cn/quantgroup/xyqb/service/captcha/IGeetestCaptchaService.java
View file @
a48d5905
package
cn
.
quantgroup
.
xyqb
.
service
.
captcha
;
package
cn
.
quantgroup
.
xyqb
.
service
.
captcha
;
import
cn.quantgroup.xyqb.model.ClientType
;
import
java.util.Map
;
/**
/**
* @author xufei on 2018/1/30.
* @author xufei on 2018/1/30.
*/
*/
...
@@ -13,7 +17,7 @@ public interface IGeetestCaptchaService {
...
@@ -13,7 +17,7 @@ public interface IGeetestCaptchaService {
* @param clientType
* @param clientType
* @return 获取失败返回null
* @return 获取失败返回null
*/
*/
String
fetchGeetestCaptcha
(
String
markStr
,
String
remoteIp
,
String
clientType
);
Map
<
String
,
String
>
fetchGeetestCaptcha
(
String
markStr
,
String
remoteIp
,
ClientType
clientType
);
/**
/**
...
@@ -27,6 +31,6 @@ public interface IGeetestCaptchaService {
...
@@ -27,6 +31,6 @@ public interface IGeetestCaptchaService {
* @param seccode
* @param seccode
* @return
* @return
*/
*/
Boolean
isCaptchaValidateSuccess
(
String
clientType
,
String
phoneNo
,
String
remoteIp
,
String
challenge
,
String
validate
,
String
seccode
);
boolean
validGeetestCaptcha
(
ClientType
clientType
,
String
phoneNo
,
String
remoteIp
,
String
challenge
,
String
validate
,
String
seccode
);
}
}
src/main/java/cn/quantgroup/xyqb/service/captcha/IQuantgroupCaptchaService.java
View file @
a48d5905
...
@@ -13,7 +13,7 @@ public interface IQuantgroupCaptchaService {
...
@@ -13,7 +13,7 @@ public interface IQuantgroupCaptchaService {
* @return
* @return
* @throws Exception EX
* @throws Exception EX
*/
*/
Map
<
String
,
String
>
fetchCaptcha
(
Locale
locale
);
Map
<
String
,
String
>
fetch
Quantgroup
Captcha
(
Locale
locale
);
/**
/**
* 校验QG验证码
* 校验QG验证码
...
@@ -21,5 +21,5 @@ public interface IQuantgroupCaptchaService {
...
@@ -21,5 +21,5 @@ public interface IQuantgroupCaptchaService {
* @param code
* @param code
* @return
* @return
*/
*/
boolean
validCaptcha
(
String
key
,
String
code
);
boolean
valid
Quantgroup
Captcha
(
String
key
,
String
code
);
}
}
src/main/java/cn/quantgroup/xyqb/service/captcha/impl/GeetestCaptchaServiceImpl.java
View file @
a48d5905
package
cn
.
quantgroup
.
xyqb
.
service
.
captcha
.
impl
;
package
cn
.
quantgroup
.
xyqb
.
service
.
captcha
.
impl
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.model.ClientType
;
import
cn.quantgroup.xyqb.service.captcha.GeetestLib
;
import
cn.quantgroup.xyqb.service.captcha.GeetestLib
;
import
cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService
;
import
cn.quantgroup.xyqb.service.captcha.IGeetestCaptchaService
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
...
@@ -11,6 +11,8 @@ import org.springframework.stereotype.Service;
...
@@ -11,6 +11,8 @@ import org.springframework.stereotype.Service;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
/**
/**
* @author xufei on 2018/1/30.
* @author xufei on 2018/1/30.
...
@@ -37,32 +39,32 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService {
...
@@ -37,32 +39,32 @@ public class GeetestCaptchaServiceImpl implements IGeetestCaptchaService {
@Value
(
"${geetest.api.url}"
)
@Value
(
"${geetest.api.url}"
)
private
String
apiUrl
;
private
String
apiUrl
;
private
GeetestLib
getGeetestSdk
()
{
@Override
return
new
GeetestLib
(
captchaId
,
privateKey
,
newFailback
,
apiUrl
);
public
Map
<
String
,
String
>
fetchGeetestCaptcha
(
String
markStr
,
String
remoteIp
,
ClientType
clientType
)
{
GeetestLib
gtSdk
=
new
GeetestLib
(
captchaId
,
privateKey
,
newFailback
,
apiUrl
);
HashMap
<
String
,
String
>
param
=
getParam
(
markStr
,
remoteIp
,
clientType
);
return
gtSdk
.
getResponseStr
(
param
);
}
}
@Override
@Override
public
String
fetchGeetestCaptcha
(
String
markStr
,
String
remoteIp
,
String
clientType
)
{
public
boolean
validGeetestCaptcha
(
ClientType
clientType
,
String
markStr
,
String
remoteIp
,
String
challenge
,
String
validate
,
String
seccode
)
{
GeetestLib
gtSdk
=
new
GeetestLib
(
captchaId
,
privateKey
,
newFailback
,
apiUrl
);
HashMap
<
String
,
String
>
param
=
getParam
(
markStr
,
remoteIp
,
clientType
);
HashMap
<
String
,
String
>
param
=
getParam
(
markStr
,
remoteIp
,
clientType
);
return
Constants
.
GT_CAPTCHA_VALIDATE_SUCCESS
==
getGeetestSdk
().
enhencedValidateRequest
(
challenge
,
validate
,
seccode
,
param
);
}
return
gtSdk
.
getResponseStr
(
param
);
private
GeetestLib
getGeetestSdk
()
{
return
new
GeetestLib
(
captchaId
,
privateKey
,
newFailback
,
apiUrl
);
}
}
private
HashMap
<
String
,
String
>
getParam
(
String
markStr
,
String
remoteIp
,
String
clientType
)
{
private
HashMap
<
String
,
String
>
getParam
(
String
markStr
,
String
remoteIp
,
ClientType
clientType
)
{
HashMap
<
String
,
String
>
param
=
new
HashMap
<>();
HashMap
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"user_id"
,
markStr
);
param
.
put
(
"user_id"
,
markStr
);
if
(
StringUtils
.
isBlank
(
clientType
))
{
if
(
Objects
.
isNull
(
clientType
))
{
param
.
put
(
"client_type"
,
"APP"
);
param
.
put
(
"client_type"
,
ClientType
.
APP
.
name
());
}
else
{
param
.
put
(
"client_type"
,
clientType
.
name
());
}
}
param
.
put
(
"client_type"
,
clientType
);
param
.
put
(
"ip_address"
,
remoteIp
);
param
.
put
(
"ip_address"
,
remoteIp
);
return
param
;
return
param
;
}
}
@Override
public
Boolean
isCaptchaValidateSuccess
(
String
clientType
,
String
markStr
,
String
remoteIp
,
String
challenge
,
String
validate
,
String
seccode
)
{
HashMap
<
String
,
String
>
param
=
getParam
(
markStr
,
remoteIp
,
clientType
);
return
Constants
.
GT_CAPTCHA_VALIDATE_SUCCESS
==
getGeetestSdk
().
enhencedValidateRequest
(
challenge
,
validate
,
seccode
,
param
);
}
}
}
src/main/java/cn/quantgroup/xyqb/service/captcha/impl/QuantgroupCaptchaServiceImpl.java
View file @
a48d5905
...
@@ -35,9 +35,7 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService {
...
@@ -35,9 +35,7 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService {
private
AbstractManageableImageCaptchaService
imageCaptchaService
;
private
AbstractManageableImageCaptchaService
imageCaptchaService
;
@Override
@Override
public
Map
<
String
,
String
>
fetchCaptcha
(
Locale
locale
)
{
public
Map
<
String
,
String
>
fetchQuantgroupCaptcha
(
Locale
locale
)
{
Map
<
String
,
String
>
data
=
new
HashMap
<>();
data
.
put
(
Constants
.
TEST_PARAM
,
Constants
.
TEST_TYPE_QG
);
String
imageId
=
UUID
.
randomUUID
().
toString
();
String
imageId
=
UUID
.
randomUUID
().
toString
();
BufferedImage
challenge
=
imageCaptchaService
.
getImageChallengeForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
imageId
,
locale
);
BufferedImage
challenge
=
imageCaptchaService
.
getImageChallengeForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
imageId
,
locale
);
ByteArrayOutputStream
jpegOutputStream
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
jpegOutputStream
=
new
ByteArrayOutputStream
();
...
@@ -45,21 +43,22 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService {
...
@@ -45,21 +43,22 @@ public class QuantgroupCaptchaServiceImpl implements IQuantgroupCaptchaService {
ImageIO
.
write
(
challenge
,
IMAGE_FORMAT_PNG
,
jpegOutputStream
);
ImageIO
.
write
(
challenge
,
IMAGE_FORMAT_PNG
,
jpegOutputStream
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
error
(
"生成QG图形验证码"
,
e
);
log
.
error
(
"生成QG图形验证码"
,
e
);
return
data
;
return
null
;
}
}
String
imageBase64
=
Base64
.
encodeBase64String
(
jpegOutputStream
.
toByteArray
());
String
imageBase64
=
Base64
.
encodeBase64String
(
jpegOutputStream
.
toByteArray
());
Map
<
String
,
String
>
data
=
new
HashMap
<
String
,
String
>(
2
);
data
.
put
(
"imageId"
,
imageId
);
data
.
put
(
"imageId"
,
imageId
);
data
.
put
(
"image"
,
String
.
format
(
IMG_BASE64_PATTREN
,
imageBase64
));
data
.
put
(
"image"
,
String
.
format
(
IMG_BASE64_PATTREN
,
imageBase64
));
return
data
;
return
data
;
}
}
@Override
@Override
public
boolean
validCaptcha
(
String
key
,
String
code
)
{
public
boolean
valid
Quantgroup
Captcha
(
String
key
,
String
code
)
{
B
oolean
validCaptcha
=
false
;
b
oolean
validCaptcha
=
false
;
if
(
StringUtils
.
isNotBlank
(
key
)
&&
StringUtils
.
isNotBlank
(
code
))
{
if
(
StringUtils
.
isNotBlank
(
key
)
&&
StringUtils
.
isNotBlank
(
code
))
{
// 验证码校验(忽略用户输入的大小写)
// 验证码校验(忽略用户输入的大小写)
try
{
try
{
validCaptcha
=
imageCaptchaService
.
validateResponseForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
key
,
code
.
toLowerCase
(
));
validCaptcha
=
Boolean
.
valueOf
(
imageCaptchaService
.
validateResponseForID
(
Constants
.
IMAGE_CAPTCHA_KEY
+
key
,
code
.
toLowerCase
()
));
}
catch
(
CaptchaServiceException
e
)
{
}
catch
(
CaptchaServiceException
e
)
{
log
.
error
(
"校验QG图形验证码:key:{}, code:{}"
,
key
,
code
,
e
);
log
.
error
(
"校验QG图形验证码:key:{}, code:{}"
,
key
,
code
,
e
);
}
}
...
...
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