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
提交
d48b4134
提交
d48b4134
编写于
8月 27, 2019
作者:
rushui.chen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
20190827 工具类的封装
上级
8c93aa14
流水线
#13700
已失败 于阶段
in 0 second
变更
4
流水线
1
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
217 行增加
和
0 行删除
+217
-0
ModifyMobileController.java
...unt/account/server/controller/ModifyMobileController.java
+9
-0
RegisterController.java
...account/account/server/controller/RegisterController.java
+6
-0
AccountUtils.java
.../pica/cloud/account/account/server/util/AccountUtils.java
+119
-0
TokenUtils.java
...om/pica/cloud/account/account/server/util/TokenUtils.java
+83
-0
未找到文件。
server/src/main/java/com/pica/cloud/account/account/server/controller/ModifyMobileController.java
0 → 100644
浏览文件 @
d48b4134
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
controller
;
import
io.swagger.annotations.Api
;
import
org.springframework.web.bind.annotation.RestController
;
@Api
(
"修改手机号资源"
)
@RestController
public
class
ModifyMobileController
{
}
server/src/main/java/com/pica/cloud/account/account/server/controller/RegisterController.java
浏览文件 @
d48b4134
...
...
@@ -7,4 +7,10 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
public
class
RegisterController
{
}
server/src/main/java/com/pica/cloud/account/account/server/util/AccountUtils.java
0 → 100644
浏览文件 @
d48b4134
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
util
;
import
com.alibaba.fastjson.JSONObject
;
import
com.pica.cloud.foundation.entity.PicaException
;
import
com.pica.cloud.foundation.entity.PicaResultCode
;
import
com.pica.cloud.foundation.redis.ICacheClient
;
import
com.pica.cloud.foundation.utils.utils.EncryptCreateUtil
;
import
com.pica.cloud.foundation.utils.utils.ValidateUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.stereotype.Component
;
/**
* 账户工具类
*/
@Component
public
class
AccountUtils
{
@Autowired
@Qualifier
(
"cacheMigrateClient"
)
private
ICacheClient
cacheClient
;
private
static
final
String
AUTH_CODE_PREFIX
=
"authCode-"
;
//手机格式校验
public
static
void
checkMobilePhone
(
String
mobilePhone
)
{
if
(
StringUtils
.
isBlank
(
mobilePhone
)
||
!
ValidateUtils
.
isMobile
(
mobilePhone
))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"请输入正确的手机号"
);
}
}
//获取验证码redis key
public
static
String
getAuthCodeKey
(
String
mobilePhone
,
String
flag
)
{
return
AUTH_CODE_PREFIX
+
flag
+
"-"
+
EncryptCreateUtil
.
encrypt
(
mobilePhone
);
}
//校验验证码
public
void
checkAuthCode
(
String
mobile
,
String
type
,
String
sysCode
)
{
String
flag
=
org
.
apache
.
commons
.
lang
.
StringUtils
.
isBlank
(
type
)
?
"0"
:
type
;
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isBlank
(
sysCode
))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"短信验证码错误"
);
}
String
authCodeKey
=
AccountUtils
.
getAuthCodeKey
(
mobile
,
flag
);
String
cacheCode
=
cacheClient
.
get
(
authCodeKey
);
//从redis获取验证码
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isBlank
(
cacheCode
))
{
throw
new
PicaException
(
PicaResultCode
.
RESULE_DATA_NONE
.
code
(),
"短信验证码已过期,请重新获取"
);
}
if
(!
org
.
apache
.
commons
.
lang
.
StringUtils
.
equals
(
sysCode
,
cacheCode
))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"短信验证码错误"
);
}
//清除验证码
cacheClient
.
del
(
authCodeKey
);
}
//手机号和验证码校验
public
void
checkMobilePhoneAndAuthCode
(
String
mobile
,
String
type
,
String
sysCode
)
{
if
(
StringUtils
.
isBlank
(
mobile
)
||
!
ValidateUtils
.
isMobile
(
mobile
))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"请输入正确的手机号"
);
}
String
flag
=
org
.
apache
.
commons
.
lang
.
StringUtils
.
isBlank
(
type
)
?
"0"
:
type
;
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isBlank
(
sysCode
))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"短信验证码错误"
);
}
String
authCodeKey
=
AccountUtils
.
getAuthCodeKey
(
mobile
,
flag
);
String
cacheCode
=
cacheClient
.
get
(
authCodeKey
);
//从redis获取验证码
if
(
org
.
apache
.
commons
.
lang
.
StringUtils
.
isBlank
(
cacheCode
))
{
throw
new
PicaException
(
PicaResultCode
.
RESULE_DATA_NONE
.
code
(),
"短信验证码已过期,请重新获取"
);
}
if
(!
org
.
apache
.
commons
.
lang
.
StringUtils
.
equals
(
sysCode
,
cacheCode
))
{
throw
new
PicaException
(
PicaResultCode
.
PARAM_IS_INVALID
.
code
(),
"短信验证码错误"
);
}
cacheClient
.
del
(
authCodeKey
);
}
/**
* 请求参数解密、反序列化
*
* @param params
* @param zClass
* @param <T>
* @return
*/
public
static
<
T
>
T
getRequestEntity
(
String
params
,
Class
<
T
>
zClass
)
throws
Exception
{
String
json
=
EncryptCreateUtil
.
dencrypt
(
params
);
return
JSONObject
.
parseObject
(
json
,
zClass
);
}
/**
* 获取终端来源
*
* @param registerSource
* @return
*/
public
static
String
getSourceType
(
Integer
registerSource
)
{
String
sourceType
=
null
;
if
(
registerSource
==
4
)
{
sourceType
=
"h5"
;
}
else
if
(
registerSource
==
3
)
{
sourceType
=
"web"
;
}
else
if
(
registerSource
==
5
)
{
sourceType
=
"admin"
;
}
else
{
sourceType
=
"app"
;
}
return
sourceType
;
}
/**
* 校验手机号是否注册过
*
* @param mobile
*/
// public boolean checkRegisterMobile(String mobile) {
// String encrypt = EncryptCreateUtil.encrypt(mobile);
// AccountContact accountContact = accountContactServer.selectByMobile(encrypt);
// return (accountContact != null && accountContact.getAcctId() != null);
// }
}
server/src/main/java/com/pica/cloud/account/account/server/util/TokenUtils.java
0 → 100644
浏览文件 @
d48b4134
package
com
.
pica
.
cloud
.
account
.
account
.
server
.
util
;
import
com.pica.cloud.account.account.server.entity.Account
;
import
com.pica.cloud.foundation.redis.ICacheClient
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.stereotype.Component
;
import
java.text.SimpleDateFormat
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.UUID
;
/**
* Token工具类
*/
@Component
public
class
TokenUtils
{
@Autowired
@Qualifier
(
"cacheMigrateClient"
)
private
ICacheClient
cacheClient
;
/**
* 校验token的状态
*
* @param token
* @return
*/
public
boolean
checkTokenStatus
(
String
token
)
{
String
str
=
cacheClient
.
get
(
"token-"
+
token
);
return
StringUtils
.
isBlank
(
str
);
}
/**
* 生成随机token
*
* @param account
* @return
*/
public
String
generateToken
(
Account
account
)
{
//判断用户终端类型
String
sourceType
=
AccountUtils
.
getSourceType
(
account
.
getRegisterSource
());
String
newToken
=
StringUtils
.
EMPTY
;
//用户唯一key
String
tokenDoctorId
=
"token-doctor-"
+
account
.
getId
().
toString
();
//清除旧token对应的用户id
String
oldToken
=
cacheClient
.
get
(
tokenDoctorId
+
"-"
+
sourceType
);
if
(
StringUtils
.
isNoneBlank
(
oldToken
))
{
cacheClient
.
del
(
oldToken
);
}
//生成新的token,并和用户唯一key绑定
newToken
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
).
toUpperCase
();
int
expiredSeconds
=
30
*
24
*
60
*
60
;
cacheClient
.
set
(
"token-"
+
newToken
,
tokenDoctorId
,
expiredSeconds
);
//存储当前登录终端对应的token
cacheClient
.
set
(
tokenDoctorId
+
"-"
+
sourceType
,
"token-"
+
newToken
,
expiredSeconds
);
String
userData
=
cacheClient
.
hget
(
tokenDoctorId
,
"id"
);
if
(
StringUtils
.
isEmpty
(
userData
))
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"token"
,
newToken
);
map
.
put
(
"id"
,
account
.
getId
()
+
""
);
map
.
put
(
"mobile"
,
account
.
getMobilePhone
());
map
.
put
(
"name"
,
account
.
getMobilePhone
().
replaceAll
(
"(\\d{3})\\d{4}(\\w{4})"
,
"$1****$2"
));
map
.
put
(
"created_time"
,
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
format
(
account
.
getCreatTime
()));
map
.
put
(
"sysCode"
,
sourceType
);
Iterator
<
Map
.
Entry
<
String
,
String
>>
iterator
=
map
.
entrySet
().
iterator
();
while
(
iterator
.
hasNext
())
{
Map
.
Entry
<
String
,
String
>
mapData
=
iterator
.
next
();
String
key
=
mapData
.
getKey
();
String
valueInfo
=
mapData
.
getValue
();
//存储token:(token-doctor-1:用户数据)
cacheClient
.
hset
(
tokenDoctorId
,
key
,
valueInfo
);
}
}
return
newToken
;
}
}
写
预览
Markdown
格式
0%
请重试
or
附加一个文件
附加文件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录