Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
6bc6be1c
Commit
6bc6be1c
authored
Jul 04, 2017
by
Java—红包—徐 然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加语音短信
parent
147cdbbb
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
157 additions
and
10 deletions
+157
-10
Constants.java
src/main/java/cn/quantgroup/xyqb/Constants.java
+6
-1
SmsController.java
...uantgroup/xyqb/controller/internal/sms/SmsController.java
+72
-9
SmsResult.java
src/main/java/cn/quantgroup/xyqb/model/sms/SmsResult.java
+50
-0
ISmsService.java
...main/java/cn/quantgroup/xyqb/service/sms/ISmsService.java
+2
-0
SmsServiceImpl.java
...a/cn/quantgroup/xyqb/service/sms/impl/SmsServiceImpl.java
+2
-0
DateUtils.java
src/main/java/cn/quantgroup/xyqb/util/DateUtils.java
+25
-0
No files found.
src/main/java/cn/quantgroup/xyqb/Constants.java
View file @
6bc6be1c
...
@@ -25,6 +25,7 @@ public interface Constants {
...
@@ -25,6 +25,7 @@ public interface Constants {
String
REDIS_PREFIX_VERIFICATION_CODE
=
"verificationCode_"
;
String
REDIS_PREFIX_VERIFICATION_CODE
=
"verificationCode_"
;
String
REDIS_VOICE_CODE_COUNT
=
"voice_verification_code_count:"
;
/**
/**
* redis中token的key值前缀
* redis中token的key值前缀
...
@@ -61,5 +62,9 @@ public interface Constants {
...
@@ -61,5 +62,9 @@ public interface Constants {
interface
UserAvatar
{
interface
UserAvatar
{
String
AVATAR_DEFAULT
=
"https://avatar.xyqb.com/default_avatar.png"
;
String
AVATAR_DEFAULT
=
"https://avatar.xyqb.com/default_avatar.png"
;
}
}
interface
Sms
{
String
VERIFICATION_CODE
=
"尊敬的用户,您本次的验证码为:%s,有效期10分钟。"
;
// 随机验证码
String
BINDCARD_SMS
=
"用户您好,您已绑卡成功,将会在1-5个工作日内收到借款,请耐心等待。如有疑问,请致电400-002-0061,感谢您对我们的支持"
;
//绑卡成功后的短信文案
String
REPAY_SMS
=
"用户您好,您在信用钱包的本期账单已还款成功,保持良好的信用可升级为VIP用户,享更多特权,感谢您对信用钱包的支持"
;
}
}
}
src/main/java/cn/quantgroup/xyqb/controller/internal/sms/SmsController.java
View file @
6bc6be1c
...
@@ -5,7 +5,9 @@ import cn.quantgroup.xyqb.Constants;
...
@@ -5,7 +5,9 @@ import cn.quantgroup.xyqb.Constants;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator
;
import
cn.quantgroup.xyqb.aspect.captcha.CaptchaValidator
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.model.JsonResult
;
import
cn.quantgroup.xyqb.service.sms.ISmsService
;
import
cn.quantgroup.xyqb.service.sms.ISmsService
;
import
cn.quantgroup.xyqb.util.DateUtils
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -55,12 +57,51 @@ public class SmsController {
...
@@ -55,12 +57,51 @@ public class SmsController {
return
sendVerificationCode2
(
phoneNo
);
return
sendVerificationCode2
(
phoneNo
);
}
}
/**
* 短信验证码: for H5
* 使用 @FPLock 注解并加入自定义限制参数, 做针对手机号的发送次数限制
*/
@CaptchaValidator
@RequestMapping
(
"/send_sms_verification_code_voice"
)
public
JsonResult
verifyPhoneNoH5New
(
@RequestParam
String
phoneNo
,
@RequestParam
(
required
=
false
)
String
registerFrom
,
String
usage
)
{
if
(
StringUtils
.
isEmpty
(
usage
)
||
!
"4"
.
equals
(
usage
))
{
LOGGER
.
error
(
"参数校验失败,用户注册语音验证码usage参数为{}"
,
usage
);
return
JsonResult
.
buildErrorStateResult
(
"参数校验失败."
,
null
);
}
LOGGER
.
info
(
"注册-发送验证码, phoneNo:{}, registerFrom:{}"
,
phoneNo
,
registerFrom
);
return
sendVerificationCode2Voice
(
phoneNo
,
usage
);
}
@CaptchaValidator
@RequestMapping
(
"/send_reset_code_voice"
)
public
JsonResult
resetPasswordH5New
(
@RequestParam
String
phoneNo
,
@RequestParam
(
required
=
false
)
String
registerFrom
,
String
usage
)
{
if
(
StringUtils
.
isEmpty
(
usage
)
||
!
"5"
.
equals
(
usage
))
{
LOGGER
.
error
(
"参数校验失败,重置密码语音验证码usage参数为{}"
,
usage
);
return
JsonResult
.
buildErrorStateResult
(
"参数校验失败."
,
null
);
}
LOGGER
.
info
(
"重置密码-发送验证码, phoneNo:{}, registerFrom:{}"
,
phoneNo
,
registerFrom
);
return
sendVerificationCode2Voice
(
phoneNo
,
usage
);
}
/**
* 快速登陆发送验证码
*/
@CaptchaValidator
@RequestMapping
(
"/send_login_code_voice"
)
public
JsonResult
sendLoginCodeNew
(
@RequestParam
String
phoneNo
,
@RequestParam
(
required
=
false
)
String
registerFrom
,
String
usage
)
{
if
(
StringUtils
.
isEmpty
(
usage
)
||
!
"6"
.
equals
(
usage
))
{
LOGGER
.
error
(
"参数校验失败,用户登录语音验证码usage参数为{}"
,
usage
);
return
JsonResult
.
buildErrorStateResult
(
"参数校验失败."
,
null
);
}
LOGGER
.
info
(
"快速登陆-发送验证码, phoneNo:{}, registerFrom:{}"
,
phoneNo
,
registerFrom
);
return
sendVerificationCode2Voice
(
phoneNo
,
usage
);
}
/**
/**
* 快速登陆发送验证码
* 快速登陆发送验证码
*
* @param phoneNo
* @param registerFrom
* @return
*/
*/
@CaptchaValidator
@CaptchaValidator
@RequestMapping
(
"/send_login_code"
)
@RequestMapping
(
"/send_login_code"
)
...
@@ -71,10 +112,6 @@ public class SmsController {
...
@@ -71,10 +112,6 @@ public class SmsController {
/**
/**
* 快速注册发送验证码
* 快速注册发送验证码
*
* @param phoneNo
* @param registerFrom
* @return
*/
*/
@CaptchaValidator
@CaptchaValidator
@RequestMapping
(
"/send_regist_code"
)
@RequestMapping
(
"/send_regist_code"
)
...
@@ -83,7 +120,6 @@ public class SmsController {
...
@@ -83,7 +120,6 @@ public class SmsController {
return
sendVerificationCode2
(
phoneNo
);
return
sendVerificationCode2
(
phoneNo
);
}
}
private
JsonResult
sendVerificationCode2
(
String
phoneNo
)
{
private
JsonResult
sendVerificationCode2
(
String
phoneNo
)
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"手机号格式有误"
,
null
);
return
JsonResult
.
buildErrorStateResult
(
"手机号格式有误"
,
null
);
...
@@ -113,4 +149,31 @@ public class SmsController {
...
@@ -113,4 +149,31 @@ public class SmsController {
}
}
}
}
private
JsonResult
sendVerificationCode2Voice
(
String
phoneNo
,
String
usage
)
{
String
verificationCountKey
=
Constants
.
REDIS_VOICE_CODE_COUNT
+
phoneNo
;
Long
getVerificationCount
=
redisTemplate
.
opsForHash
().
increment
(
verificationCountKey
,
usage
.
toString
(),
1
);
if
(
getVerificationCount
>
5
)
{
return
JsonResult
.
buildErrorStateResult
(
"今天已获取5次语音验证码,请使用短信验证码或明天再试"
,
null
);
}
redisTemplate
.
expire
(
verificationCountKey
,
DateUtils
.
getSeconds
(),
TimeUnit
.
SECONDS
);
if
(!
ValidationUtil
.
validatePhoneNo
(
phoneNo
))
{
return
JsonResult
.
buildErrorStateResult
(
"手机号格式有误"
,
null
);
}
String
key
=
Constants
.
REDIS_PREFIX_VERIFICATION_CODE
+
phoneNo
;
long
expire
=
redisTemplate
.
getExpire
(
key
,
TimeUnit
.
MINUTES
);
if
(
expire
>=
EXPIRE_MINUTES
-
1
)
{
return
JsonResult
.
buildSuccessResult
(
"发送成功"
,
null
);
}
String
randomCode
=
smsIsDebug
?
"000000"
:
String
.
valueOf
(
random
.
nextInt
(
899999
)
+
100000
);
String
uniqueId
=
phoneNo
+
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
);
MsgParams
message
=
new
MsgParams
(
Collections
.
singletonList
(
4
),
phoneNo
,
"1"
,
"4"
,
Collections
.
singletonList
(
randomCode
),
uniqueId
);
try
{
smsService
.
getSmsSender
().
sendMsg
(
message
);
redisTemplate
.
opsForValue
().
set
(
key
,
uniqueId
+
":"
+
randomCode
,
EXPIRE_MINUTES
,
TimeUnit
.
MINUTES
);
return
JsonResult
.
buildSuccessResult
(
"发送成功"
,
uniqueId
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"发送语音短信验证码失败"
);
return
JsonResult
.
buildErrorStateResult
(
"发送失败"
,
null
);
}
}
}
}
src/main/java/cn/quantgroup/xyqb/model/sms/SmsResult.java
0 → 100644
View file @
6bc6be1c
package
cn
.
quantgroup
.
xyqb
.
model
.
sms
;
/**
* Created by xuran on 2017/7/4.
*/
public
class
SmsResult
{
private
boolean
ret
;
private
String
msg
;
private
SmsResult
(
boolean
ret
,
String
msg
)
{
this
.
ret
=
ret
;
this
.
msg
=
msg
;
}
public
static
SmsResult
success
()
{
return
new
SmsResult
(
true
,
null
);
}
public
static
SmsResult
success
(
String
msg
)
{
return
new
SmsResult
(
true
,
msg
);
}
public
static
SmsResult
error
(
String
msg
)
{
return
new
SmsResult
(
false
,
msg
);
}
public
boolean
isRet
()
{
return
ret
;
}
public
void
setRet
(
boolean
ret
)
{
this
.
ret
=
ret
;
}
public
String
getMsg
()
{
return
msg
;
}
public
void
setMsg
(
String
msg
)
{
this
.
msg
=
msg
;
}
@Override
public
String
toString
()
{
return
"SmsResult{"
+
"ret="
+
ret
+
", msg='"
+
msg
+
'\''
+
'}'
;
}
}
src/main/java/cn/quantgroup/xyqb/service/sms/ISmsService.java
View file @
6bc6be1c
package
cn
.
quantgroup
.
xyqb
.
service
.
sms
;
package
cn
.
quantgroup
.
xyqb
.
service
.
sms
;
import
cn.quantgroup.sms.SmsSender
;
import
cn.quantgroup.sms.SmsSender
;
import
cn.quantgroup.xyqb.model.sms.SmsResult
;
/**
/**
* 短信发送服务
* 短信发送服务
...
@@ -19,4 +20,5 @@ public interface ISmsService {
...
@@ -19,4 +20,5 @@ public interface ISmsService {
boolean
validRegisterOrResetPasswdVerificationCode
(
String
phoneNo
,
String
smsVerificationCode
);
boolean
validRegisterOrResetPasswdVerificationCode
(
String
phoneNo
,
String
smsVerificationCode
);
boolean
validateFastLoginVerificationCode
(
String
phoneNo
,
String
verificationCode
);
boolean
validateFastLoginVerificationCode
(
String
phoneNo
,
String
verificationCode
);
}
}
src/main/java/cn/quantgroup/xyqb/service/sms/impl/SmsServiceImpl.java
View file @
6bc6be1c
...
@@ -3,6 +3,7 @@ package cn.quantgroup.xyqb.service.sms.impl;
...
@@ -3,6 +3,7 @@ package cn.quantgroup.xyqb.service.sms.impl;
import
cn.quantgroup.sms.MsgParams
;
import
cn.quantgroup.sms.MsgParams
;
import
cn.quantgroup.sms.SmsSender
;
import
cn.quantgroup.sms.SmsSender
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.Constants
;
import
cn.quantgroup.xyqb.model.sms.SmsResult
;
import
cn.quantgroup.xyqb.service.sms.ISmsService
;
import
cn.quantgroup.xyqb.service.sms.ISmsService
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -107,6 +108,7 @@ public class SmsServiceImpl implements ISmsService {
...
@@ -107,6 +108,7 @@ public class SmsServiceImpl implements ISmsService {
}
}
private
boolean
confirmSms
(
String
smsVerificationCode
,
String
unqiueId
,
String
code
)
{
private
boolean
confirmSms
(
String
smsVerificationCode
,
String
unqiueId
,
String
code
)
{
try
{
try
{
MsgParams
message
=
new
MsgParams
(
Collections
.
singletonList
(
2
),
unqiueId
);
MsgParams
message
=
new
MsgParams
(
Collections
.
singletonList
(
2
),
unqiueId
);
...
...
src/main/java/cn/quantgroup/xyqb/util/DateUtils.java
0 → 100644
View file @
6bc6be1c
package
cn
.
quantgroup
.
xyqb
.
util
;
import
java.util.Calendar
;
/**
* Created by xuran on 2017/7/4.
*/
public
class
DateUtils
{
/**
* 计算当前时间到当天23:59:59时间差,
* 返回时间差(单位秒)
* @return
*/
public
static
long
getSeconds
()
{
Calendar
endOfDay
=
Calendar
.
getInstance
();
endOfDay
.
set
(
Calendar
.
HOUR_OF_DAY
,
23
);
endOfDay
.
set
(
Calendar
.
MINUTE
,
59
);
endOfDay
.
set
(
Calendar
.
SECOND
,
59
);
long
timeStamp
=
endOfDay
.
getTimeInMillis
();
Calendar
current
=
Calendar
.
getInstance
();
long
now
=
current
.
getTimeInMillis
();
long
during
=
(
timeStamp
-
now
)
/
1000
;
return
during
;
}
}
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