Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
D
data-server
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
data-server
Commits
697d26af
Commit
697d26af
authored
Mar 04, 2021
by
licc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
钱包接口,提现发送短信验证码
parent
aab12fb4
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
98 additions
and
761 deletions
+98
-761
pom.xml
wisenergy-common/pom.xml
+6
-0
Constants.java
...on/src/main/java/cn/wisenergy/common/utils/Constants.java
+18
-3
MathUtils.java
...on/src/main/java/cn/wisenergy/common/utils/MathUtils.java
+44
-0
BankServiceImpl.java
...n/java/cn/wisenergy/service/app/impl/BankServiceImpl.java
+21
-2
RedisService.java
...rc/main/java/cn/wisenergy/service/cache/RedisService.java
+0
-666
BankController.java
...cn/wisenergy/web/admin/controller/app/BankController.java
+7
-2
SmsController.java
.../cn/wisenergy/web/admin/controller/app/SmsController.java
+2
-1
Constants.java
...b-admin/src/main/java/cn/wisenergy/web/sms/Constants.java
+0
-87
No files found.
wisenergy-common/pom.xml
View file @
697d26af
...
...
@@ -146,6 +146,12 @@
<version>
RELEASE
</version>
<scope>
compile
</scope>
</dependency>
<!-- 阿里短信依赖-->
<dependency>
<groupId>
com.aliyun
</groupId>
<artifactId>
aliyun-java-sdk-core
</artifactId>
<version>
4.4.0
</version>
</dependency>
</dependencies>
<!-- MAVEN构建 -->
...
...
wisenergy-common/src/main/java/cn/wisenergy/common/utils/Constants.java
View file @
697d26af
...
...
@@ -41,21 +41,35 @@ public class Constants {
//一秒
public
final
static
Integer
SECOND_INT
=
1
;
//一分钟
public
final
static
Integer
MINUTE_INT
=
SECOND_INT
*
6
0
;
public
final
static
Integer
MINUTE_INT
=
SECOND_INT
*
18
0
;
//半小时
public
final
static
Integer
HALF_HOUR_INT
=
MINUTE_INT
*
30
;
}
//正则的一些常量
public
static
class
RegConstant
{
//手机号正则
public
static
String
PHONE_REGSTR
=
"^
[1]
[0-9]{10}$"
;
public
static
String
PHONE_REGSTR
=
"^
1
[0-9]{10}$"
;
//密码正则
public
static
String
PASSWORD_REGSTR
=
"^([A-Z]|[a-z]|[0-9]|[_]){6,10}$"
;
}
//SMS相关常量
public
static
class
Sms
{
public
static
class
TemplateCode
{
public
static
String
LOGIN_OR_REGISTER
=
"SMS_197895260"
;
//对存入redis的tokn用户进行标注
public
static
String
LOGIN_BZ_REGISTER
=
"xts"
;
//身份验证验证码
public
static
String
LOGIN_SF_REGISTER
=
"SMS_212170059"
;
//登录确认验证码
public
static
String
LOGIN_DL_REGISTER
=
"SMS_212170058"
;
//登录异常验证码
public
static
String
LOGIN_DLYC_REGISTER
=
"SMS_212170057"
;
//用户注册验证码
public
static
String
LOGIN_ZC_REGISTER
=
"SMS_212170056"
;
//修改密码验证码
public
static
String
LOGIN_XGMM_REGISTER
=
"SMS_212170055"
;
// 信息变更验证码
public
static
String
LOGIN_XXBG_REGISTER
=
"SMS_212170054"
;
}
public
static
class
CodeType
{
...
...
@@ -69,5 +83,6 @@ public class Constants {
public
static
String
PROJECT_PRIFIX
=
"xts"
;
public
static
String
SMS_PRIFIX
=
"sms"
;
public
static
String
TOKEN_PRIFIX
=
"token"
;
public
static
String
BANK_PRIFIX
=
"bank"
;
}
}
wisenergy-common/src/main/java/cn/wisenergy/common/utils/MathUtils.java
0 → 100644
View file @
697d26af
package
cn
.
wisenergy
.
common
.
utils
;
import
java.math.BigDecimal
;
/**
* @Description 数字相关工具类
* @Date 2019-08-22 17:08
* @Author est team
* Version 1.0
**/
public
class
MathUtils
{
/**
* 返回一个4位随机数
* @return
*/
public
static
String
random
(){
int
random
=
(
int
)
((
Math
.
random
()
*
9
+
1
)
*
1000
);
return
random
+
""
;
}
/**
* 格式化BigDecimal,返回保留相应的小数
* @param decimal
* @param num
* @return
*/
public
static
BigDecimal
formatDecimal
(
BigDecimal
decimal
,
int
num
){
BigDecimal
result
=
decimal
.
setScale
(
num
,
BigDecimal
.
ROUND_HALF_UP
);
return
result
;
}
/**
* 格式化BigDecimal,默认保留两位小数
* @param decimal
* @return
*/
public
static
BigDecimal
formatDecimal
(
BigDecimal
decimal
){
BigDecimal
result
=
formatDecimal
(
decimal
,
Constants
.
Common
.
DECIMAL_DIGITS
);
return
result
;
}
}
wisenergy-service/src/main/java/cn/wisenergy/service/app/impl/BankServiceImpl.java
View file @
697d26af
package
cn
.
wisenergy
.
service
.
app
.
impl
;
import
cn.wisenergy.common.utils.
R
;
import
cn.wisenergy.common.utils.
*
;
import
cn.wisenergy.mapper.BankInfoMapper
;
import
cn.wisenergy.mapper.UsersMapper
;
import
cn.wisenergy.model.app.BankInfo
;
...
...
@@ -28,6 +28,11 @@ public class BankServiceImpl extends ServiceImpl<BankInfoMapper, BankInfo> imple
@Autowired
private
UsersMapper
usersMapper
;
@Autowired
private
SmsUtils
smsUtils
;
@Autowired
private
RedisUtils
redisUtils
;
@Override
...
...
@@ -93,7 +98,21 @@ public class BankServiceImpl extends ServiceImpl<BankInfoMapper, BankInfo> imple
}
//2、调用发送短信验证码接口
return
null
;
String
templateCode
=
""
;
String
code
=
MathUtils
.
random
();
boolean
bool
=
smsUtils
.
sendMessage
(
user
.
getUserId
(),
templateCode
,
code
);
if
(!
bool
)
{
return
R
.
error
(
"验证码发送失败,请重发!"
);
}
//缓存code到redis
String
phone
=
user
.
getUserId
();
String
key
=
StringUtil
.
formatKeyWithPrefix
(
Constants
.
RedisKey
.
BANK_PRIFIX
,
Constants
.
RedisKey
.
SMS_PRIFIX
,
phone
,
code
+
""
);
boolean
cache
=
redisUtils
.
set
(
key
,
code
,
Constants
.
Duration
.
MINUTE_INT
);
if
(!
cache
)
{
return
R
.
error
(
"缓存验证码失败!"
);
}
return
R
.
ok
(
0
,
true
);
}
@Override
...
...
wisenergy-service/src/main/java/cn/wisenergy/service/cache/RedisService.java
deleted
100644 → 0
View file @
aab12fb4
package
cn
.
wisenergy
.
service
.
cache
;
import
com.fasterxml.jackson.annotation.JsonAutoDetect
;
import
com.fasterxml.jackson.annotation.PropertyAccessor
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.shiro.dao.DataAccessException
;
import
org.springframework.data.redis.connection.RedisConnection
;
import
org.springframework.data.redis.core.RedisCallback
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer
;
import
org.springframework.data.redis.serializer.StringRedisSerializer
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
java.nio.charset.Charset
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
@Slf4j
@Component
public
class
RedisService
{
public
static
final
String
PREFIX
=
"sales_activity"
;
protected
static
final
long
DEFAULT_EXPIRE
=
10
*
24
*
60
*
60L
;
@Resource
(
name
=
"redisTemplate"
)
private
RedisTemplate
redisTemplate
;
private
static
RedisTemplate
<
String
,
Object
>
template
=
null
;
/**
* 生成key
*
* @param keys
* @return
*/
public
String
buildKey
(
Object
...
keys
)
{
StringBuilder
sb
=
new
StringBuilder
();
if
(
keys
.
length
==
1
)
{
sb
.
append
(
keys
);
return
sb
.
toString
();
}
for
(
Object
key
:
keys
)
{
sb
.
append
(
key
).
append
(
":"
);
}
if
(
sb
.
length
()
>
1
)
{
sb
.
deleteCharAt
(
sb
.
length
()
-
1
);
}
return
sb
.
toString
();
}
/**
* 指定缓存失效时间
*
* @param key 键
* @param time 时间(秒)
* @return
*/
public
boolean
expire
(
String
key
,
long
time
)
{
try
{
if
(
time
>
0
)
{
getRedisTemplate
().
expire
(
key
,
time
,
TimeUnit
.
SECONDS
);
}
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 根据key 获取过期时间
*
* @param key 键 不能为null
* @return 时间(秒) 返回0代表为永久有效
*/
public
long
getExpire
(
String
key
)
{
return
getRedisTemplate
().
getExpire
(
key
,
TimeUnit
.
SECONDS
);
}
/**
* 判断key是否存在
*
* @param key 键
* @return true 存在 false不存在
*/
public
boolean
hasKey
(
String
key
)
{
try
{
return
getRedisTemplate
().
hasKey
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 删除缓存
*
* @param key 可以传一个值 或多个
*/
public
void
del
(
String
...
key
)
{
if
(
key
!=
null
&&
key
.
length
>
0
)
{
if
(
key
.
length
==
1
)
{
getRedisTemplate
().
delete
(
key
[
0
]);
}
else
{
getRedisTemplate
().
delete
(
CollectionUtils
.
arrayToList
(
key
));
}
}
}
// ============================String=============================
/**
* 普通缓存获取
*
* @param key 键
* @return 值
*/
public
Object
get
(
String
key
)
{
return
key
==
null
?
null
:
getRedisTemplate
().
opsForValue
().
get
(
key
);
}
/**
* 普通缓存放入
*
* @param key 键
* @param value 值
* @return true成功 false失败
*/
public
boolean
set
(
String
key
,
Object
value
)
{
try
{
getRedisTemplate
().
opsForValue
().
set
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 模糊查询
*
* @param activityCode 查询语句
* @return 查询结果
*/
public
Set
keys
(
String
activityCode
)
{
try
{
StringBuilder
sb
=
new
StringBuilder
(
10
);
sb
.
append
(
PREFIX
).
append
(
":"
)
.
append
(
activityCode
)
.
append
(
":"
)
.
append
(
"*"
);
return
getRedisTemplate
().
keys
(
sb
.
toString
());
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
null
;
}
}
/**
* 普通缓存放入并设置时间
*
* @param key 键
* @param value 值
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置无限期
* @return true成功 false 失败
*/
public
boolean
set
(
String
key
,
Object
value
,
long
time
)
{
try
{
if
(
time
>
0
)
{
getRedisTemplate
().
opsForValue
().
set
(
key
,
value
,
time
,
TimeUnit
.
SECONDS
);
}
else
{
set
(
key
,
value
);
}
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 递增
*
* @param key 键
* @param delta 要增加几(大于0)
* @return
*/
public
long
incr
(
String
key
,
long
delta
)
{
if
(
delta
<
0
)
{
throw
new
RuntimeException
(
"递增因子必须大于0"
);
}
return
getRedisTemplate
().
opsForValue
().
increment
(
key
,
delta
);
}
/**
* 递减
*
* @param key 键
* @param delta 要减少几(小于0)
* @return
*/
public
long
decr
(
String
key
,
long
delta
)
{
if
(
delta
<
0
)
{
throw
new
RuntimeException
(
"递减因子必须大于0"
);
}
return
getRedisTemplate
().
opsForValue
().
increment
(
key
,
-
delta
);
}
// ================================Map=================================
/**
* HashGet
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return 值
*/
public
Object
hget
(
String
key
,
String
item
)
{
return
getRedisTemplate
().
opsForHash
().
get
(
key
,
item
);
}
/**
* 获取hashKey对应的所有键值
*
* @param key 键
* @return 对应的多个键值
*/
public
Map
<
Object
,
Object
>
hmget
(
String
key
)
{
return
getRedisTemplate
().
opsForHash
().
entries
(
key
);
}
/**
* HashSet
*
* @param key 键
* @param map 对应多个键值
* @return true 成功 false 失败
*/
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
)
{
try
{
getRedisTemplate
().
opsForHash
().
putAll
(
key
,
map
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* HashSet 并设置时间
*
* @param key 键
* @param map 对应多个键值
* @param time 时间(秒)
* @return true成功 false失败
*/
public
boolean
hmset
(
String
key
,
Map
<
String
,
Object
>
map
,
long
time
)
{
try
{
getRedisTemplate
().
opsForHash
().
putAll
(
key
,
map
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @return true 成功 false失败
*/
public
boolean
hset
(
String
key
,
String
item
,
Object
value
)
{
try
{
getRedisTemplate
().
opsForHash
().
put
(
key
,
item
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 向一张hash表中放入数据,如果不存在将创建
*
* @param key 键
* @param item 项
* @param value 值
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
* @return true 成功 false失败
*/
public
boolean
hset
(
String
key
,
String
item
,
Object
value
,
long
time
)
{
try
{
getRedisTemplate
().
opsForHash
().
put
(
key
,
item
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 删除hash表中的值
*
* @param key 键 不能为null
* @param item 项 可以使多个 不能为null
*/
public
void
hdel
(
String
key
,
Object
...
item
)
{
getRedisTemplate
().
opsForHash
().
delete
(
key
,
item
);
}
/**
* 判断hash表中是否有该项的值
*
* @param key 键 不能为null
* @param item 项 不能为null
* @return true 存在 false不存在
*/
public
boolean
hHasKey
(
String
key
,
String
item
)
{
return
getRedisTemplate
().
opsForHash
().
hasKey
(
key
,
item
);
}
/**
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
*
* @param key 键
* @param item 项
* @param by 要增加几(大于0)
* @return
*/
public
double
hincr
(
String
key
,
String
item
,
double
by
)
{
return
getRedisTemplate
().
opsForHash
().
increment
(
key
,
item
,
by
);
}
/**
* hash递减
*
* @param key 键
* @param item 项
* @param by 要减少记(小于0)
* @return
*/
public
double
hdecr
(
String
key
,
String
item
,
double
by
)
{
return
getRedisTemplate
().
opsForHash
().
increment
(
key
,
item
,
-
by
);
}
// ============================set=============================
/**
* 根据key获取Set中的所有值
*
* @param key 键
* @return
*/
public
Set
<
Object
>
sGet
(
String
key
)
{
try
{
return
getRedisTemplate
().
opsForSet
().
members
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
null
;
}
}
/**
* 根据value从一个set中查询,是否存在
*
* @param key 键
* @param value 值
* @return true 存在 false不存在
*/
public
boolean
sHasKey
(
String
key
,
Object
value
)
{
try
{
return
getRedisTemplate
().
opsForSet
().
isMember
(
key
,
value
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 将数据放入set缓存
*
* @param key 键
* @param values 值 可以是多个
* @return 成功个数
*/
public
long
sSet
(
String
key
,
Object
...
values
)
{
try
{
return
getRedisTemplate
().
opsForSet
().
add
(
key
,
values
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
/**
* 将set数据放入缓存
*
* @param key 键
* @param time 时间(秒)
* @param values 值 可以是多个
* @return 成功个数
*/
public
long
sSetAndTime
(
String
key
,
long
time
,
Object
...
values
)
{
try
{
Long
count
=
getRedisTemplate
().
opsForSet
().
add
(
key
,
values
);
if
(
time
>
0
)
expire
(
key
,
time
);
return
count
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
/**
* 获取set缓存的长度
*
* @param key 键
* @return
*/
public
long
sGetSetSize
(
String
key
)
{
try
{
return
getRedisTemplate
().
opsForSet
().
size
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
/**
* 移除值为value的
*
* @param key 键
* @param values 值 可以是多个
* @return 移除的个数
*/
public
long
setRemove
(
String
key
,
Object
...
values
)
{
try
{
Long
count
=
getRedisTemplate
().
opsForSet
().
remove
(
key
,
values
);
return
count
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
// ===============================list=================================
/**
* 获取list缓存的内容
*
* @param key 键
* @param start 开始
* @param end 结束 0 到 -1代表所有值
* @return
*/
public
List
<
Object
>
lGet
(
String
key
,
long
start
,
long
end
)
{
try
{
return
getRedisTemplate
().
opsForList
().
range
(
key
,
start
,
end
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
null
;
}
}
/**
* 获取list缓存的长度
*
* @param key 键
* @return
*/
public
long
lGetListSize
(
String
key
)
{
try
{
return
getRedisTemplate
().
opsForList
().
size
(
key
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
/**
* 通过索引 获取list中的值
*
* @param key 键
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
* @return
*/
public
Object
lGetIndex
(
String
key
,
long
index
)
{
try
{
return
getRedisTemplate
().
opsForList
().
index
(
key
,
index
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
null
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
public
boolean
lSet
(
String
key
,
Object
value
)
{
try
{
getRedisTemplate
().
opsForList
().
rightPush
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public
boolean
lSet
(
String
key
,
Object
value
,
long
time
)
{
try
{
getRedisTemplate
().
opsForList
().
rightPush
(
key
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @return
*/
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
)
{
try
{
getRedisTemplate
().
opsForList
().
rightPushAll
(
key
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 将list放入缓存
*
* @param key 键
* @param value 值
* @param time 时间(秒)
* @return
*/
public
boolean
lSet
(
String
key
,
List
<
Object
>
value
,
long
time
)
{
try
{
getRedisTemplate
().
opsForList
().
rightPushAll
(
key
,
value
);
if
(
time
>
0
)
{
expire
(
key
,
time
);
}
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 根据索引修改list中的某条数据
*
* @param key 键
* @param index 索引
* @param value 值
* @return
*/
public
boolean
lUpdateIndex
(
String
key
,
long
index
,
Object
value
)
{
try
{
getRedisTemplate
().
opsForList
().
set
(
key
,
index
,
value
);
return
true
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
false
;
}
}
/**
* 移除N个值为value
*
* @param key 键
* @param count 移除多少个
* @param value 值
* @return 移除的个数
*/
public
long
lRemove
(
String
key
,
long
count
,
Object
value
)
{
try
{
Long
remove
=
getRedisTemplate
().
opsForList
().
remove
(
key
,
count
,
value
);
return
remove
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
0
;
}
}
public
void
deleteInvalidRedisKey
(
String
activityCode
)
{
StringBuilder
sb
=
new
StringBuilder
(
10
);
sb
.
append
(
PREFIX
).
append
(
":"
).
append
(
activityCode
).
append
(
":"
).
append
(
"*"
);
byte
[]
bytes
=
sb
.
toString
().
getBytes
(
Charset
.
defaultCharset
());
redisTemplate
.
execute
(
new
RedisCallback
()
{
@Override
public
Object
doInRedis
(
RedisConnection
connection
)
throws
DataAccessException
{
Set
<
byte
[]>
keys
=
connection
.
keys
(
bytes
);
for
(
byte
[]
key
:
keys
)
{
connection
.
del
(
key
);
}
return
null
;
}
});
}
private
RedisTemplate
getRedisTemplate
()
{
if
(
null
==
template
)
{
template
=
new
RedisTemplate
<
String
,
Object
>();
template
.
setConnectionFactory
(
redisTemplate
.
getConnectionFactory
());
Jackson2JsonRedisSerializer
jackson2JsonRedisSerializer
=
new
Jackson2JsonRedisSerializer
(
Object
.
class
);
ObjectMapper
om
=
new
ObjectMapper
();
om
.
setVisibility
(
PropertyAccessor
.
ALL
,
JsonAutoDetect
.
Visibility
.
ANY
);
om
.
enableDefaultTyping
(
ObjectMapper
.
DefaultTyping
.
NON_FINAL
);
jackson2JsonRedisSerializer
.
setObjectMapper
(
om
);
StringRedisSerializer
stringRedisSerializer
=
new
StringRedisSerializer
();
// key采用String的序列化方式
template
.
setKeySerializer
(
stringRedisSerializer
);
// hash的key也采用String的序列化方式
template
.
setHashKeySerializer
(
stringRedisSerializer
);
// value序列化方式采用jackson
template
.
setValueSerializer
(
jackson2JsonRedisSerializer
);
// hash的value序列化方式采用jackson
template
.
setHashValueSerializer
(
jackson2JsonRedisSerializer
);
template
.
afterPropertiesSet
();
}
return
template
;
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/BankController.java
View file @
697d26af
...
...
@@ -48,9 +48,14 @@ public class BankController {
@ApiOperation
(
value
=
"获取银行卡信息"
,
notes
=
"获取银行卡信息"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"userId"
,
value
=
"用户id"
,
dataType
=
"String"
)
@GetMapping
(
"/getByUserId"
)
public
R
<
BankInfo
>
getByUserId
(
String
userId
){
public
R
<
BankInfo
>
getByUserId
(
String
userId
)
{
return
bankService
.
getByUserId
(
userId
);
}
@ApiOperation
(
value
=
"提现发送短信验证码"
,
notes
=
"提现发送短信验证码"
,
httpMethod
=
"GET"
)
@ApiImplicitParam
(
name
=
"userId"
,
value
=
"用户id"
,
dataType
=
"String"
)
@GetMapping
(
"/sendSmsCode"
)
public
R
<
Boolean
>
sendSmsCode
(
String
userId
)
{
return
bankService
.
bankWithdrawSendSms
(
userId
);
}
}
wisenergy-web-admin/src/main/java/cn/wisenergy/web/admin/controller/app/SmsController.java
View file @
697d26af
package
cn
.
wisenergy
.
web
.
admin
.
controller
.
app
;
import
cn.wisenergy.common.utils.Constants
;
import
cn.wisenergy.common.utils.RedisUtils
;
import
cn.wisenergy.common.utils.SmsUtils
;
import
cn.wisenergy.common.utils.StringUtil
;
...
...
@@ -39,7 +40,7 @@ public class SmsController {
if
(!
phone
.
matches
(
Constants
.
RegConstant
.
PHONE_REGSTR
)){
throw
new
BaseException
(
ResultEnum
.
PHONE_ERROR
);
}
if
(
codeType
!=
Constants
.
Sms
.
CodeType
.
LOGIN_OR_REGISTER
&&
codeType
!=
Constants
.
Sms
.
CodeType
.
PASS_UPDATE
&&
codeType
!=
Constants
.
Sms
.
CodeType
.
ORDER_NOTICE
){
if
(
!
codeType
.
equals
(
Constants
.
Sms
.
CodeType
.
LOGIN_OR_REGISTER
)
&&
!
codeType
.
equals
(
Constants
.
Sms
.
CodeType
.
PASS_UPDATE
)
&&
!
codeType
.
equals
(
Constants
.
Sms
.
CodeType
.
ORDER_NOTICE
)
){
throw
new
BaseException
(
ResultEnum
.
CODETYPE_ERROR
);
}
String
key
=
StringUtil
.
formatKeyWithPrefix
(
Constants
.
RedisKey
.
PROJECT_PRIFIX
,
Constants
.
RedisKey
.
SMS_PRIFIX
,
phone
,
codeType
+
""
);
...
...
wisenergy-web-admin/src/main/java/cn/wisenergy/web/sms/Constants.java
deleted
100644 → 0
View file @
aab12fb4
package
cn
.
wisenergy
.
web
.
sms
;
/***
* 系统中保存的一些常量
*/
/**
* Created by m1991 on 2021/2/28 22:50
*/
public
class
Constants
{
//通用常量
public
static
class
Common
{
//否
public
final
static
Integer
NOT
=
0
;
//是
public
final
static
Integer
YES
=
1
;
//女
public
final
static
Integer
SEX_WOMEN
=
0
;
//男
public
final
static
Integer
SEX_MAN
=
1
;
//数据精度
public
final
static
Integer
DECIMAL_DIGITS
=
2
;
}
//访问来源
public
static
class
SourceType
{
//访问来源-APP
public
final
static
Integer
APP
=
0
;
//访问来源-PC
public
final
static
Integer
PC
=
1
;
}
//连接符
public
static
class
Connnector
{
//逗号
public
final
static
String
COMMA_
=
","
;
//下划线
public
final
static
String
UNDERLINE
=
"_"
;
//冒号
public
final
static
String
COLON
=
":"
;
}
//时长
public
static
class
Duration
{
//一秒
public
final
static
Integer
SECOND_INT
=
1
;
//一分钟
public
final
static
Integer
MINUTE_INT
=
SECOND_INT
*
60
;
//半小时
public
final
static
Integer
HALF_HOUR_INT
=
MINUTE_INT
*
30
;
}
//正则的一些常量
public
static
class
RegConstant
{
//手机号正则
public
static
String
PHONE_REGSTR
=
"^1[0-9]{10}$"
;
//密码正则
public
static
String
PASSWORD_REGSTR
=
"^([A-Z]|[a-z]|[0-9]|[_]){6,10}$"
;
}
//SMS相关常量
public
static
class
Sms
{
public
static
class
TemplateCode
{
//对存入redis的tokn用户进行标注
public
static
String
LOGIN_BZ_REGISTER
=
"xts"
;
//身份验证验证码
public
static
String
LOGIN_SF_REGISTER
=
"SMS_212170059"
;
//登录确认验证码
public
static
String
LOGIN_DL_REGISTER
=
"SMS_212170058"
;
//登录异常验证码
public
static
String
LOGIN_DLYC_REGISTER
=
"SMS_212170057"
;
//用户注册验证码
public
static
String
LOGIN_ZC_REGISTER
=
"SMS_212170056"
;
//修改密码验证码
public
static
String
LOGIN_XGMM_REGISTER
=
"SMS_212170055"
;
// 信息变更验证码
public
static
String
LOGIN_XXBG_REGISTER
=
"SMS_212170054"
;
}
public
static
class
CodeType
{
public
static
Integer
LOGIN_OR_REGISTER
=
0
;
public
static
Integer
PASS_UPDATE
=
1
;
public
static
Integer
ORDER_NOTICE
=
2
;
}
}
//RedisKey相关的常量
public
static
class
RedisKey
{
public
static
String
PROJECT_PRIFIX
=
"xts"
;
public
static
String
SMS_PRIFIX
=
"sms"
;
public
static
String
TOKEN_PRIFIX
=
"token"
;
}
}
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