Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
V
volunteer_service
Project
Project
Details
Activity
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
licc
volunteer_service
Commits
15fa52b7
Commit
15fa52b7
authored
Jan 18, 2021
by
licc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增短信相关接口
parent
a3ea46cd
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
558 additions
and
37 deletions
+558
-37
Volunteer.java
...model/src/main/java/cn/wisenergy/model/app/Volunteer.java
+1
-0
SceneType.java
...del/src/main/java/cn/wisenergy/model/enums/SceneType.java
+51
-0
UpdatePasswordVo.java
...src/main/java/cn/wisenergy/model/vo/UpdatePasswordVo.java
+37
-0
UserLoginVo.java
...odel/src/main/java/cn/wisenergy/model/vo/UserLoginVo.java
+21
-8
SendSmsSerVice.java
...rc/main/java/cn/wisenergy/service/app/SendSmsSerVice.java
+42
-5
UserLoginService.java
.../main/java/cn/wisenergy/service/app/UserLoginService.java
+4
-5
SendSmsSerViceImpl.java
...ava/cn/wisenergy/service/app/impl/SendSmsSerViceImpl.java
+57
-8
UserLoginServiceImpl.java
...a/cn/wisenergy/service/app/impl/UserLoginServiceImpl.java
+87
-7
Cache.java
...rvice/src/main/java/cn/wisenergy/service/cache/Cache.java
+62
-0
RedisCacheImpl.java
.../main/java/cn/wisenergy/service/cache/RedisCacheImpl.java
+82
-0
CachePrefix.java
...rc/main/java/cn/wisenergy/service/common/CachePrefix.java
+16
-0
Common.java
...ice/src/main/java/cn/wisenergy/service/common/Common.java
+2
-0
SendSmsController.java
...wisenergy/web/admin/controller/app/SendSmsController.java
+52
-2
UserLoginController.java
...senergy/web/admin/controller/app/UserLoginController.java
+44
-2
No files found.
wisenergy-model/src/main/java/cn/wisenergy/model/app/Volunteer.java
View file @
15fa52b7
...
...
@@ -17,6 +17,7 @@ import java.util.Date;
* @ Description: 志愿实体类
* @ Author : 86187
* @ Date : 2021/1/7 15:15
* @author 86187
*/
@Data
@Builder
...
...
wisenergy-model/src/main/java/cn/wisenergy/model/enums/SceneType.java
0 → 100644
View file @
15fa52b7
package
cn
.
wisenergy
.
model
.
enums
;
/**
* 图片验证码业务类型
*
* @author zh
* @version v2.0
* @since v7.0
* 2018年3月19日 下午4:35:32
*/
public
enum
SceneType
{
//验证码登录
LOGIN
(
1
,
"验证码登录"
),
//手机注册
REGISTER
(
2
,
"手机注册"
),
//修改密码
MODIFY_PASSWORD
(
3
,
"修改密码"
),
//找回密码
FIND_PASSWORD
(
4
,
"找回密码"
),
RESET_PASSWORD
(
5
,
"短信重置密码"
);
private
Integer
code
;
private
String
desc
;
SceneType
(
Integer
code
,
String
desc
)
{
this
.
code
=
code
;
this
.
desc
=
desc
;
}
public
String
getDescription
()
{
return
desc
;
}
public
Integer
getCode
()
{
return
code
;
}
public
static
String
getNameByCode
(
Integer
code
)
{
if
(
null
==
code
)
{
return
null
;
}
for
(
SceneType
type
:
SceneType
.
values
())
{
if
(
type
.
getCode
().
intValue
()
==
code
.
intValue
())
{
return
type
.
name
();
}
}
return
null
;
}
}
wisenergy-model/src/main/java/cn/wisenergy/model/vo/UpdatePasswordVo.java
0 → 100644
View file @
15fa52b7
package
cn
.
wisenergy
.
model
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @ Description: 修改账户密码Vo
* @ Author : 86187
* @ Date : 2021/1/18 14:35
* @author 86187
*/
@Data
@ApiModel
(
value
=
"UpdatePasswordVo"
)
public
class
UpdatePasswordVo
implements
Serializable
{
private
static
final
long
serialVersionUID
=
5543462178133500983L
;
/**
* 用户id
*/
@ApiModelProperty
(
value
=
"用户id"
,
name
=
"userId"
)
private
Integer
userId
;
/**
* 新密码
*/
@ApiModelProperty
(
value
=
"新密码"
,
name
=
"newPassword"
)
private
String
newPassword
;
/**
* 旧密码
*/
@ApiModelProperty
(
value
=
"旧密码"
,
name
=
"oldPassword"
)
private
String
oldPassword
;
}
wisenergy-model/src/main/java/cn/wisenergy/model/vo/UserLoginVo.java
View file @
15fa52b7
...
...
@@ -7,10 +7,11 @@ import lombok.Data;
import
java.io.Serializable
;
/**
*@ Description: 用户登录Vo
*@ Author : 86187
*@ Date : 2021/1/15 14:27
*/
* @author 86187
* @ Description: 用户登录Vo
* @ Author : 86187
* @ Date : 2021/1/15 14:27
*/
@Data
@ApiModel
(
value
=
"UserLoginVo"
)
public
class
UserLoginVo
implements
Serializable
{
...
...
@@ -19,18 +20,30 @@ public class UserLoginVo implements Serializable {
/**
* 手机号码
*/
@ApiModelProperty
(
value
=
"手机号码"
,
name
=
"phone"
)
@ApiModelProperty
(
value
=
"手机号码"
,
name
=
"phone"
)
private
String
phone
;
/**
* 密码
*/
@ApiModelProperty
(
value
=
"密码"
,
name
=
"password"
)
@ApiModelProperty
(
value
=
"密码"
,
name
=
"password"
)
private
String
password
;
/**
* 验证码
*/
@ApiModelProperty
(
value
=
"验证码"
,
name
=
"smCode"
)
private
String
smCode
;
@ApiModelProperty
(
value
=
"验证码"
,
name
=
"code"
)
private
String
code
;
/**
* 场景类型:1:验证码登录 2:手机注册 3:修改密码 4:找回密码
*/
@ApiModelProperty
(
value
=
"场景类型:1:验证码登录 2:手机注册 3:修改密码 4:找回密码 5:短信重置密码"
,
name
=
"scene"
)
private
Integer
scene
;
/**
* 来源: PC/APP
*/
@ApiModelProperty
(
value
=
"来源: PC/APP"
,
name
=
"type"
)
private
String
type
;
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/SendSmsSerVice.java
View file @
15fa52b7
...
...
@@ -3,10 +3,47 @@ package cn.wisenergy.service.app;
import
cn.wisenergy.common.utils.R
;
/**
*@ Description: 短信验证码接口定义
*@ Author : 86187
*@ Date : 2021/1/15 15:44
*/
* @author 86187
* @ Description: 短信验证码接口定义
* @ Author : 86187
* @ Date : 2021/1/15 15:44
*/
public
interface
SendSmsSerVice
{
R
<
Object
>
getSmCode
(
String
phone
);
/**
* 发送短信验证码
*
* @param phone 手机号
* @return true 成功 false 失败
*/
R
<
Boolean
>
sendSmCode
(
String
phone
);
/**
* 在缓存中记录验证码
*
* @param phone 手机号
* @param code 短信验证码
* @param type 场景类型 1:验证码登录 2:手机注册 3:修改密码 4:找回密码
* @return 是否成功
*/
R
<
String
>
record
(
String
phone
,
String
code
,
Integer
type
);
/**
* 验证手机验证码:外部调用
*
* @param phone 手机号码
* @param code 手机验证码
* @param type 场景类型 1:验证码登录 2:手机注册 3:修改密码 4:找回密码
* @return 是否通过校验 true通过,false不通过
*/
R
<
Boolean
>
valid
(
String
phone
,
String
code
,
Integer
type
);
/**
* 验证手机验证码 :内部调用
*
* @param phone 手机号码
* @param code 手机验证码
* @param type 场景类型 1:验证码登录 2:手机注册 3:修改密码 4:找回密码
* @return 是否通过校验 true通过,false不通过
*/
boolean
validCode
(
String
phone
,
String
code
,
Integer
type
);
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/UserLoginService.java
View file @
15fa52b7
package
cn
.
wisenergy
.
service
.
app
;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.model.vo.UpdatePasswordVo
;
import
cn.wisenergy.model.vo.UserInfoVo
;
import
cn.wisenergy.model.vo.UserLoginVo
;
import
cn.wisenergy.model.vo.UserRegisterVo
;
...
...
@@ -46,12 +47,10 @@ public interface UserLoginService {
/**
* 修改密码
*
* @param userId 用户id
* @param newPassword 新密码
* @param oldPassword 旧密码
* @param updateVo 修改密码信息
* @return true 成功 false 失败
*/
R
<
Boolean
>
updatePassword
(
Integer
userId
,
String
newPassword
,
String
oldPassword
);
R
<
Boolean
>
updatePassword
(
UpdatePasswordVo
updateVo
);
/**
* 重置密码
...
...
@@ -67,5 +66,5 @@ public interface UserLoginService {
* @param userLoginVo 登录信息
* @return true 成功 false 失败
*/
R
<
Boolean
>
note
Password
(
UserLoginVo
userLoginVo
);
R
<
Boolean
>
smsReset
Password
(
UserLoginVo
userLoginVo
);
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/SendSmsSerViceImpl.java
View file @
15fa52b7
package
cn
.
wisenergy
.
service
.
app
.
impl
;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.model.enums.SceneType
;
import
cn.wisenergy.service.app.SendSmsSerVice
;
import
cn.wisenergy.service.cache.Cache
;
import
cn.wisenergy.service.common.CachePrefix
;
import
cn.wisenergy.service.common.Common
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
*@ Description: 短信验证码接口实现
*@ Author : 86187
*@ Date : 2021/1/15 15:45
*/
* @ Description: 短信验证码接口实现
* @ Author : 86187
* @ Date : 2021/1/15 15:45
* @author 86187
*/
@Service
@Slf4j
public
class
SendSmsSerViceImpl
implements
SendSmsSerVice
{
@Autowired
private
Cache
cache
;
@Override
public
R
<
Object
>
get
SmCode
(
String
phone
)
{
log
.
info
(
"volunteer-service[]SendSmsSerViceImpl[]
getSmCode[]input.param.phone:"
+
phone
);
if
(
StringUtils
.
isBlank
(
phone
))
{
return
R
.
error
(
"
手机号码
不能为空!"
);
public
R
<
Boolean
>
send
SmCode
(
String
phone
)
{
log
.
info
(
"volunteer-service[]SendSmsSerViceImpl[]
sendSmCode[]input.param.phone:"
+
phone
);
if
(
StringUtils
.
isBlank
(
phone
))
{
return
R
.
error
(
"
入参
不能为空!"
);
}
return
null
;
}
@Override
public
R
<
String
>
record
(
String
phone
,
String
code
,
Integer
scene
)
{
String
value
=
SceneType
.
getNameByCode
(
scene
);
cache
.
put
(
CachePrefix
.
SMS_CODE
.
getPrefix
()
+
value
+
"_"
+
phone
,
code
,
Common
.
SMS_TIMEOUT
);
return
R
.
ok
(
"缓存验证码成功!"
);
}
@Override
public
R
<
Boolean
>
valid
(
String
phone
,
String
code
,
Integer
type
)
{
String
value
=
SceneType
.
getNameByCode
(
type
);
//获取短信验证码key
String
valCode
=
CachePrefix
.
SMS_CODE
.
getPrefix
()
+
value
+
"_"
+
phone
;
//redis中获取验证码
Object
obj
=
cache
.
get
(
valCode
);
if
(
obj
!=
null
&&
obj
.
equals
(
code
))
{
//验证码存在,校验通过,清除验证码缓存
cache
.
remove
(
valCode
);
return
R
.
ok
(
0
,
true
);
}
return
R
.
ok
(
1
,
false
);
}
@Override
public
boolean
validCode
(
String
phone
,
String
code
,
Integer
type
)
{
//获取短信验证码key
String
valCode
=
CachePrefix
.
SMS_CODE
.
getPrefix
()
+
type
+
"_"
+
phone
;
//redis中获取验证码
Object
obj
=
cache
.
get
(
valCode
);
if
(
obj
!=
null
&&
obj
.
equals
(
code
))
{
//验证码存在,校验通过,清除验证码缓存
cache
.
remove
(
valCode
);
return
true
;
}
return
false
;
}
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/UserLoginServiceImpl.java
View file @
15fa52b7
...
...
@@ -7,10 +7,14 @@ import cn.wisenergy.mapper.UsersMapper;
import
cn.wisenergy.model.app.LoginRecord
;
import
cn.wisenergy.model.app.UserInfo
;
import
cn.wisenergy.model.enums.OperationTypeEnum
;
import
cn.wisenergy.model.enums.SceneType
;
import
cn.wisenergy.model.vo.UpdatePasswordVo
;
import
cn.wisenergy.model.vo.UserInfoVo
;
import
cn.wisenergy.model.vo.UserLoginVo
;
import
cn.wisenergy.model.vo.UserRegisterVo
;
import
cn.wisenergy.service.app.SendSmsSerVice
;
import
cn.wisenergy.service.app.UserLoginService
;
import
cn.wisenergy.service.cache.Cache
;
import
cn.wisenergy.service.common.Common
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
...
...
@@ -35,6 +39,12 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, UserInfo> imp
@Autowired
private
LoginRecordMapper
loginRecordMapper
;
@Autowired
private
SendSmsSerVice
sendSmsSerVice
;
@Autowired
private
Cache
cache
;
@Override
public
R
<
Boolean
>
register
(
UserRegisterVo
userVo
)
{
log
.
info
(
"volunteer-service[]UserLoginServiceImpl[]register[]input.param.userVo:"
+
userVo
);
...
...
@@ -85,8 +95,25 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, UserInfo> imp
}
@Override
public
R
<
Boolean
>
loginCode
(
UserLoginVo
userLoginVo
)
{
return
null
;
public
R
<
Boolean
>
loginCode
(
UserLoginVo
userVo
)
{
log
.
info
(
"volunteer-service[]UserLoginServiceImpl[]loginCode[]input.param.userVo:"
+
userVo
);
if
(
null
==
userVo
||
StringUtils
.
isBlank
(
userVo
.
getPhone
())
||
StringUtils
.
isBlank
(
userVo
.
getCode
())
||
StringUtils
.
isBlank
(
userVo
.
getType
())
||
null
==
userVo
.
getScene
())
{
return
R
.
error
(
"入参为空!"
);
}
//1、判断手机号账户是否存在
QueryWrapper
<
UserInfo
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"phone"
,
userVo
.
getPhone
());
queryWrapper
.
eq
(
"is_delete"
,
0
);
UserInfo
userInfo
=
usersMapper
.
selectOne
(
queryWrapper
);
if
(
null
==
userInfo
)
{
return
R
.
error
(
"该手机号未注册,请先注册!"
);
}
//2、判断验证码是否正确
boolean
bool
=
sendSmsSerVice
.
validCode
(
userVo
.
getPhone
(),
userVo
.
getCode
(),
userVo
.
getScene
());
return
R
.
ok
(
bool
);
}
@Override
...
...
@@ -153,8 +180,33 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, UserInfo> imp
}
@Override
public
R
<
Boolean
>
updatePassword
(
Integer
userId
,
String
newPassword
,
String
oldPassword
)
{
return
null
;
public
R
<
Boolean
>
updatePassword
(
UpdatePasswordVo
updateVo
)
{
log
.
info
(
"volunteer-service[]UserLoginServiceImpl[]loginOut[]input.param.updateVo:"
+
updateVo
);
if
(
null
==
updateVo
||
null
==
updateVo
.
getUserId
()
||
StringUtils
.
isBlank
(
updateVo
.
getNewPassword
())
||
StringUtils
.
isBlank
(
updateVo
.
getOldPassword
()))
{
return
R
.
error
(
"入参为空!"
);
}
//1、获取用户信息
UserInfo
userInfo
=
usersMapper
.
selectById
(
updateVo
.
getUserId
());
if
(
null
==
userInfo
)
{
return
R
.
error
(
"用户信息不存在,无法修改密码!"
);
}
//2、判断旧密码是否正确
String
password
=
Md5Util
.
digestMD5
(
updateVo
.
getNewPassword
()
+
userInfo
.
getPassword
());
if
(!
userInfo
.
getPassword
().
equals
(
password
))
{
return
R
.
error
(
"旧密码不正确,请从新输入!"
);
}
//3、修改用户密码为新密码
String
newPassword
=
Md5Util
.
digestMD5
(
updateVo
.
getNewPassword
()
+
userInfo
.
getPhone
());
userInfo
.
setPassword
(
newPassword
);
int
count
=
usersMapper
.
edit
(
userInfo
);
if
(
count
==
0
)
{
return
R
.
ok
(
1
,
false
);
}
return
R
.
ok
(
0
,
true
);
}
@Override
...
...
@@ -168,7 +220,7 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, UserInfo> imp
UserInfo
userInfo
=
usersMapper
.
selectById
(
userId
);
//加密重置密码
String
password
=
Md5Util
.
digestMD5
(
Common
.
RESET_PASSWORD_VALUE
);
String
password
=
Md5Util
.
digestMD5
(
Common
.
RESET_PASSWORD_VALUE
+
userInfo
.
getPhone
()
);
userInfo
.
setPassword
(
password
);
int
count
=
usersMapper
.
edit
(
userInfo
);
...
...
@@ -179,8 +231,36 @@ public class UserLoginServiceImpl extends ServiceImpl<UsersMapper, UserInfo> imp
}
@Override
public
R
<
Boolean
>
notePassword
(
UserLoginVo
userVo
)
{
return
null
;
public
R
<
Boolean
>
smsResetPassword
(
UserLoginVo
userVo
)
{
log
.
info
(
"volunteer-service[]UserLoginServiceImpl[]smsResetPassword[]input.param.userVo:"
+
userVo
);
if
(
null
==
userVo
||
StringUtils
.
isBlank
(
userVo
.
getPhone
())
||
StringUtils
.
isBlank
(
userVo
.
getCode
())
||
StringUtils
.
isBlank
(
userVo
.
getPassword
())
||
null
==
userVo
.
getScene
())
{
return
R
.
error
(
"入参为空!"
);
}
//获取用户信息
QueryWrapper
<
UserInfo
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
eq
(
"phone"
,
userVo
.
getPhone
());
queryWrapper
.
eq
(
"is_delete"
,
0
);
UserInfo
userInfo
=
baseMapper
.
selectOne
(
queryWrapper
);
if
(
null
==
userInfo
)
{
return
R
.
error
(
"用户信息不存在,无法重置密码!"
);
}
//验证验证码
boolean
bool
=
sendSmsSerVice
.
validCode
(
userVo
.
getPhone
(),
userVo
.
getCode
(),
userVo
.
getScene
());
if
(!
bool
)
{
return
R
.
ok
(
1
,
false
);
}
//3、设置新密码
String
password
=
Md5Util
.
digestMD5
(
userVo
.
getPassword
()
+
userVo
.
getPhone
());
userInfo
.
setPassword
(
password
);
int
count
=
usersMapper
.
edit
(
userInfo
);
if
(
count
==
0
)
{
return
R
.
ok
(
1
,
false
);
}
return
R
.
ok
(
0
,
true
);
}
private
Boolean
checkPhone
(
String
phone
,
Integer
userId
)
{
...
...
wisenergy-service/src/main/java/cn/wisenergy/service/cache/Cache.java
0 → 100644
View file @
15fa52b7
package
cn
.
wisenergy
.
service
.
cache
;
import
java.util.Collection
;
import
java.util.Map
;
/**
* @author 86187
*/
public
interface
Cache
<
T
>
{
/**
* Get an item from the cache, nontransactionally
* @param key
* @return the cached object or <tt>null</tt>
*/
Object
get
(
Object
key
);
/**
* 批量set
* @param map
*/
void
multiSet
(
Map
map
);
/**
* 批量删除
* @param keys 要删除的key集合
*/
void
multiDel
(
Collection
keys
);
/**
* Add an item to the cache, nontransactionally, with
* failfast semantics
* @param key
* @param value
*/
void
put
(
Object
key
,
T
value
);
/**
* 往缓存中写入内容
* @param key
* @param value
* @param exp 超时时间,单位为秒
*/
void
put
(
Object
key
,
T
value
,
long
exp
);
/**
* 删除
* @param key
*/
void
remove
(
Object
key
);
/**
* 删除
* @param key
*/
void
vagueDel
(
Object
key
);
/**
* Clear the cache
*/
void
clear
();
}
wisenergy-service/src/main/java/cn/wisenergy/service/cache/RedisCacheImpl.java
0 → 100644
View file @
15fa52b7
package
cn
.
wisenergy
.
service
.
cache
;
import
org.apache.poi.ss.formula.functions.T
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.stereotype.Component
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
/**
* @author 86187
* @ Description: redis的cache实现
* @ Author : 86187
* @ Date : 2021/1/18 11:03
*/
@Component
public
class
RedisCacheImpl
implements
Cache
<
T
>
{
@Autowired
private
RedisTemplate
redisTemplate
;
public
RedisCacheImpl
()
{
}
@Override
public
Object
get
(
Object
key
)
{
return
redisTemplate
.
opsForValue
().
get
(
key
);
}
@Override
public
void
multiSet
(
Map
map
)
{
redisTemplate
.
opsForValue
().
multiSet
(
map
);
}
@Override
public
void
multiDel
(
Collection
keys
)
{
redisTemplate
.
delete
(
keys
);
}
@Override
public
void
put
(
Object
key
,
T
value
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
);
}
@Override
public
void
put
(
Object
key
,
T
value
,
long
exp
)
{
redisTemplate
.
opsForValue
().
set
(
key
,
value
,
exp
,
TimeUnit
.
SECONDS
);
}
@Override
public
void
remove
(
Object
key
)
{
redisTemplate
.
delete
(
key
);
}
/**
* 删除
*
* @param key
*/
@Override
public
void
vagueDel
(
Object
key
)
{
Set
<
String
>
keys
=
redisTemplate
.
keys
(
key
+
"*"
);
redisTemplate
.
delete
(
keys
);
}
@Override
public
void
clear
()
{
Set
keys
=
redisTemplate
.
keys
(
"*"
);
redisTemplate
.
delete
(
keys
);
}
}
wisenergy-service/src/main/java/cn/wisenergy/service/common/CachePrefix.java
0 → 100644
View file @
15fa52b7
package
cn
.
wisenergy
.
service
.
common
;
/**
* @author 86187
*/
public
enum
CachePrefix
{
/**
* 短信验证码
*/
SMS_CODE
;
public
String
getPrefix
()
{
return
this
.
name
()
+
"_"
;
}
}
wisenergy-service/src/main/java/cn/wisenergy/service/common/Common.java
View file @
15fa52b7
...
...
@@ -17,4 +17,6 @@ public class Common {
*/
public
static
final
String
SEND_SMS_URL
=
"http://dysmsapi.aliyuncs.com/?Signature="
;
public
static
final
Integer
SMS_TIMEOUT
=
300
;
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/SendSmsController.java
View file @
15fa52b7
package
cn
.
wisenergy
.
web
.
admin
.
controller
.
app
;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.service.app.SendSmsSerVice
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
* @ Description: 短信管理
...
...
@@ -15,6 +21,50 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping
(
"/user"
)
@Slf4j
public
class
SendSmsController
{
@Autowired
private
SendSmsSerVice
sendSmsSerVice
;
@ApiOperation
(
value
=
"发送短信验证码"
,
notes
=
"发送短信验证码"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"phone"
,
value
=
"手机号码"
,
dataType
=
"String"
,
required
=
true
)
@GetMapping
(
"/sendSms"
)
public
R
<
Boolean
>
sendSms
(
String
phone
)
{
log
.
info
(
"SendSmsController[]sendSms[]input.param:phone:"
+
phone
);
if
(
StringUtils
.
isBlank
(
phone
))
{
return
R
.
error
(
"入参为空!"
);
}
return
sendSmsSerVice
.
sendSmCode
(
phone
);
}
@ApiOperation
(
value
=
"在缓存中记录验证码"
,
notes
=
"在缓存中记录验证码"
,
httpMethod
=
"GET"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"phone"
,
value
=
"手机号码"
,
dataType
=
"String"
,
required
=
true
),
@ApiImplicitParam
(
name
=
"code"
,
value
=
"短信验证码"
,
dataType
=
"String"
,
required
=
true
),
@ApiImplicitParam
(
name
=
"scene"
,
value
=
"场景类型 1:验证码登录 2:手机注册 3:修改密码 4:找回密码"
,
dataType
=
"int"
,
required
=
true
)
})
@GetMapping
(
"/recode"
)
public
R
<
String
>
recode
(
String
phone
,
String
code
,
Integer
scene
)
{
log
.
info
(
"SendSmsController[]recode[]input.param:phone,code,type"
+
phone
,
code
,
scene
);
if
(
StringUtils
.
isBlank
(
phone
)
||
StringUtils
.
isBlank
(
code
)
||
null
==
scene
)
{
return
R
.
error
(
"入参为空!"
);
}
return
sendSmsSerVice
.
record
(
phone
,
code
,
scene
);
}
@ApiOperation
(
value
=
"在缓存中记录验证码"
,
notes
=
"在缓存中记录验证码"
,
httpMethod
=
"GET"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"phone"
,
value
=
"手机号码"
,
dataType
=
"String"
,
required
=
true
),
@ApiImplicitParam
(
name
=
"code"
,
value
=
"短信验证码"
,
dataType
=
"String"
,
required
=
true
),
@ApiImplicitParam
(
name
=
"scene"
,
value
=
"场景类型 1:验证码登录 2:手机注册 3:修改密码 4:找回密码"
,
dataType
=
"int"
,
required
=
true
)
})
@GetMapping
(
"/valid"
)
public
R
<
Boolean
>
valid
(
String
phone
,
String
code
,
Integer
scene
)
{
log
.
info
(
"SendSmsController[]valid[]input.param:phone,code,type"
+
phone
,
code
,
scene
);
if
(
StringUtils
.
isBlank
(
phone
)
||
StringUtils
.
isBlank
(
code
)
||
null
==
scene
)
{
return
R
.
error
(
"入参为空!"
);
}
return
sendSmsSerVice
.
valid
(
phone
,
code
,
scene
);
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/UserLo
ng
Controller.java
→
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/UserLo
gin
Controller.java
View file @
15fa52b7
...
...
@@ -2,6 +2,8 @@ package cn.wisenergy.web.admin.controller.app;
import
cn.wisenergy.common.utils.R
;
import
cn.wisenergy.model.app.Banner
;
import
cn.wisenergy.model.vo.UpdatePasswordVo
;
import
cn.wisenergy.model.vo.UserInfoVo
;
import
cn.wisenergy.model.vo.UserLoginVo
;
import
cn.wisenergy.model.vo.UserRegisterVo
;
...
...
@@ -26,7 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
@Api
(
tags
=
"PC-用户登录"
)
@RequestMapping
(
"/user/login"
)
@Slf4j
public
class
UserLo
ng
Controller
{
public
class
UserLo
gin
Controller
{
@Autowired
private
UserLoginService
userLoginService
;
...
...
@@ -41,13 +43,27 @@ public class UserLongController {
return
R
.
error
(
"入参为空!"
);
}
if
(
StringUtils
.
isBlank
(
userVo
.
getPhone
())
||
StringUtils
.
isBlank
(
userVo
.
getPassword
()))
{
if
(
StringUtils
.
isBlank
(
userVo
.
getPhone
())
||
StringUtils
.
isBlank
(
userVo
.
getPassword
()))
{
return
R
.
error
(
"入参不能为空!"
);
}
return
userLoginService
.
register
(
userVo
);
}
@ApiOperation
(
value
=
"用户验证码登录"
,
notes
=
"用户验证码登录"
,
httpMethod
=
"POST"
)
@ApiImplicitParam
(
name
=
"userVo"
,
value
=
"用户信息"
,
dataType
=
"UserLoginVo"
)
@PostMapping
(
"/loginCode"
)
public
R
<
Boolean
>
loginCode
(
@RequestBody
UserLoginVo
userVo
)
{
log
.
info
(
"volunteer-service[]UserLongController[]loginCode[]input.param.userVo:"
+
userVo
);
if
(
null
==
userVo
||
StringUtils
.
isBlank
(
userVo
.
getPhone
())
||
StringUtils
.
isBlank
(
userVo
.
getCode
())
||
StringUtils
.
isBlank
(
userVo
.
getType
())
||
null
==
userVo
.
getScene
())
{
return
R
.
error
(
"入参为空!"
);
}
return
userLoginService
.
loginCode
(
userVo
);
}
@ApiOperation
(
value
=
"用户账号密码登录"
,
notes
=
"用户账号密码登录"
,
httpMethod
=
"POST"
)
@ApiImplicitParam
(
name
=
"userVo"
,
value
=
"登录用户信息"
,
dataType
=
"UserLoginVo"
)
@PostMapping
(
"/login"
)
...
...
@@ -72,6 +88,19 @@ public class UserLongController {
return
userLoginService
.
loginOut
(
userId
);
}
@ApiOperation
(
value
=
"修改用户密码"
,
notes
=
"修改用户密码"
,
httpMethod
=
"POST"
)
@ApiImplicitParam
(
name
=
"userVo"
,
value
=
"用户密码"
,
dataType
=
"UpdatePasswordVo"
)
@PostMapping
(
"/updatePassword"
)
public
R
<
Boolean
>
updatePassword
(
@RequestBody
UpdatePasswordVo
userVo
)
{
log
.
info
(
"volunteer-service[]UserLongController[]updatePassword[]input.param.userVo:"
+
userVo
);
if
(
null
==
userVo
||
null
==
userVo
.
getUserId
()
||
StringUtils
.
isBlank
(
userVo
.
getOldPassword
())
||
StringUtils
.
isBlank
(
userVo
.
getNewPassword
()))
{
return
R
.
error
(
"入参不能为空!"
);
}
return
userLoginService
.
updatePassword
(
userVo
);
}
@ApiOperation
(
value
=
"重置密码"
,
notes
=
"重置密码"
,
httpMethod
=
"POST"
)
@PostMapping
(
"/resetPassword"
)
public
R
<
Boolean
>
resetPassword
(
Integer
userId
)
{
...
...
@@ -82,4 +111,17 @@ public class UserLongController {
return
userLoginService
.
resetPassword
(
userId
);
}
@ApiOperation
(
value
=
"短信重置密码"
,
notes
=
"修改用户密码"
,
httpMethod
=
"POST"
)
@ApiImplicitParam
(
name
=
"userVo"
,
value
=
"用户密码"
,
dataType
=
"UserLoginVo"
)
@PostMapping
(
"/smsResetPassword"
)
public
R
<
Boolean
>
smsResetPassword
(
@RequestBody
UserLoginVo
userVo
)
{
log
.
info
(
"volunteer-service[]UserLongController[]smsResetPassword[]input.param.userVo:"
+
userVo
);
if
(
null
==
userVo
||
StringUtils
.
isBlank
(
userVo
.
getPhone
())
||
StringUtils
.
isBlank
(
userVo
.
getPassword
())
||
null
==
userVo
.
getScene
())
{
return
R
.
error
(
"入参不能为空!"
);
}
return
userLoginService
.
smsResetPassword
(
userVo
);
}
}
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