Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gs1-office-web-sit
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
吴迪
gs1-office-web-sit
Commits
982e7701
Commit
982e7701
authored
Dec 14, 2021
by
ZhangYunfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增修改用户手机号功能
parent
72636f02
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
483 additions
and
81 deletions
+483
-81
MemberController.java
...io/office/modules/manage/controller/MemberController.java
+9
-0
TimescodeChphoneDao.java
...ava/io/office/modules/manage/dao/TimescodeChphoneDao.java
+19
-0
TimescodeChphoneIpDao.java
...a/io/office/modules/manage/dao/TimescodeChphoneIpDao.java
+19
-0
TimescodeChphoneEntity.java
.../office/modules/manage/entity/TimescodeChphoneEntity.java
+44
-0
TimescodeChphoneIpEntity.java
...ffice/modules/manage/entity/TimescodeChphoneIpEntity.java
+42
-0
MemberService.java
.../java/io/office/modules/manage/service/MemberService.java
+2
-0
MemberServiceImpl.java
...office/modules/manage/service/impl/MemberServiceImpl.java
+316
-80
TimescodeRegiServiceImpl.java
...modules/manage/service/impl/TimescodeRegiServiceImpl.java
+1
-1
TimescodeChphoneDao.xml
src/main/resources/mapper/manage/TimescodeChphoneDao.xml
+16
-0
TimescodeChphoneIpDao.xml
src/main/resources/mapper/manage/TimescodeChphoneIpDao.xml
+15
-0
No files found.
src/main/java/io/office/modules/manage/controller/MemberController.java
View file @
982e7701
...
...
@@ -66,6 +66,15 @@ public class MemberController extends AbstractController {
memberService
.
updatephone
(
params
,
request
,
response
);
return
R
.
ok
();
}
/**
* 获取验证码
*/
@RequestMapping
(
"/authApi/getVerificationCode"
)
// @RequiresPermissions("manage:timescoderegi:list")
public
R
getVerificationCode
(
@RequestBody
Map
<
String
,
Object
>
params
,
HttpServletRequest
request
,
HttpServletResponse
response
){
String
msg
=
memberService
.
getVerificationCode
(
params
,
request
,
response
);
return
R
.
ok
();
}
/**
* 列表
...
...
src/main/java/io/office/modules/manage/dao/TimescodeChphoneDao.java
0 → 100644
View file @
982e7701
package
io
.
office
.
modules
.
manage
.
dao
;
import
io.office.modules.manage.entity.TimescodeChphoneEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Component
;
/**
* ${comments}
*
* @author wudi
* @email
* @date 2021-12-13 17:24:17
*/
@Mapper
@Component
public
interface
TimescodeChphoneDao
extends
BaseMapper
<
TimescodeChphoneEntity
>
{
}
src/main/java/io/office/modules/manage/dao/TimescodeChphoneIpDao.java
0 → 100644
View file @
982e7701
package
io
.
office
.
modules
.
manage
.
dao
;
import
io.office.modules.manage.entity.TimescodeChphoneIpEntity
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Component
;
/**
* ${comments}
*
* @author wudi
* @email
* @date 2021-12-13 17:24:17
*/
@Mapper
@Component
public
interface
TimescodeChphoneIpDao
extends
BaseMapper
<
TimescodeChphoneIpEntity
>
{
}
src/main/java/io/office/modules/manage/entity/TimescodeChphoneEntity.java
0 → 100644
View file @
982e7701
package
io
.
office
.
modules
.
manage
.
entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
java.io.Serializable
;
import
java.util.Date
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
/**
* ${comments}
*
* @author wudi
* @email
* @date 2021-12-13 17:24:17
*/
@Data
@AllArgsConstructor
@TableName
(
"timescode_chPhone"
)
public
class
TimescodeChphoneEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* $column.comments
*/
@TableId
(
type
=
IdType
.
INPUT
)
private
String
phone
;
/**
* $column.comments
*/
private
String
date
;
/**
* $column.comments
*/
private
Integer
times
;
/**
* $column.comments
*/
private
Integer
timesValidate
;
}
src/main/java/io/office/modules/manage/entity/TimescodeChphoneIpEntity.java
0 → 100644
View file @
982e7701
package
io
.
office
.
modules
.
manage
.
entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
java.io.Serializable
;
import
java.util.Date
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* ${comments}
*
* @author wudi
* @email
* @date 2021-12-13 17:24:17
*/
@Data
@AllArgsConstructor
@TableName
(
"timescode_chPhone_ip"
)
public
class
TimescodeChphoneIpEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* $column.comments
*/
@TableId
(
type
=
IdType
.
INPUT
)
private
String
ip
;
/**
* $column.comments
*/
private
String
date
;
/**
* $column.comments
*/
private
Integer
timesIp
;
}
src/main/java/io/office/modules/manage/service/MemberService.java
View file @
982e7701
...
...
@@ -25,5 +25,7 @@ public interface MemberService extends IService<MemberEntity> {
void
updatephone
(
Map
<
String
,
Object
>
params
,
HttpServletRequest
request
,
HttpServletResponse
response
);
String
getVerificationCode
(
Map
<
String
,
Object
>
params
,
HttpServletRequest
request
,
HttpServletResponse
response
);
}
src/main/java/io/office/modules/manage/service/impl/MemberServiceImpl.java
View file @
982e7701
...
...
@@ -2,27 +2,29 @@ package io.office.modules.manage.service.impl;
import
io.office.common.exception.RRException
;
import
io.office.common.utils.IPUtils
;
import
io.office.modules.manage.dao.TimescodeRegiDao
;
import
io.office.modules.manage.entity.TimescodeRegiEntity
;
import
io.office.modules.manage.dao.*
;
import
io.office.modules.manage.entity.*
;
import
io.office.modules.manage.utils.DateUtils
;
import
io.office.modules.manage.utils.MD5Util
;
import
org.apache.commons.httpclient.NameValuePair
;
import
org.apache.commons.httpclient.methods.PostMethod
;
import
org.dom4j.Document
;
import
org.dom4j.DocumentHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.Map
;
import
java.util.regex.Pattern
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
io.office.common.utils.PageUtils
;
import
io.office.common.utils.Query
;
import
io.office.modules.manage.dao.MemberDao
;
import
io.office.modules.manage.entity.MemberEntity
;
import
io.office.modules.manage.service.MemberService
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
@Service
(
"memberService"
)
...
...
@@ -33,8 +35,17 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
private
TimescodeRegiDao
timescodeRegiDao
;
@Autowired
private
TimescodeChphoneDao
timescodeChphoneDao
;
@Autowired
private
TimescodeChphoneIpDao
timescodeChphoneIpDao
;
@Autowired
private
MemberDao
memberDao
;
@Autowired
private
LogMessageDao
logMessageDao
;
@Override
public
PageUtils
queryPage
(
Map
<
String
,
Object
>
params
)
{
IPage
<
MemberEntity
>
page
=
this
.
page
(
...
...
@@ -46,53 +57,52 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
}
@Override
public
void
userRegistered
(
Map
<
String
,
Object
>
params
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
String
userName
=
params
.
get
(
"userName"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"userName"
));
String
emiail
=
params
.
get
(
"e-miail"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"e-miail"
));
String
phone
=
params
.
get
(
"phone"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"phone"
));
String
subjoin
=
params
.
get
(
"subjoin"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"subjoin"
));
//验证码
String
passWord
=
params
.
get
(
"passWord"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"passWord"
));
String
passWord_repeat
=
params
.
get
(
"passWord_repeat"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"passWord_repeat"
));
//重复密码
String
userName
=
params
.
get
(
"userName"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"userName"
));
String
emiail
=
params
.
get
(
"e-miail"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"e-miail"
));
String
phone
=
params
.
get
(
"phone"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"phone"
));
String
subjoin
=
params
.
get
(
"subjoin"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"subjoin"
));
//验证码
String
passWord
=
params
.
get
(
"passWord"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"passWord"
));
String
passWord_repeat
=
params
.
get
(
"passWord_repeat"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"passWord_repeat"
));
//重复密码
//判断用户名合法性
if
(!
checkUserName
(
userName
)){
if
(!
checkUserName
(
userName
))
{
throw
new
RRException
(
"用户名不能是纯数字,长度2-8位"
);
}
//判断密码合法性
if
(!
checkPassWord
(
passWord
)){
if
(!
checkPassWord
(
passWord
))
{
throw
new
RRException
(
"密码只能是数字加字母,长度5-12位"
);
}
//判断重复密码
if
(!
passWord
.
equals
(
passWord_repeat
)){
if
(!
passWord
.
equals
(
passWord_repeat
))
{
throw
new
RRException
(
"两次密码不一致"
);
}
//判断email
if
(!
isValidEmail
(
emiail
)){
if
(!
isValidEmail
(
emiail
))
{
throw
new
RRException
(
"e-miail格式错误"
);
}
//判断联系电话非空,且为11位数字
if
(!
matchPhoneNumber
(
phone
)){
if
(!
matchPhoneNumber
(
phone
))
{
throw
new
RRException
(
"手机格式不正确,请重新填写"
);
}
//利用获取验证码时保存的session,判断手机验证码非空,和发送的短信内容是否一致,提交时的手机号与接收验证码的手机号是否相同,验证码是否已失效
String
subjoinReq
=
request
.
getSession
().
getAttribute
(
"subjoin"
)
==
null
?
""
:
String
.
valueOf
(
request
.
getSession
().
getAttribute
(
"subjoin"
));
String
telReq
=
request
.
getSession
().
getAttribute
(
"tel"
)
==
null
?
""
:
String
.
valueOf
(
request
.
getSession
().
getAttribute
(
"tel"
));
Long
dateReq
=
request
.
getSession
().
getAttribute
(
"date"
)
==
null
?
0
:
Long
.
valueOf
(
String
.
valueOf
(
request
.
getSession
().
getAttribute
(
"date"
)));
//毫秒值
subjoinReq
=
"344942"
;
telReq
=
"13159872863"
;
String
subjoinReq
=
request
.
getSession
().
getAttribute
(
"subjoin"
)
==
null
?
""
:
String
.
valueOf
(
request
.
getSession
().
getAttribute
(
"subjoin"
));
String
telReq
=
request
.
getSession
().
getAttribute
(
"tel"
)
==
null
?
""
:
String
.
valueOf
(
request
.
getSession
().
getAttribute
(
"tel"
));
Long
dateReq
=
request
.
getSession
().
getAttribute
(
"date"
)
==
null
?
0
:
Long
.
valueOf
(
String
.
valueOf
(
request
.
getSession
().
getAttribute
(
"date"
)));
//毫秒值
subjoinReq
=
"344942"
;
telReq
=
"13159872863"
;
long
l
=
System
.
currentTimeMillis
();
//dateReq=(l-dateReq)/1000;
dateReq
=
30L
;
dateReq
=
30L
;
//获取验证码验证次数
TimescodeRegiEntity
timescodeRegiEntity
=
timescodeRegiDao
.
selectById
(
phone
);
if
(
timescodeRegiEntity
==
null
)
{
if
(
timescodeRegiEntity
==
null
)
{
throw
new
RRException
(
"该手机格未获取过验证码"
);
}
Integer
timesValidate
=
timescodeRegiEntity
.
getTimesValidate
();
//验证码输入错误次数;
//校验验证码
checkSubjoinRegi
(
subjoin
,
subjoinReq
,
phone
,
telReq
,
dateReq
,
timesValidate
);
checkSubjoinRegi
(
subjoin
,
subjoinReq
,
phone
,
telReq
,
dateReq
,
timesValidate
);
//存入数据库 密码加密
MemberEntity
memberEntity
=
new
MemberEntity
();
memberEntity
.
setUsername
(
userName
);
...
...
@@ -109,60 +119,128 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
@Override
public
void
updatePass
(
Map
<
String
,
Object
>
params
)
{
String
id
=
params
.
get
(
"id"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"id"
));
//用户ID
String
oldPass
=
params
.
get
(
"oldPass"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"oldPass"
));
//原始密码
String
newPass
=
params
.
get
(
"newPass"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"newPass"
));
//新密码
String
affirmPass
=
params
.
get
(
"affirmPass"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"affirmPass"
));
//确认密码
if
(
id
.
equals
(
""
)){
String
id
=
params
.
get
(
"id"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"id"
));
//用户ID
String
oldPass
=
params
.
get
(
"oldPass"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"oldPass"
));
//原始密码
String
newPass
=
params
.
get
(
"newPass"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"newPass"
));
//新密码
String
affirmPass
=
params
.
get
(
"affirmPass"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"affirmPass"
));
//确认密码
if
(
id
.
equals
(
""
))
{
throw
new
RRException
(
"请先登录"
);
}
if
(
oldPass
.
equals
(
""
)){
if
(
oldPass
.
equals
(
""
))
{
throw
new
RRException
(
"请输入旧密码"
);
}
if
(
newPass
.
equals
(
""
)){
if
(
newPass
.
equals
(
""
))
{
throw
new
RRException
(
"请输入新密码"
);
}
if
(
affirmPass
.
equals
(
""
)){
if
(
affirmPass
.
equals
(
""
))
{
throw
new
RRException
(
"请输入确认密码"
);
}
if
(!
newPass
.
equals
(
affirmPass
)){
if
(!
newPass
.
equals
(
affirmPass
))
{
throw
new
RRException
(
"两次密码信息不一致,请重新输入"
);
}
MemberEntity
memberEntity
=
memberDao
.
selectById
(
id
);
String
passData
=
memberEntity
.
getPass
();
String
passMD5
=
MD5Util
.
md5Encrypt32Upper
(
oldPass
);
if
(!
passMD5
.
equals
(
passData
)){
if
(!
passMD5
.
equals
(
passData
))
{
throw
new
RRException
(
"旧密码输入错误"
);
}
//修改密码
memberDao
.
updateByIdPassWord
(
Integer
.
valueOf
(
id
),
MD5Util
.
md5Encrypt32Upper
(
newPass
));
memberDao
.
updateByIdPassWord
(
Integer
.
valueOf
(
id
),
MD5Util
.
md5Encrypt32Upper
(
newPass
));
}
@Override
public
void
updatephone
(
Map
<
String
,
Object
>
params
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
//TODO tgl (接口未完成) 记录表:timescode_chPhone timescode_chPhone_ip 5分钟有效 每天3次 同IP10次
String
id
=
params
.
get
(
"id"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"id"
));
//用户ID
String
phone
=
params
.
get
(
"phone"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"phone"
));
//手机号码
String
verification
=
params
.
get
(
"verification"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"verification"
));
//验证码
if
(
id
.
equals
(
""
)){
String
ip
=
IPUtils
.
getIpAddr
(
request
);
String
id
=
params
.
get
(
"id"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"id"
));
//用户ID
String
phone
=
params
.
get
(
"phone"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"phone"
));
//手机号码
String
verification
=
params
.
get
(
"verification"
)
==
null
?
""
:
String
.
valueOf
(
params
.
get
(
"verification"
));
//验证码
if
(
id
.
equals
(
""
))
{
throw
new
RRException
(
"请先登录"
);
}
if
(
phone
.
equals
(
""
)){
int
flag
=
1
;
TimescodeChphoneEntity
timescodeChphoneEntity
=
timescodeChphoneDao
.
selectById
(
phone
);
if
(
timescodeChphoneEntity
!=
null
)
{
// 该手机号码是否发送过短信
Integer
times
=
timescodeChphoneEntity
.
getTimes
();
Integer
times_validate
=
timescodeChphoneEntity
.
getTimesValidate
();
String
date
=
timescodeChphoneEntity
.
getDate
();
String
date_1
=
DateUtils
.
getDay
();
if
(
date_1
.
equals
(
date
))
{
times
=
times
+
1
;
date
=
date_1
;
//更新数据
timescodeChphoneDao
.
updateById
(
new
TimescodeChphoneEntity
(
phone
,
date
,
times
,
times_validate
));
if
(
times
<=
3
)
{
flag
=
1
;
}
else
{
flag
=
0
;
}
}
else
{
//不是同一天修改 数据并初始化数据
times
=
1
;
date
=
date_1
;
timescodeChphoneDao
.
updateById
(
new
TimescodeChphoneEntity
(
phone
,
date
,
times
,
times_validate
));
flag
=
1
;
}
}
else
{
//没有手机号,新增数据
String
date
=
DateUtils
.
getDay
();
int
times
=
1
;
int
times_validate
=
0
;
//新增数据
timescodeChphoneDao
.
insert
(
new
TimescodeChphoneEntity
(
phone
,
date
,
times
,
times_validate
));
flag
=
1
;
}
// 以下添加同一个ip短信发送次数验证
int
flag_ip
=
1
;
TimescodeChphoneIpEntity
timescodeChphoneIpEntity
=
timescodeChphoneIpDao
.
selectById
(
ip
);
if
(
timescodeChphoneIpEntity
!=
null
)
{
Integer
times_ip
=
timescodeChphoneIpEntity
.
getTimesIp
();
String
date
=
timescodeChphoneIpEntity
.
getDate
();
String
date_1
=
DateUtils
.
getDay
();
if
(
date_1
.
equals
(
date
))
{
times_ip
=
times_ip
+
1
;
date
=
date_1
;
timescodeChphoneIpDao
.
updateById
(
new
TimescodeChphoneIpEntity
(
ip
,
date
,
times_ip
));
if
(
times_ip
<=
10
)
{
flag_ip
=
1
;
}
else
{
flag_ip
=
0
;
}
}
else
{
times_ip
=
1
;
date
=
date_1
;
timescodeChphoneIpDao
.
updateById
(
new
TimescodeChphoneIpEntity
(
ip
,
date
,
times_ip
));
flag_ip
=
1
;
}
}
else
{
String
date
=
DateUtils
.
getDay
();
int
times_ip
=
1
;
timescodeChphoneIpDao
.
insert
(
new
TimescodeChphoneIpEntity
(
ip
,
date
,
times_ip
));
flag_ip
=
1
;
}
// 同一个ip短信发送次数验证end
if
(
flag
==
0
)
{
throw
new
RRException
(
"同一手机号每日最多操作三次!"
);
}
else
if
(
flag_ip
==
0
)
{
throw
new
RRException
(
"同一ip每日最多操作十次!"
);
}
if
(
phone
.
equals
(
""
))
{
throw
new
RRException
(
"请输入手机号码"
);
}
if
(
verification
.
equals
(
""
)){
if
(
verification
.
equals
(
""
))
{
throw
new
RRException
(
"请输入验证码"
);
}
String
verUpdatephone
=
request
.
getSession
().
getAttribute
(
"ver
Updatephone
"
).
toString
();
//获取手机验证码
String
verUpdatephone
=
request
.
getSession
().
getAttribute
(
"ver
ification
"
).
toString
();
//获取手机验证码
long
verUpdateData
=
Long
.
valueOf
(
request
.
getSession
().
getAttribute
(
"verUpdateData"
).
toString
());
//获取手机有效时间
if
(!
verUpdatephone
.
equals
(
verification
)){
if
(!
verUpdatephone
.
equals
(
verification
))
{
throw
new
RRException
(
"验证码输入错误"
);
}
long
l
=
System
.
currentTimeMillis
();
if
(
l
-
verUpdateData
>
300
)
{
if
(
l
-
verUpdateData
>
300
)
{
throw
new
RRException
(
"验证码已超时"
);
}
memberDao
.
updateByIDPhone
(
Integer
.
valueOf
(
id
),
phone
);
memberDao
.
updateByIDPhone
(
Integer
.
valueOf
(
id
),
phone
);
}
...
...
@@ -171,32 +249,34 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
String
t123456
=
MD5Util
.
md5Encrypt32Upper
(
"t123456"
);
System
.
out
.
println
(
t123456
);
}
/**
* 以下为短信验证码验证次数判断
* @param sub 验证码
* @param reSub session存储的验证码
* @param tel 手机号
* @param reTel session存储的手机号
* @param time_diff session存储的毫秒值
* @param times_validate 验证码失败次数
*
* @param sub 验证码
* @param reSub session存储的验证码
* @param tel 手机号
* @param reTel session存储的手机号
* @param time_diff session存储的毫秒值
* @param times_validate 验证码失败次数
* @return
*/
public
boolean
checkSubjoinRegi
(
String
sub
,
String
reSub
,
String
tel
,
String
reTel
,
long
time_diff
,
int
times_validate
)
{
if
(
sub
.
equals
(
""
)){
public
boolean
checkSubjoinRegi
(
String
sub
,
String
reSub
,
String
tel
,
String
reTel
,
long
time_diff
,
int
times_validate
)
{
if
(
sub
.
equals
(
""
))
{
throw
new
RRException
(
"手机验证码不能为空!"
);
}
else
if
(
time_diff
>=
300
)
{
}
else
if
(
time_diff
>=
300
)
{
throw
new
RRException
(
"验证码已超时!"
);
}
else
if
(
times_validate
>=
3
)
{
}
else
if
(
times_validate
>=
3
)
{
throw
new
RRException
(
"该验证码输入错误满3次,已失效,请重新获取!"
);
}
else
{
if
(!
sub
.
equals
(
reSub
)){
if
(
times_validate
<=
3
)
{
times_validate
+=
1
;
timescodeRegiDao
.
updateByIdTimes_validate
(
reTel
,
times_validate
);
}
else
{
if
(!
sub
.
equals
(
reSub
))
{
if
(
times_validate
<=
3
)
{
times_validate
+=
1
;
timescodeRegiDao
.
updateByIdTimes_validate
(
reTel
,
times_validate
);
throw
new
RRException
(
"验证码已输入错误"
+
times_validate
+
"次(输入错误满3次时,该验证码失效)!"
);
}
}
if
(!
tel
.
equals
(
reTel
)){
if
(!
tel
.
equals
(
reTel
))
{
throw
new
RRException
(
"手机号码错误!"
);
}
}
...
...
@@ -204,19 +284,13 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
}
//用户名校验
public
boolean
checkUserName
(
String
logname
){
public
boolean
checkUserName
(
String
logname
)
{
String
t1
=
"^[0-9A-Za-z]{2,8}$"
;
//判断密码用户名和密码是否为数字,字母(数字或字母)
String
t2
=
"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{2,10}$"
;
//(数字和字母)
if
(
logname
.
matches
(
t2
))
{
String
t2
=
"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{2,10}$"
;
//(数字和字母)
if
(
logname
.
matches
(
t2
))
{
return
logname
.
matches
(
t2
);
}
else
{
}
else
{
//System.out.println("用户名只能是数字加字母,长度2-8位");
return
false
;
...
...
@@ -231,12 +305,12 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
}
public
boolean
checkPassWord
(
String
passWord
){
public
boolean
checkPassWord
(
String
passWord
)
{
String
t1
=
"^[0-9A-Za-z]{2,8}$"
;
//判断密码用户名和密码是否为数字,字母(数字或字母)
String
t2
=
"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{5,12}$"
;
//(数字和字母)
if
(
passWord
.
matches
(
t2
))
{
String
t2
=
"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{5,12}$"
;
//(数字和字母)
if
(
passWord
.
matches
(
t2
))
{
return
passWord
.
matches
(
t2
);
}
else
{
}
else
{
//System.out.println("用户名只能是数字加字母,长度2-8位");
return
false
;
...
...
@@ -245,14 +319,175 @@ public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> impl
/**
* 验证手机号 由于号码段不断的更新,只需要判断手机号有11位,并且全是数字以及1开头等
*
* @param phoneNumber 手机号码
* @return
*/
private
static
boolean
matchPhoneNumber
(
String
phoneNumber
)
{
String
regex
=
"1[358][0-9]{9}"
;
if
(
phoneNumber
==
null
||
phoneNumber
.
length
()<=
0
)
{
if
(
phoneNumber
==
null
||
phoneNumber
.
length
()
<=
0
)
{
return
false
;
}
return
Pattern
.
matches
(
regex
,
phoneNumber
);
}
@Override
public
String
getVerificationCode
(
Map
<
String
,
Object
>
params
,
HttpServletRequest
request
,
HttpServletResponse
response
)
{
//验证码随机6位数字(验证码)
String
pass
=
(
int
)
((
Math
.
random
()
*
9
+
1
)
*
100000
)
+
""
;
//获取IP(可能不是真实IP)
String
ip
=
IPUtils
.
getIpAddr
(
request
);
//手机号
String
phone
=
String
.
valueOf
(
params
.
get
(
"phone"
)
==
null
?
""
:
params
.
get
(
"phone"
));
String
userName
=
String
.
valueOf
(
params
.
get
(
"userName"
)
==
null
?
""
:
params
.
get
(
"userName"
));
//判断手机号码格式
if
(!
matchPhoneNumber
(
phone
))
{
throw
new
RRException
(
"手机格式不正确,请重新填写"
);
}
//TODO tgl 判断手机号码是否在黑名单内
//写入session
HttpSession
session
=
request
.
getSession
();
session
.
setAttribute
(
"verification"
,
pass
);
//验证码
session
.
setAttribute
(
"tel"
,
phone
);
//手机号
session
.
setAttribute
(
"date"
,
System
.
currentTimeMillis
());
//毫秒值
//发送状态
String
state
=
""
;
// 以下添加同一个手机号短信发送次数验证
int
flag
=
1
;
TimescodeChphoneEntity
timescodeChphoneEntity
=
timescodeChphoneDao
.
selectById
(
phone
);
if
(
timescodeChphoneEntity
!=
null
)
{
// 该手机号码是否发送过短信
Integer
times
=
timescodeChphoneEntity
.
getTimes
();
Integer
times_validate
=
timescodeChphoneEntity
.
getTimesValidate
();
String
date
=
timescodeChphoneEntity
.
getDate
();
String
date_1
=
DateUtils
.
getDay
();
if
(
date_1
.
equals
(
date
))
{
times
=
times
+
1
;
date
=
date_1
;
//更新数据
timescodeChphoneDao
.
updateById
(
new
TimescodeChphoneEntity
(
phone
,
date
,
times
,
times_validate
));
if
(
times
<=
3
)
{
flag
=
1
;
}
else
{
flag
=
0
;
}
}
else
{
//不是同一天修改 数据并初始化数据
times
=
1
;
date
=
date_1
;
timescodeChphoneDao
.
updateById
(
new
TimescodeChphoneEntity
(
phone
,
date
,
times
,
times_validate
));
flag
=
1
;
}
}
else
{
//没有手机号,新增数据
String
date
=
DateUtils
.
getDay
();
int
times
=
1
;
int
times_validate
=
0
;
//新增数据
timescodeChphoneDao
.
insert
(
new
TimescodeChphoneEntity
(
phone
,
date
,
times
,
times_validate
));
flag
=
1
;
}
// 同一个手机号短信发送次数验证end
// 以下添加同一个ip短信发送次数验证
int
flag_ip
=
1
;
TimescodeChphoneIpEntity
timescodeChphoneIpEntity
=
timescodeChphoneIpDao
.
selectById
(
ip
);
if
(
timescodeChphoneIpEntity
!=
null
)
{
Integer
times_ip
=
timescodeChphoneIpEntity
.
getTimesIp
();
String
date
=
timescodeChphoneIpEntity
.
getDate
();
String
date_1
=
DateUtils
.
getDay
();
if
(
date_1
.
equals
(
date
))
{
times_ip
=
times_ip
+
1
;
date
=
date_1
;
timescodeChphoneIpDao
.
updateById
(
new
TimescodeChphoneIpEntity
(
ip
,
date
,
times_ip
));
if
(
times_ip
<=
10
)
{
flag_ip
=
1
;
}
else
{
flag_ip
=
0
;
}
}
else
{
times_ip
=
1
;
date
=
date_1
;
timescodeChphoneIpDao
.
updateById
(
new
TimescodeChphoneIpEntity
(
ip
,
date
,
times_ip
));
flag_ip
=
1
;
}
}
else
{
String
date
=
DateUtils
.
getDay
();
int
times_ip
=
1
;
timescodeChphoneIpDao
.
insert
(
new
TimescodeChphoneIpEntity
(
ip
,
date
,
times_ip
));
flag_ip
=
1
;
}
// 同一个ip短信发送次数验证end
if
(
flag
==
0
)
{
throw
new
RRException
(
"同一手机号每日最多操作三次!"
);
}
else
if
(
flag_ip
==
0
)
{
throw
new
RRException
(
"同一ip每日最多操作十次!"
);
}
else
{
//flag=1时 ,发送短信
// //********* 以下调用手机发短信接口 ********* //
String
res
=
"res"
;
String
account
=
"gs1cn"
;
// 此处按接口文档填写
String
password
=
"test@2021"
;
// 此处按接口文档填写
String
userid
=
"9220"
;
// 此处按接口文档填写
String
content
=
"您在中国物品编码中心网站修改手机号码的手机验证码为:"
+
pass
+
",五分钟内有效,请正确输入!同一手机号每日最多操作三次!同一个ip每日最多操作十次!【中国物品编码中心】"
;
try
{
NameValuePair
[]
data
=
{
new
NameValuePair
(
"action"
,
"send"
),
new
NameValuePair
(
"userid"
,
userid
),
new
NameValuePair
(
"account"
,
account
),
new
NameValuePair
(
"password"
,
password
),
new
NameValuePair
(
"mobile"
,
phone
),
new
NameValuePair
(
"content"
,
content
),
new
NameValuePair
(
"sendTime"
,
DateUtils
.
getDay
()),
new
NameValuePair
(
"mobilenumber"
,
"2"
),
new
NameValuePair
(
"countnumber"
,
"2"
),
new
NameValuePair
(
"telephonenumber"
,
"0"
),
};
String
post
=
sendPost
(
"http://39.106.204.178:8888/sms.aspx"
,
data
);
Document
document
=
DocumentHelper
.
parseText
(
post
);
// 获取returnstatus节点对象
String
returnstatus
=
document
.
selectSingleNode
(
"//returnstatus"
).
getText
();
if
(
returnstatus
.
equals
(
"Success"
))
{
//保存验证码信息log_message表
state
=
"发送成功"
;
return
"Success"
;
}
else
if
(
returnstatus
.
equals
(
"Faild"
))
{
state
=
"发送失败"
;
throw
new
RRException
(
"验证码发送失败:"
+
document
.
selectSingleNode
(
"//message"
).
getText
());
}
else
{
state
=
"发送失败"
;
throw
new
RRException
(
"验证码发送失败,请稍后再试!"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RRException
(
"网络错误,无法连接到服务器!"
);
}
finally
{
logMessageDao
.
insert
(
new
LogMessageEntity
(
userName
,
phone
,
new
Date
(),
pass
,
ip
,
request
.
getRequestURL
().
toString
(),
"注册新用户"
,
state
));
}
}
}
/**
* 发送post 数据
* @param urls
* @return
*/
public
static
String
sendPost
(
String
urls
,
NameValuePair
[]
data
)
{
try
{
PostMethod
postMethod
=
null
;
postMethod
=
new
PostMethod
(
urls
)
;
postMethod
.
setRequestHeader
(
"Content-Type"
,
"application/x-www-form-urlencoded;charset=utf-8"
)
;
//参数设置,需要注意的就是里边不能传NULL,要传空字符串
postMethod
.
setRequestBody
(
data
);
org
.
apache
.
commons
.
httpclient
.
HttpClient
httpClient
=
new
org
.
apache
.
commons
.
httpclient
.
HttpClient
();
int
response
=
httpClient
.
executeMethod
(
postMethod
);
// 执行POST方法
String
result
=
postMethod
.
getResponseBodyAsString
()
;
return
result
;
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
.
getMessage
());
}
}
}
\ No newline at end of file
src/main/java/io/office/modules/manage/service/impl/TimescodeRegiServiceImpl.java
View file @
982e7701
...
...
@@ -103,7 +103,7 @@ public class TimescodeRegiServiceImpl extends ServiceImpl<TimescodeRegiDao, Time
//写入session
HttpSession
session
=
request
.
getSession
();
session
.
setAttribute
(
"subjoin"
,
pass
);
//验证码
session
.
setAttribute
(
"tel"
,
p
ass
);
//手机号
session
.
setAttribute
(
"tel"
,
p
hone
);
//手机号
session
.
setAttribute
(
"date"
,
System
.
currentTimeMillis
());
//毫秒值
//发送状态
...
...
src/main/resources/mapper/manage/TimescodeChphoneDao.xml
0 → 100644
View file @
982e7701
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"io.office.modules.manage.dao.TimescodeChphoneDao"
>
<!-- 可根据自己的需求,是否要使用 -->
<resultMap
type=
"io.office.modules.manage.entity.TimescodeChphoneEntity"
id=
"timescodeChphoneMap"
>
<result
property=
"phone"
column=
"phone"
/>
<result
property=
"date"
column=
"date"
/>
<result
property=
"times"
column=
"times"
/>
<result
property=
"timesValidate"
column=
"times_validate"
/>
</resultMap>
</mapper>
\ No newline at end of file
src/main/resources/mapper/manage/TimescodeChphoneIpDao.xml
0 → 100644
View file @
982e7701
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"io.office.modules.manage.dao.TimescodeChphoneIpDao"
>
<!-- 可根据自己的需求,是否要使用 -->
<resultMap
type=
"io.office.modules.manage.entity.TimescodeChphoneIpEntity"
id=
"timescodeChphoneIpMap"
>
<result
property=
"ip"
column=
"ip"
/>
<result
property=
"date"
column=
"date"
/>
<result
property=
"timesIp"
column=
"times_ip"
/>
</resultMap>
</mapper>
\ No newline at end of file
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