Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
youjj
cloud-platform
Commits
d0409377
Commit
d0409377
authored
Dec 20, 2019
by
jiaorz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
验证码图片问题
parent
41c39b6e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
15 deletions
+88
-15
RedisKey.java
.../com/github/wxiaoqi/security/admin/constant/RedisKey.java
+6
-0
AppUserRest.java
...va/com/github/wxiaoqi/security/admin/rpc/AppUserRest.java
+2
-3
AppPermissionService.java
...aoqi/security/admin/rpc/service/AppPermissionService.java
+6
-2
RedisKey.java
...n/java/com/xxfc/platform/universal/constant/RedisKey.java
+3
-0
VerifyDto.java
.../main/java/com/xxfc/platform/universal/dto/VerifyDto.java
+11
-0
ThirdFeign.java
...in/java/com/xxfc/platform/universal/feign/ThirdFeign.java
+3
-0
CaptchaController.java
...xxfc/platform/universal/controller/CaptchaController.java
+48
-3
ClickWordCaptcha.java
...com/xxfc/platform/universal/service/ClickWordCaptcha.java
+9
-7
No files found.
ace-modules/ace-admin-api/src/main/java/com/github/wxiaoqi/security/admin/constant/RedisKey.java
View file @
d0409377
...
@@ -7,4 +7,10 @@ public class RedisKey {
...
@@ -7,4 +7,10 @@ public class RedisKey {
*/
*/
public
static
final
String
CONSTANT_CODE_PREFIX
=
"cache:mobilecode:"
;
public
static
final
String
CONSTANT_CODE_PREFIX
=
"cache:mobilecode:"
;
/**
* 图片验证码
*/
public
static
final
String
CAPTCHA_PHONE_PREFIX
=
"captcha:phone:"
;
}
}
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/rpc/AppUserRest.java
View file @
d0409377
...
@@ -8,7 +8,6 @@ import com.github.wxiaoqi.security.admin.rpc.service.AppPermissionService;
...
@@ -8,7 +8,6 @@ import com.github.wxiaoqi.security.admin.rpc.service.AppPermissionService;
import
com.github.wxiaoqi.security.admin.vo.ImiVo
;
import
com.github.wxiaoqi.security.admin.vo.ImiVo
;
import
com.github.wxiaoqi.security.api.vo.authority.PermissionInfo
;
import
com.github.wxiaoqi.security.api.vo.authority.PermissionInfo
;
import
com.github.wxiaoqi.security.api.vo.user.AppUserInfo
;
import
com.github.wxiaoqi.security.api.vo.user.AppUserInfo
;
import
com.github.wxiaoqi.security.auth.client.annotation.IgnoreUserToken
;
import
com.github.wxiaoqi.security.auth.client.config.UserAuthConfig
;
import
com.github.wxiaoqi.security.auth.client.config.UserAuthConfig
;
import
com.github.wxiaoqi.security.auth.client.jwt.UserAuthUtil
;
import
com.github.wxiaoqi.security.auth.client.jwt.UserAuthUtil
;
import
com.github.wxiaoqi.security.auth.common.util.jwt.IJWTInfo
;
import
com.github.wxiaoqi.security.auth.common.util.jwt.IJWTInfo
;
...
@@ -72,8 +71,8 @@ public class AppUserRest {
...
@@ -72,8 +71,8 @@ public class AppUserRest {
*/
*/
@RequestMapping
(
value
=
"/user/sendsms"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/user/sendsms"
,
method
=
RequestMethod
.
POST
)
public
@ResponseBody
public
@ResponseBody
JSONObject
sendsms
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"0"
)
Integer
type
){
JSONObject
sendsms
(
@RequestParam
(
value
=
"username"
,
defaultValue
=
""
)
String
username
,
@RequestParam
(
value
=
"type"
,
defaultValue
=
"0"
)
Integer
type
,
String
pointList
){
return
appPermissionService
.
sendSMS
(
username
,
type
);
return
appPermissionService
.
sendSMS
(
username
,
type
,
pointList
);
}
}
/**
/**
...
...
ace-modules/ace-admin/src/main/java/com/github/wxiaoqi/security/admin/rpc/service/AppPermissionService.java
View file @
d0409377
...
@@ -160,7 +160,7 @@ public class AppPermissionService {
...
@@ -160,7 +160,7 @@ public class AppPermissionService {
* @return phone手机号 type:类型(0用户注册,1微信绑定,2人脸注册,3忘记密码,4直接发送验证码) 改写发送验证码方法(暂时通过测试)
* @return phone手机号 type:类型(0用户注册,1微信绑定,2人脸注册,3忘记密码,4直接发送验证码) 改写发送验证码方法(暂时通过测试)
*/
*/
public
JSONObject
sendSMS
(
String
phone
,
Integer
type
)
{
public
JSONObject
sendSMS
(
String
phone
,
Integer
type
,
String
pointList
)
{
if
(
StringUtils
.
isBlank
(
phone
)
||
type
==
null
)
{
if
(
StringUtils
.
isBlank
(
phone
)
||
type
==
null
)
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
NULL_CODE
,
"参数为空"
);
}
}
...
@@ -170,11 +170,15 @@ public class AppPermissionService {
...
@@ -170,11 +170,15 @@ public class AppPermissionService {
}
}
// 组织返回结果集
// 组织返回结果集
JSONObject
result
=
new
JSONObject
();
JSONObject
result
=
new
JSONObject
();
if
(
type
==
0
)
{
if
(
type
==
0
)
{
// 注册验证码
AppUserLogin
rsUserLogin
=
appUserLoginBiz
.
checkeUserLogin
(
phone
);
AppUserLogin
rsUserLogin
=
appUserLoginBiz
.
checkeUserLogin
(
phone
);
if
(
rsUserLogin
!=
null
)
{
if
(
rsUserLogin
!=
null
)
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXIST_CODE
,
"用户已存在"
);
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
EXIST_CODE
,
"用户已存在"
);
}
}
ObjectRestResponse
<
Boolean
>
objectRestResponse
=
thirdFeign
.
verify
(
phone
,
pointList
);
if
(
objectRestResponse
.
getData
()
==
null
||
objectRestResponse
.
getData
()
==
false
)
{
return
JsonResultUtil
.
createFailedResult
(
ResultCode
.
FAILED_CODE
,
"图片验证码验证失败"
);
}
}
else
if
(
type
==
1
)
{
}
else
if
(
type
==
1
)
{
AppUserLogin
rsUserLogin
=
appUserLoginBiz
.
checkeUserLogin
(
phone
);
AppUserLogin
rsUserLogin
=
appUserLoginBiz
.
checkeUserLogin
(
phone
);
...
...
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/constant/RedisKey.java
View file @
d0409377
...
@@ -103,4 +103,7 @@ public class RedisKey {
...
@@ -103,4 +103,7 @@ public class RedisKey {
* 服务器上传压缩包文件序号
* 服务器上传压缩包文件序号
*/
*/
public
static
final
String
UPLOAD_ZIP_NO_PREFIX
=
"upload:zip:no:"
;
public
static
final
String
UPLOAD_ZIP_NO_PREFIX
=
"upload:zip:no:"
;
public
static
final
String
CAPTCHA_PHONE_PREFIX
=
"captcha:phone:"
;
}
}
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/dto/VerifyDto.java
0 → 100644
View file @
d0409377
package
com
.
xxfc
.
platform
.
universal
.
dto
;
import
lombok.Data
;
@Data
public
class
VerifyDto
{
String
list
;
String
pointList
;
}
\ No newline at end of file
xx-universal/xx-universal-api/src/main/java/com/xxfc/platform/universal/feign/ThirdFeign.java
View file @
d0409377
...
@@ -90,4 +90,7 @@ public interface ThirdFeign {
...
@@ -90,4 +90,7 @@ public interface ThirdFeign {
@GetMapping
(
"/info/app/unauth/getAliPayUserInfo"
)
@GetMapping
(
"/info/app/unauth/getAliPayUserInfo"
)
public
ObjectRestResponse
<
String
>
getAliPayUserInfo
(
@RequestParam
(
value
=
"code"
)
String
code
);
public
ObjectRestResponse
<
String
>
getAliPayUserInfo
(
@RequestParam
(
value
=
"code"
)
String
code
);
@RequestMapping
(
"/captcha/app/unauth/verify"
)
ObjectRestResponse
<
Boolean
>
verify
(
@RequestParam
(
value
=
"phone"
)
String
phone
,
@RequestParam
(
value
=
"pointList"
)
String
pointList
);
}
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/controller/CaptchaController.java
View file @
d0409377
package
com
.
xxfc
.
platform
.
universal
.
controller
;
package
com
.
xxfc
.
platform
.
universal
.
controller
;
import
com.alibaba.fastjson.JSONArray
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.util.process.ResultCode
;
import
com.xxfc.platform.universal.constant.CaptchaType
;
import
com.xxfc.platform.universal.constant.CaptchaType
;
import
com.xxfc.platform.universal.constant.RedisKey
;
import
com.xxfc.platform.universal.dto.CaptchaBaseParam
;
import
com.xxfc.platform.universal.dto.CaptchaBaseParam
;
import
com.xxfc.platform.universal.service.AbstractCaptcha
;
import
com.xxfc.platform.universal.service.AbstractCaptcha
;
import
com.xxfc.platform.universal.service.CaptchaFactory
;
import
com.xxfc.platform.universal.service.CaptchaFactory
;
import
com.xxfc.platform.universal.service.ICaptchaFactory
;
import
com.xxfc.platform.universal.service.ICaptchaFactory
;
import
com.xxfc.platform.universal.utils.ImageUtils
;
import
com.xxfc.platform.universal.utils.ImageUtils
;
import
com.xxfc.platform.universal.vo.CaptchaBaseVO
;
import
com.xxfc.platform.universal.vo.CaptchaBaseVO
;
import
com.xxfc.platform.universal.vo.ClickWordCaptchaVO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
java.awt.*
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* @author stx
* @author stx
* @date 2018/11/5 14:58
* @date 2018/11/5 14:58
...
@@ -19,8 +30,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
...
@@ -19,8 +30,12 @@ import org.springframework.web.bind.annotation.ResponseBody;
*/
*/
@Controller
@Controller
@RequestMapping
(
value
=
"/captcha"
)
@RequestMapping
(
value
=
"/captcha"
)
@Slf4j
public
class
CaptchaController
{
public
class
CaptchaController
{
@Autowired
RedisTemplate
redisTemplate
;
@RequestMapping
(
"/app/unauth/blockPuzzle"
)
@RequestMapping
(
"/app/unauth/blockPuzzle"
)
@ResponseBody
@ResponseBody
ObjectRestResponse
blockPuzzle
()
{
ObjectRestResponse
blockPuzzle
()
{
...
@@ -36,17 +51,47 @@ public class CaptchaController {
...
@@ -36,17 +51,47 @@ public class CaptchaController {
@RequestMapping
(
"/app/unauth/clickWord"
)
@RequestMapping
(
"/app/unauth/clickWord"
)
@ResponseBody
@ResponseBody
ObjectRestResponse
clickWord
()
{
ObjectRestResponse
clickWord
(
String
phone
)
{
ICaptchaFactory
captchaFactory
=
new
CaptchaFactory
();
ICaptchaFactory
captchaFactory
=
new
CaptchaFactory
();
AbstractCaptcha
captcha
=
captchaFactory
.
getInstance
(
CaptchaType
.
CLICK_WORD
);
AbstractCaptcha
captcha
=
captchaFactory
.
getInstance
(
CaptchaType
.
CLICK_WORD
);
CaptchaBaseParam
captchaBaseParam
=
new
CaptchaBaseParam
();
CaptchaBaseParam
captchaBaseParam
=
new
CaptchaBaseParam
();
captchaBaseParam
.
setUrlOrPath
(
ImageUtils
.
getClickWordBgPath
());
captchaBaseParam
.
setUrlOrPath
(
ImageUtils
.
getClickWordBgPath
());
captcha
.
setFontColorRandom
(
false
);
captcha
.
setFontColorRandom
(
false
);
CaptchaBaseVO
dataVO
=
captcha
.
create
(
captchaBaseParam
);
ClickWordCaptchaVO
dataVO
=
(
ClickWordCaptchaVO
)
captcha
.
create
(
captchaBaseParam
);
if
(
dataVO
.
getPointList
()
!=
null
)
{
try
{
String
redisLockKey
=
RedisKey
.
CAPTCHA_PHONE_PREFIX
+
phone
;
Boolean
suc
=
redisTemplate
.
opsForValue
().
setIfAbsent
(
redisLockKey
,
JSONArray
.
toJSONString
(
dataVO
.
getPointList
()));
if
(
suc
)
{
redisTemplate
.
expire
(
redisLockKey
,
5
,
TimeUnit
.
MINUTES
);
//5分钟内过期
}
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
EXCEPTION_CODE
,
"出现异常"
);
}
}
return
ObjectRestResponse
.
succ
(
dataVO
);
return
ObjectRestResponse
.
succ
(
dataVO
);
}
}
@RequestMapping
(
"/app/unauth/verify"
)
@ResponseBody
ObjectRestResponse
<
Boolean
>
verify
(
String
phone
,
String
pointList
)
{
if
(
StringUtils
.
isBlank
(
phone
)
||
StringUtils
.
isBlank
(
pointList
))
{
return
ObjectRestResponse
.
paramIsEmpty
();
}
String
redisLockKey
=
RedisKey
.
CAPTCHA_PHONE_PREFIX
+
phone
;
String
captchaCode
=
redisTemplate
.
opsForValue
().
get
(
redisLockKey
)
==
null
?
""
:
redisTemplate
.
opsForValue
().
get
(
redisLockKey
).
toString
();
log
.
info
(
"【注册验证码坐标】:》》》》》 {}"
,
captchaCode
);
if
(
StringUtils
.
isBlank
(
captchaCode
))
{
log
.
error
(
"【注册验证码坐标为空,请重新验证】"
);
return
ObjectRestResponse
.
succ
(
false
);
}
ICaptchaFactory
captchaFactory
=
new
CaptchaFactory
();
AbstractCaptcha
captcha
=
captchaFactory
.
getInstance
(
CaptchaType
.
CLICK_WORD
);
boolean
flag
=
captcha
.
verification
(
JSONArray
.
parseArray
(
captchaCode
,
Point
.
class
),
JSONArray
.
parseArray
(
pointList
,
Point
.
class
));
return
ObjectRestResponse
.
succ
(
flag
);
}
}
}
xx-universal/xx-universal-server/src/main/java/com/xxfc/platform/universal/service/ClickWordCaptcha.java
View file @
d0409377
package
com
.
xxfc
.
platform
.
universal
.
service
;
package
com
.
xxfc
.
platform
.
universal
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.google.common.collect.Lists
;
import
com.xxfc.platform.universal.dto.CaptchaBaseParam
;
import
com.xxfc.platform.universal.dto.CaptchaBaseParam
;
import
com.xxfc.platform.universal.interceptor.CaptchaException
;
import
com.xxfc.platform.universal.interceptor.CaptchaException
;
import
com.xxfc.platform.universal.utils.RandomUtils
;
import
com.xxfc.platform.universal.utils.RandomUtils
;
import
com.xxfc.platform.universal.vo.CaptchaBaseVO
;
import
com.xxfc.platform.universal.vo.ClickWordCaptchaVO
;
import
com.xxfc.platform.universal.vo.ClickWordCaptchaVO
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -32,8 +32,9 @@ public class ClickWordCaptcha extends AbstractCaptcha {
...
@@ -32,8 +32,9 @@ public class ClickWordCaptcha extends AbstractCaptcha {
private
static
int
HAN_ZI_SIZE_HALF
=
30
/
2
;
private
static
int
HAN_ZI_SIZE_HALF
=
30
/
2
;
@Override
@Override
public
C
aptchaBase
VO
create
(
CaptchaBaseParam
captchaParam
)
{
public
C
lickWordCaptcha
VO
create
(
CaptchaBaseParam
captchaParam
)
{
if
(
captchaParam
==
null
if
(
captchaParam
==
null
||
StringUtils
.
isBlank
(
captchaParam
.
getUrlOrPath
()))
{
||
StringUtils
.
isBlank
(
captchaParam
.
getUrlOrPath
()))
{
throw
new
CaptchaException
(
"参数不正确,captchaParam:"
+
JSON
.
toJSONString
(
captchaParam
));
throw
new
CaptchaException
(
"参数不正确,captchaParam:"
+
JSON
.
toJSONString
(
captchaParam
));
...
@@ -64,10 +65,10 @@ public class ClickWordCaptcha extends AbstractCaptcha {
...
@@ -64,10 +65,10 @@ public class ClickWordCaptcha extends AbstractCaptcha {
return
false
;
return
false
;
}
}
}
}
return
fals
e
;
return
tru
e
;
}
}
private
C
aptchaBase
VO
getImageData
(
BufferedImage
backgroundImage
)
{
private
C
lickWordCaptcha
VO
getImageData
(
BufferedImage
backgroundImage
)
{
ClickWordCaptchaVO
dataVO
=
new
ClickWordCaptchaVO
();
ClickWordCaptchaVO
dataVO
=
new
ClickWordCaptchaVO
();
List
<
String
>
wordList
=
new
ArrayList
<
String
>();
List
<
String
>
wordList
=
new
ArrayList
<
String
>();
List
<
Point
>
pointList
=
new
ArrayList
();
List
<
Point
>
pointList
=
new
ArrayList
();
...
@@ -106,7 +107,6 @@ public class ClickWordCaptcha extends AbstractCaptcha {
...
@@ -106,7 +107,6 @@ public class ClickWordCaptcha extends AbstractCaptcha {
if
((
num
-
1
)
!=
i
)
{
if
((
num
-
1
)
!=
i
)
{
wordList
.
add
(
word
);
wordList
.
add
(
word
);
pointList
.
add
(
point
);
}
}
}
}
...
@@ -114,9 +114,11 @@ public class ClickWordCaptcha extends AbstractCaptcha {
...
@@ -114,9 +114,11 @@ public class ClickWordCaptcha extends AbstractCaptcha {
BufferedImage
combinedImage
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
BufferedImage
combinedImage
=
new
BufferedImage
(
width
,
height
,
BufferedImage
.
TYPE_INT_RGB
);
Graphics
combinedGraphics
=
combinedImage
.
getGraphics
();
Graphics
combinedGraphics
=
combinedImage
.
getGraphics
();
combinedGraphics
.
drawImage
(
backgroundImage
,
0
,
0
,
null
);
combinedGraphics
.
drawImage
(
backgroundImage
,
0
,
0
,
null
);
Point
point
=
pointList
.
get
(
RandomUtils
.
getRandomInt
(
0
,
wordList
.
size
()-
1
).
intValue
());
dataVO
.
setOriginalImageBase64
(
getImageToBase64Str
(
backgroundImage
));
dataVO
.
setOriginalImageBase64
(
getImageToBase64Str
(
backgroundImage
));
dataVO
.
setPointList
(
pointList
);
List
<
Point
>
list
=
Lists
.
newArrayList
();
list
.
add
(
point
);
dataVO
.
setPointList
(
list
);
dataVO
.
setWordList
(
wordList
);
dataVO
.
setWordList
(
wordList
);
return
dataVO
;
return
dataVO
;
}
}
...
...
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