Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
P
pica-cloud-account
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
Close sidebar
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
com.pica.cloud.account
pica-cloud-account
提交
73b616fd
提交
73b616fd
编写于
10月 14, 2019
作者:
rushui.chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
20191014 整理代码,合并发送短信验证码逻辑
上级
cb1674e0
流水线
#15747
已失败 于阶段
in 0 second
变更
2
流水线
1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
50 行增加
和
37 行删除
+50
-37
AccountController.java
.../account/account/server/controller/AccountController.java
+1
-26
AutoCodeController.java
...account/account/server/controller/AutoCodeController.java
+49
-11
未找到文件。
server/src/main/java/com/pica/cloud/account/account/server/controller/AccountController.java
浏览文件 @
73b616fd
...
...
@@ -48,8 +48,7 @@ public class AccountController extends AccountBaseController {
private
Logger
logger
=
LoggerFactory
.
getLogger
(
AccountController
.
class
);
@Autowired
private
AccountService
accountService
;
@Autowired
private
CaptchaService
captchaService
;
@Autowired
@Qualifier
(
"cacheMigrateClient"
)
private
ICacheClient
redisClient
;
...
...
@@ -59,30 +58,6 @@ public class AccountController extends AccountBaseController {
return
"test"
;
}
@ApiOperation
(
"H5端和PC端获取短信验证码"
)
@PostMapping
(
"/authCode"
)
public
PicaResponse
<
String
>
getAuthCode
(
@RequestBody
EncryptEntity
entity
)
throws
Exception
{
BaseRequest
request
=
CryptoUtil
.
decrypt
(
entity
,
BaseRequest
.
class
);
String
mobilePhone
=
request
.
getMobile
();
String
flag
=
request
.
getFlag
()+
""
;
String
captchaToken
=
request
.
getCaptchaToken
();
String
captchaAnswer
=
request
.
getCaptchaAnswer
();
//校验图形验证码
if
(!
captchaService
.
acknowledge
(
captchaToken
,
captchaAnswer
))
{
return
PicaResponse
.
toResponse
(
null
,
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"图形验证码错误"
);
}
this
.
checkMobilePhone
(
mobilePhone
);
String
authCode
=
CommonUtil
.
createValidateCode
();
//随机生成验证码
String
message
=
"您的验证码是"
+
authCode
+
",在10分钟内有效。如非本人操作,请忽略本短信!"
;
//判断账号是否已经存在
Account
account
=
accountService
.
getByMobilePhone
(
mobilePhone
);
long
senderId
=
account
==
null
?
0L
:
account
.
getId
();
//验证码保存到redis,失效时间10分钟
redisClient
.
set
(
this
.
getAuthCodeKey
(
mobilePhone
,
flag
),
authCode
,
600
);
//发送短信
super
.
sendMobileMessage
(
mobilePhone
,
message
,
senderId
);
return
PicaResponse
.
toResponse
(
StringUtils
.
EMPTY
);
}
@ApiOperation
(
"微信登录"
)
@PostMapping
(
"/login/wechat"
)
...
...
server/src/main/java/com/pica/cloud/account/account/server/controller/AutoCodeController.java
浏览文件 @
73b616fd
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
controller
;
import
com.pica.cloud.account.account.server.entity.Account
;
import
com.pica.cloud.account.account.server.entity.AccountInfoEntity
;
import
com.pica.cloud.account.account.server.entity.AccountUnionEntity
;
import
com.pica.cloud.account.account.server.entity.EncryptEntity
;
...
...
@@ -8,15 +9,21 @@ import com.pica.cloud.account.account.server.enums.AccountTypeEnum;
import
com.pica.cloud.account.account.server.exception.AccountException
;
import
com.pica.cloud.account.account.server.mapper.AccountInfoDetailMapper
;
import
com.pica.cloud.account.account.server.req.BaseRequest
;
import
com.pica.cloud.account.account.server.service.AccountService
;
import
com.pica.cloud.account.account.server.service.AccountUnionService
;
import
com.pica.cloud.account.account.server.service.CaptchaService
;
import
com.pica.cloud.account.account.server.util.AESUtil
;
import
com.pica.cloud.account.account.server.util.AccountUtils
;
import
com.pica.cloud.account.account.server.util.CryptoUtil
;
import
com.pica.cloud.foundation.entity.PicaException
;
import
com.pica.cloud.foundation.entity.PicaResponse
;
import
com.pica.cloud.foundation.entity.PicaResultCode
;
import
com.pica.cloud.foundation.redis.ICacheClient
;
import
com.pica.cloud.foundation.utils.utils.CommonUtil
;
import
com.pica.cloud.foundation.utils.utils.ValidateUtils
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -26,7 +33,6 @@ import org.springframework.web.bind.annotation.RestController;
@Api
(
description
=
"短信验证码资源"
)
@RestController
@RequestMapping
(
value
=
"/authCode"
)
public
class
AutoCodeController
extends
AccountBaseController
{
private
final
String
AUTH_CODE_PREFIX
=
"authCode-"
;
...
...
@@ -37,19 +43,19 @@ public class AutoCodeController extends AccountBaseController {
@Autowired
private
AccountUnionService
accountUnionService
;
@Autowired
private
CaptchaService
captchaService
;
@Autowired
private
AccountService
accountService
;
@Autowired
@Qualifier
(
"cacheMigrateClient"
)
private
ICacheClient
cacheClient
;
/**
* 必须要传递flag类型
*
* @param entity
* @return
* @throws Exception
*/
@ApiOperation
(
"App端获取短信验证码"
)
@PostMapping
(
value
=
""
)
@ApiOperation
(
"获取短信验证码,无需图形验证码,如app端"
)
@PostMapping
(
value
=
"/authCode"
)
public
PicaResponse
getAuthCode
(
@RequestBody
EncryptEntity
entity
)
throws
Exception
{
BaseRequest
request
=
CryptoUtil
.
decrypt
(
entity
,
BaseRequest
.
class
);
AccountUtils
.
checkMobilePhone
(
request
.
getMobile
());
...
...
@@ -57,6 +63,31 @@ public class AutoCodeController extends AccountBaseController {
return
PicaResponse
.
toResponse
();
}
@ApiOperation
(
"获取短信验证码,需要图形验证码,如H5端和PC端;验证码类型 0默认 1注册 2微信登录绑定手机 3修改手机 4重置密码 5忘记密码 7患者招募提交问卷(效验)"
)
@PostMapping
(
"/account/authCode"
)
public
PicaResponse
<
String
>
getAuthCodeWithCaptcha
(
@RequestBody
EncryptEntity
entity
)
throws
Exception
{
BaseRequest
request
=
CryptoUtil
.
decrypt
(
entity
,
BaseRequest
.
class
);
String
mobilePhone
=
request
.
getMobile
();
String
flag
=
request
.
getFlag
()
+
""
;
String
captchaToken
=
request
.
getCaptchaToken
();
String
captchaAnswer
=
request
.
getCaptchaAnswer
();
//校验图形验证码
if
(!
captchaService
.
acknowledge
(
captchaToken
,
captchaAnswer
))
{
return
PicaResponse
.
toResponse
(
null
,
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"图形验证码错误"
);
}
this
.
checkMobilePhone
(
mobilePhone
);
String
authCode
=
CommonUtil
.
createValidateCode
();
//随机生成验证码
String
message
=
"您的验证码是"
+
authCode
+
",在10分钟内有效。如非本人操作,请忽略本短信!"
;
//判断账号是否已经存在
Account
account
=
accountService
.
getByMobilePhone
(
mobilePhone
);
long
senderId
=
account
==
null
?
0L
:
account
.
getId
();
//验证码保存到redis,失效时间10分钟
cacheClient
.
set
(
this
.
getAuthCodeKey
(
mobilePhone
,
flag
),
authCode
,
600
);
//发送短信
super
.
sendMobileMessage
(
mobilePhone
,
message
,
senderId
);
return
PicaResponse
.
toResponse
(
StringUtils
.
EMPTY
);
}
@ApiOperation
(
"微信获取验证码"
)
@PostMapping
(
value
=
"/authCode/wechat"
)
public
PicaResponse
getWChatSysCode
(
@RequestBody
EncryptEntity
entity
)
throws
Exception
{
...
...
@@ -89,7 +120,7 @@ public class AutoCodeController extends AccountBaseController {
Long
time
=
cacheClient
.
get
(
this
.
getAuthCodeKey
(
mobilePhone
,
flag
.
toString
())
+
"-secure"
,
Long
.
class
);
if
(
time
==
null
)
{
processSendAuthCode
(
mobilePhone
,
flag
,
authCodeKeySecure
);
}
else
{
}
else
{
int
remainTime
=
59
-
(
int
)
(
System
.
currentTimeMillis
()
-
time
)
/
1000
;
if
(
remainTime
>
0
)
{
throw
new
AccountException
(
AccountExceptionEnum
.
PICA_SYSCODE_RETRY
.
getCode
(),
...
...
@@ -124,4 +155,11 @@ public class AutoCodeController extends AccountBaseController {
private
String
getAuthCodeKey
(
String
mobilePhone
,
String
flag
)
{
return
AUTH_CODE_PREFIX
+
flag
+
"-"
+
AESUtil
.
encryptV0
(
mobilePhone
);
}
//手机格式校验
private
void
checkMobilePhone
(
String
mobilePhone
)
{
if
(
StringUtils
.
isBlank
(
mobilePhone
)
||
!
ValidateUtils
.
isMobile
(
mobilePhone
))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"请输入正确的手机号"
);
}
}
}
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录