Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
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
haoban3.0
haoban-manage3.0
Commits
b928f905
Commit
b928f905
authored
Feb 21, 2020
by
qwmqiuwenmin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
9ea4057e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
0 deletions
+123
-0
SendCodeController.java
.../gic/haoban/manage/web/controller/SendCodeController.java
+113
-0
HaoBanErrCode.java
...java/com/gic/haoban/manage/web/errCode/HaoBanErrCode.java
+8
-0
dubbo-haoban-manage-wx.xml
...ge3-wx/src/main/webapp/WEB-INF/dubbo-haoban-manage-wx.xml
+2
-0
No files found.
haoban-manage3-wx/src/main/java/com/gic/haoban/manage/web/controller/SendCodeController.java
View file @
b928f905
package
com
.
gic
.
haoban
.
manage
.
web
.
controller
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.alibaba.fastjson.JSON
;
import
com.gic.haoban.common.utils.CheckSmsCodeUtil
;
import
com.gic.haoban.common.utils.GooglePhoneNumberUtil
;
import
com.gic.haoban.common.utils.HaobanResponse
;
import
com.gic.haoban.communicate.api.service.valid.ValidationCodeService
;
import
com.gic.haoban.manage.api.dto.StaffDTO
;
import
com.gic.haoban.manage.api.service.StaffApiService
;
import
com.gic.haoban.manage.web.errCode.HaoBanErrCode
;
import
com.gic.redis.data.util.RedisUtil
;
import
com.gic.reponse.SendSmsResponse
;
@RestController
public
class
SendCodeController
extends
WebBaseController
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
SendCodeController
.
class
);
@Autowired
private
StaffApiService
staffApiService
;
@Autowired
private
ValidationCodeService
validationCodeService
;
/**
* 验证码发送
*
* @param phoneNumber
* @return
*/
@RequestMapping
(
"/send-code"
)
public
HaobanResponse
sendCode
(
String
phoneNumber
,
@RequestParam
(
defaultValue
=
"86"
)
String
nationcode
,
Integer
type
,
@RequestParam
(
defaultValue
=
"0"
)
int
isTest
)
{
if
(
StringUtils
.
isBlank
(
phoneNumber
)
||
null
==
type
)
{
logger
.
info
(
"没有phoneNumber!"
);
return
resultResponse
(
HaoBanErrCode
.
ERR_5
);
}
if
(!
GooglePhoneNumberUtil
.
checkPhoneNumber
(
phoneNumber
,
nationcode
))
{
logger
.
info
(
"区号或者手机号码不合法:{}-{}"
,
nationcode
,
phoneNumber
);
return
resultResponse
(
HaoBanErrCode
.
ERR_20
);
}
String
cacheKey
=
nationcode
+
phoneNumber
+
type
;
Object
value
=
RedisUtil
.
getCache
(
cacheKey
);
if
(
value
!=
null
&&
(
boolean
)
value
){
logger
.
info
(
"手机号码:{}-{} 验证码只能一分钟请求一次"
,
nationcode
,
phoneNumber
);
return
resultResponse
(
HaoBanErrCode
.
ERR_22
);
}
else
{
RedisUtil
.
setCache
(
cacheKey
,
true
,
60L
);
}
//绑定
if
(
type
==
1
)
{
StaffDTO
staffDTO
=
staffApiService
.
selectByNationcodeAndPhoneNumber
(
null
,
nationcode
,
phoneNumber
);
if
(
staffDTO
==
null
)
{
logger
.
info
(
"用户不存在:{}-{}"
,
nationcode
,
phoneNumber
);
return
resultResponse
(
HaoBanErrCode
.
ERR_8
);
}
}
String
smsCode
=
""
;
if
(
CheckSmsCodeUtil
.
getCacheSmsCode
(
nationcode
+
"-"
+
phoneNumber
,
type
)
!=
null
){
smsCode
=
(
String
)
CheckSmsCodeUtil
.
getCacheSmsCode
(
nationcode
+
"-"
+
phoneNumber
,
type
);
}
else
{
smsCode
=
CheckSmsCodeUtil
.
createSMSCode
();
CheckSmsCodeUtil
.
cacheSmsCode
(
nationcode
+
"-"
+
phoneNumber
,
smsCode
,
type
);
}
logger
.
info
(
"{}-{} 的 验证码:{}"
,
nationcode
,
phoneNumber
,
smsCode
);
//非测试
if
(
isTest
!=
1
)
{
SendSmsResponse
smsResponse
=
validationCodeService
.
sendValidationCode
(
nationcode
,
phoneNumber
,
smsCode
);
logger
.
info
(
"{}-{} 的 验证码 发送结果回执:{}"
,
nationcode
,
phoneNumber
,
JSON
.
toJSONString
(
smsResponse
));
if
(!
smsResponse
.
isSuccess
())
{
HaobanResponse
response
=
new
HaobanResponse
();
response
.
setMessage
(
smsResponse
.
getMessage
());
response
.
setErrorCode
(
HaoBanErrCode
.
ERR_13
.
getCode
());
return
response
;
}
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
else
{
return
resultResponse
(
HaoBanErrCode
.
ERR_1
,
smsCode
);
}
}
/**
* 验证码校验
*
* @param phoneNumber
* @return
*/
@RequestMapping
(
"/validate-code"
)
public
HaobanResponse
validateCode
(
String
phoneNumber
,
@RequestParam
(
defaultValue
=
"86"
)
String
nationcode
,
String
code
,
int
type
)
{
if
(
StringUtils
.
isBlank
(
phoneNumber
)
||
StringUtils
.
isBlank
(
code
))
{
logger
.
info
(
"没有phoneNumber!"
);
return
resultResponse
(
HaoBanErrCode
.
ERR_5
);
}
boolean
b
=
CheckSmsCodeUtil
.
checkSmsCode
(
nationcode
+
"-"
+
phoneNumber
,
code
,
type
);
boolean
c
=
CheckSmsCodeUtil
.
checkSmsCodeIsDelay
(
nationcode
+
"-"
+
phoneNumber
,
code
,
type
);
if
(!
c
){
logger
.
info
(
"phoneNumber:{},code:{} 验证失败,验证码失效"
,
nationcode
+
"-"
+
phoneNumber
,
code
);
return
resultResponse
(
HaoBanErrCode
.
ERR_21
);
}
else
if
(!
b
){
logger
.
info
(
"phoneNumber:{},code:{} 验证失败,验证码失败"
,
nationcode
+
"-"
+
phoneNumber
,
code
);
return
resultResponse
(
HaoBanErrCode
.
ERR_9
);
}
else
{
return
resultResponse
(
HaoBanErrCode
.
ERR_1
);
}
}
}
haoban-manage3-wx/src/main/java/com/gic/haoban/manage/web/errCode/HaoBanErrCode.java
View file @
b928f905
...
...
@@ -60,6 +60,14 @@ public enum HaoBanErrCode {
* 验证码校验失败
*/
ERR_12
(
12
,
"验证码校验失败"
),
ERR_13
(
13
,
"验证码发送失败"
),
ERR_20
(
20
,
"区号或者手机号码不合法"
),
ERR_21
(
21
,
"验证码已过期或者错误"
),
ERR_22
(
22
,
"验证码一分钟只能请求一次"
),
/**
* 员工档案模块
...
...
haoban-manage3-wx/src/main/webapp/WEB-INF/dubbo-haoban-manage-wx.xml
View file @
b928f905
...
...
@@ -28,6 +28,8 @@
<dubbo:reference
interface=
"com.gic.haoban.manage.api.service.WxEnterpriseApiService"
id=
"wxEnterpriseApiService"
/>
<dubbo:reference
interface=
"com.gic.enterprise.api.service.StoreService"
id=
"storeService"
/>
<dubbo:reference
interface=
"com.gic.wechat.api.service.qywx.QywxCorpApiService"
id=
"qywxCorpApiService"
/>
<dubbo:reference
interface=
"com.gic.haoban.communicate.api.service.valid.ValidationCodeService"
id=
"validationCodeService"
/>
</beans>
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