Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
32b9aa4e
Commit
32b9aa4e
authored
Jan 16, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
验证码,redis异常层级重构
parent
77ae64b1
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
56 additions
and
66 deletions
+56
-66
src/main/java/cn/meteor/beyondclouds/common/enums/RedisErrorCode.java
+0
-29
src/main/java/cn/meteor/beyondclouds/common/exception/RedisOperationException.java
+8
-5
src/main/java/cn/meteor/beyondclouds/common/exception/SmsException.java
+9
-5
src/main/java/cn/meteor/beyondclouds/common/helper/impl/RedisHelperImpl.java
+4
-5
src/main/java/cn/meteor/beyondclouds/common/helper/impl/SmsHelperImpl.java
+5
-14
src/main/java/cn/meteor/beyondclouds/modules/sms/SmsApi.java
+2
-1
src/main/java/cn/meteor/beyondclouds/modules/sms/enums/SmsErrorCode.java
+1
-1
src/main/java/cn/meteor/beyondclouds/modules/sms/exception/SmsServiceException.java
+18
-0
src/main/java/cn/meteor/beyondclouds/modules/sms/service/ISmsService.java
+2
-1
src/main/java/cn/meteor/beyondclouds/modules/sms/service/impl/SmsServiceImpl.java
+7
-5
No files found.
src/main/java/cn/meteor/beyondclouds/common/enums/RedisErrorCode.java
deleted
100644 → 0
View file @
77ae64b1
package
cn
.
meteor
.
beyondclouds
.
common
.
enums
;
import
cn.meteor.beyondclouds.core.IErrorCode
;
/**
* Redis操作相关错误
* @author meteor
*/
public
enum
RedisErrorCode
implements
IErrorCode
{
SET_FAILURE
(
10001
,
"存储失败"
);
RedisErrorCode
(
long
code
,
String
msg
)
{
this
.
code
=
code
;
this
.
msg
=
msg
;
}
private
long
code
;
private
String
msg
;
@Override
public
long
code
()
{
return
code
;
}
@Override
public
String
msg
()
{
return
msg
;
}
}
src/main/java/cn/meteor/beyondclouds/common/exception/RedisOperationException.java
View file @
32b9aa4e
...
...
@@ -6,12 +6,15 @@ import cn.meteor.beyondclouds.core.exception.ServiceException;
/**
* @author meteor
*/
public
class
RedisOperationException
extends
ServiceException
{
public
RedisOperationException
(
long
errorCode
,
String
errorMsg
)
{
super
(
errorCode
,
errorMsg
);
public
class
RedisOperationException
extends
Exception
{
public
RedisOperationException
()
{
}
public
RedisOperationException
(
IErrorCode
errorCode
)
{
super
(
errorCode
);
public
RedisOperationException
(
String
message
)
{
super
(
message
);
}
public
RedisOperationException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
}
src/main/java/cn/meteor/beyondclouds/common/exception/SmsException.java
View file @
32b9aa4e
...
...
@@ -7,12 +7,16 @@ import cn.meteor.beyondclouds.core.exception.ServiceException;
* 短信相关异常
* @author meteor
*/
public
class
SmsException
extends
ServiceException
{
public
SmsException
(
long
errorCode
,
String
errorMsg
)
{
super
(
errorCode
,
errorMsg
);
public
class
SmsException
extends
Exception
{
public
SmsException
()
{
}
public
SmsException
(
IErrorCode
errorCod
e
)
{
super
(
errorCod
e
);
public
SmsException
(
String
messag
e
)
{
super
(
messag
e
);
}
public
SmsException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
}
src/main/java/cn/meteor/beyondclouds/common/helper/RedisHelperImpl.java
→
src/main/java/cn/meteor/beyondclouds/common/helper/
impl/
RedisHelperImpl.java
View file @
32b9aa4e
package
cn
.
meteor
.
beyondclouds
.
common
.
helper
;
package
cn
.
meteor
.
beyondclouds
.
common
.
helper
.
impl
;
import
cn.meteor.beyondclouds.common.enums.RedisErrorCode
;
import
cn.meteor.beyondclouds.common.exception.RedisOperationException
;
import
cn.meteor.beyondclouds.common.helper.IRedisHelper
;
import
cn.meteor.beyondclouds.util.JsonUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Component
;
...
...
@@ -75,7 +74,7 @@ public class RedisHelperImpl implements IRedisHelper {
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
new
RedisOperationException
(
RedisErrorCode
.
SET_FAILURE
);
throw
new
RedisOperationException
(
"数据存储失败"
);
}
}
...
...
@@ -89,7 +88,7 @@ public class RedisHelperImpl implements IRedisHelper {
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
throw
new
RedisOperationException
(
RedisErrorCode
.
SET_FAILURE
);
throw
new
RedisOperationException
();
}
}
...
...
src/main/java/cn/meteor/beyondclouds/common/helper/SmsHelperImpl.java
→
src/main/java/cn/meteor/beyondclouds/common/helper/
impl/
SmsHelperImpl.java
View file @
32b9aa4e
package
cn
.
meteor
.
beyondclouds
.
common
.
helper
;
package
cn
.
meteor
.
beyondclouds
.
common
.
helper
.
impl
;
import
cn.meteor.beyondclouds.common.enums.SmsErrorCode
;
import
cn.meteor.beyondclouds.common.exception.SmsException
;
import
cn.meteor.beyondclouds.common.helper.ISmsHelper
;
import
cn.meteor.beyondclouds.util.JsonUtils
;
import
com.aliyuncs.CommonRequest
;
import
com.aliyuncs.CommonResponse
;
import
com.aliyuncs.DefaultAcsClient
;
import
com.aliyuncs.IAcsClient
;
import
com.aliyuncs.exceptions.ClientException
;
import
com.aliyuncs.exceptions.ServerException
;
import
com.aliyuncs.http.MethodType
;
import
com.aliyuncs.profile.DefaultProfile
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.util.Map
;
/**
...
...
@@ -47,16 +44,10 @@ public class SmsHelperImpl implements ISmsHelper {
CommonResponse
response
=
client
.
getCommonResponse
(
request
);
Map
data
=
JsonUtils
.
toBean
(
response
.
getData
(),
Map
.
class
);
if
(!
data
.
get
(
SMS_RESPONSE_DATA_KEY
).
equals
(
SMS_RESPONSE_DATA_VALUE_OK
))
{
throw
new
SmsException
(
SmsErrorCode
.
SEND_FAILURE
);
throw
new
SmsException
(
"短信发送失败"
);
}
}
catch
(
ServerException
e
)
{
e
.
printStackTrace
();
throw
new
SmsException
(
SmsErrorCode
.
SERVER_ERROR
.
code
(),
e
.
getErrMsg
());
}
catch
(
ClientException
e
)
{
e
.
printStackTrace
();
throw
new
SmsException
(
SmsErrorCode
.
CLIENT_ERROR
.
code
(),
e
.
getErrMsg
());
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
throw
new
SmsException
(
e
.
getMessage
(),
e
);
}
}
...
...
src/main/java/cn/meteor/beyondclouds/modules/sms/SmsApi.java
View file @
32b9aa4e
...
...
@@ -3,6 +3,7 @@ package cn.meteor.beyondclouds.modules.sms;
import
cn.meteor.beyondclouds.common.exception.SmsException
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.exception.ServiceException
;
import
cn.meteor.beyondclouds.modules.sms.exception.SmsServiceException
;
import
cn.meteor.beyondclouds.modules.sms.service.ISmsService
;
import
cn.meteor.beyondclouds.util.VerifyCodeUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -32,7 +33,7 @@ public class SmsApi {
try
{
smsService
.
sendVerifyCode
(
mobile
,
VerifyCodeUtils
.
randomVerifyCode
());
return
Response
.
success
();
}
catch
(
ServiceException
e
)
{
}
catch
(
S
msS
erviceException
e
)
{
e
.
printStackTrace
();
return
Response
.
error
(
e
);
}
...
...
src/main/java/cn/meteor/beyondclouds/
common
/enums/SmsErrorCode.java
→
src/main/java/cn/meteor/beyondclouds/
modules/sms
/enums/SmsErrorCode.java
View file @
32b9aa4e
package
cn
.
meteor
.
beyondclouds
.
common
.
enums
;
package
cn
.
meteor
.
beyondclouds
.
modules
.
sms
.
enums
;
import
cn.meteor.beyondclouds.core.IErrorCode
;
...
...
src/main/java/cn/meteor/beyondclouds/modules/sms/exception/SmsServiceException.java
0 → 100644
View file @
32b9aa4e
package
cn
.
meteor
.
beyondclouds
.
modules
.
sms
.
exception
;
import
cn.meteor.beyondclouds.core.IErrorCode
;
import
cn.meteor.beyondclouds.core.exception.ServiceException
;
/**
* 短信业务异常
* @author meteor
*/
public
class
SmsServiceException
extends
ServiceException
{
public
SmsServiceException
(
long
errorCode
,
String
errorMsg
)
{
super
(
errorCode
,
errorMsg
);
}
public
SmsServiceException
(
IErrorCode
errorCode
)
{
super
(
errorCode
);
}
}
src/main/java/cn/meteor/beyondclouds/modules/sms/service/ISmsService.java
View file @
32b9aa4e
...
...
@@ -2,6 +2,7 @@ package cn.meteor.beyondclouds.modules.sms.service;
import
cn.meteor.beyondclouds.common.exception.RedisOperationException
;
import
cn.meteor.beyondclouds.common.exception.SmsException
;
import
cn.meteor.beyondclouds.modules.sms.exception.SmsServiceException
;
/**
* 短信业务类
...
...
@@ -14,5 +15,5 @@ public interface ISmsService {
* @param mobile
* @param randomVerifyCode
*/
void
sendVerifyCode
(
String
mobile
,
String
randomVerifyCode
)
throws
Sms
Exception
,
RedisOperation
Exception
;
void
sendVerifyCode
(
String
mobile
,
String
randomVerifyCode
)
throws
Sms
Service
Exception
;
}
src/main/java/cn/meteor/beyondclouds/modules/sms/service/impl/SmsServiceImpl.java
View file @
32b9aa4e
package
cn
.
meteor
.
beyondclouds
.
modules
.
sms
.
service
.
impl
;
import
cn.meteor.beyondclouds.common.exception.RedisOperationException
;
import
cn.meteor.beyondclouds.common.exception.SmsException
;
import
cn.meteor.beyondclouds.modules.sms.enums.SmsErrorCode
;
import
cn.meteor.beyondclouds.common.helper.IRedisHelper
;
import
cn.meteor.beyondclouds.common.helper.ISmsHelper
;
import
cn.meteor.beyondclouds.core.redis.RedisKey
;
import
cn.meteor.beyondclouds.modules.sms.exception.SmsServiceException
;
import
cn.meteor.beyondclouds.modules.sms.service.ISmsService
;
import
cn.meteor.beyondclouds.modules.user.enums.UserErrorCode
;
import
cn.meteor.beyondclouds.modules.user.exception.UserServiceException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -28,11 +26,15 @@ public class SmsServiceImpl implements ISmsService {
}
@Override
public
void
sendVerifyCode
(
String
mobile
,
String
randomVerifyCode
)
throws
SmsException
,
RedisOperationException
{
public
void
sendVerifyCode
(
String
mobile
,
String
randomVerifyCode
)
throws
SmsServiceException
{
try
{
//1. 发送短信
smsHelper
.
sendVerifyCode
(
mobile
,
randomVerifyCode
);
//2.存储短信到redis
redisHelper
.
set
(
RedisKey
.
VERIFY_CODE_KEY
(
mobile
),
randomVerifyCode
,
5
*
60
);
}
catch
(
Exception
e
)
{
throw
new
SmsServiceException
(
SmsErrorCode
.
SEND_FAILURE
);
}
}
}
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