Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
aa70eac5
Commit
aa70eac5
authored
Mar 12, 2021
by
giaogiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改手机号
parent
7fa83bef
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
147 additions
and
20 deletions
+147
-20
common/src/main/java/com/sien/common/controller/AppSmsController.java
+24
-4
common/src/main/java/com/sien/common/controller/AppUserController.java
+1
-1
common/src/main/java/com/sien/common/param/app/AppUserPhoneUpdateParam.java
+10
-0
common/src/main/java/com/sien/common/service/AppSmsService.java
+20
-2
common/src/main/java/com/sien/common/service/AppUserApiService.java
+3
-2
common/src/main/java/com/sien/common/service/impl/AppSmsServiceImpl.java
+59
-4
common/src/main/java/com/sien/common/service/impl/AppUserApiServiceImpl.java
+13
-4
config/src/main/resources/static/i18n/messages_zh_CN.properties
+3
-1
framework/src/main/java/io/geekidea/springbootplus/framework/common/api/ApiCode.java
+14
-2
No files found.
common/src/main/java/com/sien/common/controller/AppSmsController.java
View file @
aa70eac5
...
...
@@ -41,15 +41,35 @@ public class AppSmsController extends BaseController {
}
/**
*
获取修改手机号的
验证码
*
修改手机号,向旧手机号发
验证码
*/
@GetMapping
(
"/updatePhoneCode"
)
@OperationLog
(
name
=
"
获取修改手机号的
验证码"
,
type
=
OperationLogType
.
INFO
)
@ApiOperation
(
value
=
"
获取修改手机号的验证码
"
,
response
=
Object
.
class
,
notes
=
"本地环境默认666666"
)
@OperationLog
(
name
=
"
修改手机号,向旧手机号发
验证码"
,
type
=
OperationLogType
.
INFO
)
@ApiOperation
(
value
=
"
向旧手机号发验证码-修改手机号
"
,
response
=
Object
.
class
,
notes
=
"本地环境默认666666"
)
public
ApiResult
<
Object
>
updatePhoneCode
()
throws
Exception
{
return
appSmsService
.
updatePhoneCodeSendToOld
();
}
/**
* 修改手机号,向旧手机号发验证码
*/
@GetMapping
(
"/updatePhoneCodeToNew"
)
@OperationLog
(
name
=
"修改手机号,向新手机号发验证码"
,
type
=
OperationLogType
.
INFO
)
@ApiOperation
(
value
=
"向新手机号发验证码-修改手机号"
,
response
=
Object
.
class
,
notes
=
"本地环境默认666666"
)
public
ApiResult
<
Object
>
updatePhoneCodeSendToNew
(
@RequestParam
String
phoneArea
,
@RequestParam
String
phone
)
throws
Exception
{
return
appSmsService
.
updatePhoneCodeSendToNew
(
phoneArea
,
phone
);
}
return
appSmsService
.
updatePhoneCode
();
/**
* 校验旧手机验证码
*/
@GetMapping
(
"/checkPhoneCodeOld"
)
@OperationLog
(
name
=
"校验旧手机验证码"
,
type
=
OperationLogType
.
INFO
)
@ApiOperation
(
value
=
"校验旧手机验证码-修改手机号"
,
response
=
Object
.
class
,
notes
=
"本地环境默认666666"
)
public
ApiResult
<
Boolean
>
checkPhoneCodeOld
(
@RequestParam
String
code
)
throws
Exception
{
return
appSmsService
.
checkPhoneCodeOld
(
code
);
}
}
common/src/main/java/com/sien/common/controller/AppUserController.java
View file @
aa70eac5
...
...
@@ -81,7 +81,7 @@ public class AppUserController extends BaseController {
@ApiOperation
(
value
=
"修改手机号"
,
response
=
ApiResult
.
class
)
public
ApiResult
<
Boolean
>
updatePhone
(
@RequestBody
AppUserPhoneUpdateParam
userPhoneUpdateParam
)
throws
Exception
{
return
appUserApiService
.
updatePhone
(
userPhoneUpdateParam
.
getPhoneArea
(),
userPhoneUpdateParam
.
getPhone
(),
userPhoneUpdateParam
.
getCode
());
return
appUserApiService
.
updatePhone
(
userPhoneUpdateParam
.
getPhoneArea
(),
userPhoneUpdateParam
.
getPhone
(),
userPhoneUpdateParam
.
getCode
()
,
userPhoneUpdateParam
.
getCodeNew
()
);
}
// @GetMapping("/userInfoList")
...
...
common/src/main/java/com/sien/common/param/app/AppUserPhoneUpdateParam.java
View file @
aa70eac5
...
...
@@ -2,6 +2,7 @@ package com.sien.common.param.app;
import
io.geekidea.springbootplus.framework.common.entity.BaseEntity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
...
...
@@ -17,7 +18,16 @@ import lombok.experimental.Accessors;
@EqualsAndHashCode
(
callSuper
=
true
)
@ApiModel
(
value
=
"AppUserPhoneUpdateParam"
)
public
class
AppUserPhoneUpdateParam
extends
BaseEntity
{
@ApiModelProperty
(
"新手机区号"
)
private
String
phoneArea
;
@ApiModelProperty
(
"新手机号"
)
private
String
phone
;
@ApiModelProperty
(
"旧手机号的验证码"
)
private
String
code
;
@ApiModelProperty
(
"新手机号的验证码"
)
private
String
codeNew
;
}
common/src/main/java/com/sien/common/service/AppSmsService.java
View file @
aa70eac5
...
...
@@ -5,14 +5,29 @@ import io.geekidea.springbootplus.framework.common.api.ApiResult;
public
interface
AppSmsService
{
void
deleteRegisterCode
(
String
area
,
String
number
);
void
deleteUpdatePhoneCode
(
String
area
,
String
number
);
void
deleteUpdatePhoneCodeNew
(
String
area
,
String
number
);
/**
* 获取注册验证码
*/
ApiResult
<
Object
>
registerOrLoginCode
(
String
phoneArea
,
String
phone
);
ApiResult
<
Object
>
updatePhoneCode
()
throws
Exception
;
ApiResult
<
Object
>
updatePhoneCodeSendToOld
()
throws
Exception
;
/**
* 修改手机号,向新手机号发验证码
*/
ApiResult
<
Object
>
updatePhoneCodeSendToNew
(
String
phoneArea
,
String
phone
);
/**
* 修改手机号,校验旧手机验证码
*/
ApiResult
<
Boolean
>
checkPhoneCodeOld
(
String
code
)
throws
Exception
;
/**
* 获取注册验证码
...
...
@@ -28,7 +43,10 @@ public interface AppSmsService {
* @return
*/
boolean
equalsRegisterCode
(
String
area
,
String
number
,
String
code
);
boolean
equalsUpdatePhoneCode
(
String
area
,
String
number
,
String
code
);
boolean
equalsUpdatePhoneCodeOld
(
String
area
,
String
number
,
String
code
);
boolean
equalsUpdatePhoneCodeNew
(
String
area
,
String
number
,
String
code
);
/**
* 校验验登陆证码
...
...
common/src/main/java/com/sien/common/service/AppUserApiService.java
View file @
aa70eac5
package
com
.
sien
.
common
.
service
;
import
com.sien.common.entity.AppUser
;
import
com.sien.common.param.app.AppSmsRegisterParam
;
import
com.sien.common.param.app.AppUserInfoParam
;
import
com.sien.common.vo.app.LoginAppUserTokenVo
;
import
com.sien.common.entity.AppUser
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
java.util.List
;
...
...
@@ -33,13 +33,14 @@ public interface AppUserApiService {
/**
* 修改手机号
*
* @param phoneArea
* @param phone
* @param code
* @return
* @throws Exception
*/
ApiResult
<
Boolean
>
updatePhone
(
String
phoneArea
,
String
phone
,
String
code
)
throws
Exception
;
ApiResult
<
Boolean
>
updatePhone
(
String
phoneArea
,
String
phone
,
String
code
,
String
codeNew
)
throws
Exception
;
/**
...
...
common/src/main/java/com/sien/common/service/impl/AppSmsServiceImpl.java
View file @
aa70eac5
package
com
.
sien
.
common
.
service
.
impl
;
import
cn.hutool.core.util.RandomUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.sien.common.entity.AppUser
;
import
com.sien.common.service.AppSmsService
;
import
com.sien.common.service.AppUserService
;
import
com.sien.common.sms.SendSms
;
...
...
@@ -48,12 +50,18 @@ public class AppSmsServiceImpl implements AppSmsService {
* 注册 短信验证码redis的key值
*/
private
static
final
String
SMS_REGIEST
=
"sms:app:register:%s_%s"
;
/**
* 修改 短信验证码redis的key值
*/
private
static
final
String
SMS_UPDATE
=
"sms:app:update:%s_%s"
;
/**
* 修改 短信验证码redis的key值,新手机
*/
private
static
final
String
SMS_UPDATE_NEW
=
"sms:app:updateNew:%s_%s"
;
/**
* 短信验证码redis的key值
*/
private
static
final
String
SMS_LOGIN
=
"sms:app:login:%s_%s"
;
...
...
@@ -65,9 +73,13 @@ public class AppSmsServiceImpl implements AppSmsService {
@Override
public
void
deleteUpdatePhoneCode
(
String
area
,
String
number
)
{
redisTemplate
.
delete
(
String
.
format
(
SMS_UPDATE
,
area
,
number
));
}
@Override
public
void
deleteUpdatePhoneCodeNew
(
String
area
,
String
number
)
{
redisTemplate
.
delete
(
String
.
format
(
SMS_UPDATE_NEW
,
area
,
number
));
}
...
...
@@ -77,10 +89,46 @@ public class AppSmsServiceImpl implements AppSmsService {
}
@Override
public
ApiResult
<
Object
>
updatePhoneCode
()
throws
Exception
{
public
ApiResult
<
Object
>
updatePhoneCode
SendToOld
()
throws
Exception
{
JwtToken
jwtToken
=
(
JwtToken
)
SecurityUtils
.
getSubject
().
getPrincipal
();
AppUserQueryVo
appUserById
=
appUserService
.
getAppUserById
(
jwtToken
.
getUserId
());
return
getSmsCodeApiResult
(
String
.
format
(
SMS_UPDATE
,
appUserById
.
getPhoneArea
(),
appUserById
.
getPhone
()),
appUserById
.
getPhoneArea
(),
appUserById
.
getPhone
());
// 向旧手机发送验证码
String
key
=
String
.
format
(
SMS_UPDATE
,
appUserById
.
getPhoneArea
(),
appUserById
.
getPhone
());
ApiResult
<
Object
>
smsCodeApiResult
=
getSmsCodeApiResult
(
key
,
appUserById
.
getPhoneArea
(),
appUserById
.
getPhone
());
return
smsCodeApiResult
;
}
@Override
public
ApiResult
<
Object
>
updatePhoneCodeSendToNew
(
String
phoneArea
,
String
phone
)
{
// 判断手机号是否已经注册
AppUser
one
=
appUserService
.
getOne
(
new
QueryWrapper
<
AppUser
>().
lambda
()
.
eq
(
AppUser:
:
getPhoneArea
,
phoneArea
)
.
eq
(
AppUser:
:
getPhone
,
phone
));
if
(
one
!=
null
)
{
return
ApiResult
.
fail
(
ApiCode
.
UPDATA_PHONE_USE
,
null
);
}
// 向新手机发送验证码
String
key
=
String
.
format
(
SMS_UPDATE_NEW
,
phoneArea
,
phone
);
ApiResult
<
Object
>
smsCodeApiResult
=
getSmsCodeApiResult
(
key
,
phoneArea
,
phone
);
return
smsCodeApiResult
;
}
@Override
public
ApiResult
<
Boolean
>
checkPhoneCodeOld
(
String
code
)
throws
Exception
{
JwtToken
jwtToken
=
(
JwtToken
)
SecurityUtils
.
getSubject
().
getPrincipal
();
AppUserQueryVo
appUserById
=
appUserService
.
getAppUserById
(
jwtToken
.
getUserId
());
boolean
equalsRegisterCode
=
this
.
equalsUpdatePhoneCodeOld
(
appUserById
.
getPhoneArea
(),
appUserById
.
getPhone
(),
code
);
if
(!
equalsRegisterCode
)
{
return
ApiResult
.
fail
(
ApiCode
.
SMS_CODE_ERROR
);
}
return
ApiResult
.
ok
();
}
/**
...
...
@@ -128,10 +176,17 @@ public class AppSmsServiceImpl implements AppSmsService {
}
@Override
public
boolean
equalsUpdatePhoneCode
(
String
area
,
String
number
,
String
code
)
{
public
boolean
equalsUpdatePhoneCode
Old
(
String
area
,
String
number
,
String
code
)
{
return
equalsSms
(
SMS_UPDATE
,
area
,
number
,
code
);
}
@Override
public
boolean
equalsUpdatePhoneCodeNew
(
String
area
,
String
number
,
String
code
)
{
return
equalsSms
(
SMS_UPDATE_NEW
,
area
,
number
,
code
);
}
private
boolean
equalsSms
(
String
type
,
String
area
,
String
number
,
String
code
)
{
String
formatKey
=
String
.
format
(
type
,
area
,
number
);
...
...
common/src/main/java/com/sien/common/service/impl/AppUserApiServiceImpl.java
View file @
aa70eac5
...
...
@@ -60,18 +60,27 @@ public class AppUserApiServiceImpl implements AppUserApiService {
}
@Override
public
ApiResult
<
Boolean
>
updatePhone
(
String
phoneArea
,
String
phone
,
String
code
)
throws
Exception
{
public
ApiResult
<
Boolean
>
updatePhone
(
String
phoneArea
,
String
phone
,
String
code
,
String
codeNew
)
throws
Exception
{
JwtToken
jwtToken
=
(
JwtToken
)
SecurityUtils
.
getSubject
().
getPrincipal
();
AppUserQueryVo
appUserById
=
appUserService
.
getAppUserById
(
jwtToken
.
getUserId
());
// 校验验证码
boolean
equalsRegisterCode
=
appSmsService
.
equalsUpdatePhoneCode
(
appUserById
.
getPhoneArea
(),
appUserById
.
getPhone
(),
code
);
// 校验
旧手机
验证码
boolean
equalsRegisterCode
=
appSmsService
.
equalsUpdatePhoneCode
Old
(
appUserById
.
getPhoneArea
(),
appUserById
.
getPhone
(),
code
);
if
(!
equalsRegisterCode
)
{
return
ApiResult
.
fail
(
ApiCode
.
SMS_CODE_ERROR
);
}
// 删除已使用的验证码
// 校验新手机验证码
boolean
equalsRegisterCodeNew
=
appSmsService
.
equalsUpdatePhoneCodeNew
(
phoneArea
,
phone
,
codeNew
);
if
(!
equalsRegisterCodeNew
)
{
return
ApiResult
.
fail
(
ApiCode
.
SMS_CODE_ERROR_NEW
);
}
// 删除已使用的旧手机验证码
appSmsService
.
deleteUpdatePhoneCode
(
appUserById
.
getPhoneArea
(),
appUserById
.
getPhone
());
// 删除已使用的新手机验证码
appSmsService
.
deleteUpdatePhoneCodeNew
(
phoneArea
,
phone
);
// 判断手机号是否已经注册
AppUser
one
=
appUserService
.
getOne
(
new
QueryWrapper
<
AppUser
>().
lambda
()
...
...
config/src/main/resources/static/i18n/messages_zh_CN.properties
View file @
aa70eac5
...
...
@@ -76,6 +76,8 @@ api.response.code.JWTDECODE_EXCEPTION=Token解析异常
#*/
api.response.code.HTTP_REQUEST_METHOD_NOT_SUPPORTED_EXCEPTION
=
默认的异常处理
api.response.code.user.PWD_OR_USERNAME_ERROR
=
账号或密码错误
api.response.code.user.SMS_CODE_ERROR
=
验证码错误
api.response.code.user.SMS_CODE_ERROR
=
旧手机号
验证码错误
api.response.code.user.USER_NOT_FOUND
=
用户不存在
api.response.code.user.USER_WECHAT_CODE
=
微信code错误
api.response.code.user.SMS_CODE_ERROR_NEW
=
新手机号验证码错误
api.response.code.user.UPDATA_PHONE_USE
=
绑定手机已经被使用
framework/src/main/java/io/geekidea/springbootplus/framework/common/api/ApiCode.java
View file @
aa70eac5
...
...
@@ -110,9 +110,16 @@ public enum ApiCode {
PWD_OR_USERNAME_ERROR
(
6001
,
"api.response.code.user.PWD_OR_USERNAME_ERROR"
),
/**
* 验证码错误
*
旧手机号
验证码错误
*/
SMS_CODE_ERROR
(
6002
,
"api.response.code.user.SMS_CODE_ERROR"
),
SMS_CODE_ERROR
(
6005
,
"api.response.code.user.SMS_CODE_ERROR"
),
/**
* 新手机号验证码错误
*/
SMS_CODE_ERROR_NEW
(
6002
,
"api.response.code.user.SMS_CODE_ERROR_NEW"
),
/**
* 用户不存在
*/
...
...
@@ -123,6 +130,11 @@ public enum ApiCode {
*/
USER_WECHAT_CODE
(
6004
,
"api.response.code.user.USER_WECHAT_CODE"
),
/**
* 绑定手机已经被使用
*/
UPDATA_PHONE_USE
(
6006
,
"api.response.code.user.UPDATA_PHONE_USE"
),
;
private
final
int
code
;
...
...
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