Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
S
syyl
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
svn
syyl
Commits
873018f4
提交
873018f4
authored
11月 11, 2020
作者:
renjiancai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
上级
91749a32
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
159 行增加
和
0 行删除
+159
-0
SmsClient.java
...main/java/com/zrqx/sysuser/fg/client/third/SmsClient.java
+24
-0
SmsHystric.java
...ain/java/com/zrqx/sysuser/fg/client/third/SmsHystric.java
+22
-0
FgPermissionsController.java
...er/fg/controller/permissions/FgPermissionsController.java
+113
-0
没有找到文件。
com.zrqx.sysuser/src/main/java/com/zrqx/sysuser/fg/client/third/SmsClient.java
0 → 100644
浏览文件 @
873018f4
package
com
.
zrqx
.
sysuser
.
fg
.
client
.
third
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
com.zrqx.core.form.third.sms.SmsForm
;
import
com.zrqx.core.util.response.CallBack
;
/**
* 手机短信
*/
@FeignClient
(
value
=
"third"
,
fallback
=
SmsHystric
.
class
)
public
interface
SmsClient
{
/**
* 发送手机短信
* @param smsForm
* @return
*/
@PostMapping
(
"/sms/send"
)
public
CallBack
<
String
>
sendSms
(
@RequestBody
SmsForm
smsForm
);
}
com.zrqx.sysuser/src/main/java/com/zrqx/sysuser/fg/client/third/SmsHystric.java
0 → 100644
浏览文件 @
873018f4
package
com
.
zrqx
.
sysuser
.
fg
.
client
.
third
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
com.zrqx.core.form.third.sms.SmsForm
;
import
com.zrqx.core.util.response.CallBack
;
@Component
public
class
SmsHystric
implements
SmsClient
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SmsHystric
.
class
);
@Override
public
CallBack
<
String
>
sendSms
(
@RequestBody
SmsForm
smsForm
){
logger
.
info
(
" 发送: "
+
smsForm
.
getPhone
()
+
" 验证码: "
+
smsForm
.
getCode
()
+
",短信接口不可用"
);
return
null
;
}
}
com.zrqx.sysuser/src/main/java/com/zrqx/sysuser/fg/controller/permissions/FgPermissionsController.java
浏览文件 @
873018f4
package
com
.
zrqx
.
sysuser
.
fg
.
controller
.
permissions
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
java.util.stream.Collectors
;
import
javax.imageio.ImageIO
;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.commons.lang.StringUtils
;
...
...
@@ -18,27 +23,35 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.mysql.fabric.xmlrpc.base.Member
;
import
com.zrqx.core.constant.sysuser.SysUserRequestPath
;
import
com.zrqx.core.enums.StatusEnum
;
import
com.zrqx.core.enums.sysuser.UserTypeEnum
;
import
com.zrqx.core.exception.BaseException
;
import
com.zrqx.core.exception.BusinessValidateException
;
import
com.zrqx.core.form.sysuser.bg.user.UpdateNewPasswordForm
;
import
com.zrqx.core.form.sysuser.bg.user.UpdatePasswordForm
;
import
com.zrqx.core.form.sysuser.fg.user.LoginForm
;
import
com.zrqx.core.form.sysuser.fg.user.LoginUserInfo
;
import
com.zrqx.core.form.third.sms.SmsForm
;
import
com.zrqx.core.model.sysuser.role.Role
;
import
com.zrqx.core.model.sysuser.user.User
;
import
com.zrqx.core.util.JsonUtil.JsonUtil
;
import
com.zrqx.core.util.bean.BeanUtils
;
import
com.zrqx.core.util.datatype.ArrayUtils
;
import
com.zrqx.core.util.datatype.PasswordUtil
;
import
com.zrqx.core.util.datatype.UUIDUtil
;
import
com.zrqx.core.util.datatype.VerifyUtil
;
import
com.zrqx.core.util.response.CallBack
;
import
com.zrqx.sysuser.commons.redis.Redis
;
import
com.zrqx.sysuser.fg.client.third.SmsClient
;
import
com.zrqx.sysuser.fg.service.role.FgRoleService
;
import
com.zrqx.sysuser.fg.service.user.FgUserService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
sun.misc.BASE64Encoder
;
import
tk.mybatis.mapper.entity.Example
;
/**
* 登录Controller
...
...
@@ -56,6 +69,8 @@ public class FgPermissionsController {
@Autowired
StringRedisTemplate
stringRedisTemplate
;
@Autowired
private
SmsClient
smsClient
;
@Autowired
private
Redis
redis
;
...
...
@@ -173,4 +188,102 @@ public class FgPermissionsController {
userService
.
updateByPrimaryKeySelective
(
m
);
return
CallBack
.
success
(
"成功"
);
}
@ApiOperation
(
value
=
"重置密码-1 发送手机短信"
,
notes
=
"0:成功;16:60s内不能再次发送;18:短信验证码发送失败;"
)
@GetMapping
(
value
=
"/password"
+
1
)
public
CallBack
<
String
>
resetPassword1
(
String
phone
)
throws
Exception
{
if
(!
userService
.
isExistByPhone
(
null
,
phone
))
{
throw
new
BaseException
(
99
,
"手机号未注册"
);
}
String
sendTime
=
phone
+
"password"
;
if
(
redis
.
get
(
sendTime
)
!=
null
)
{
throw
new
BaseException
(
16
,
"60s内不能再次发送"
);
}
SmsForm
ssf
=
new
SmsForm
();
ssf
.
setPhone
(
phone
);
String
code
=
PasswordUtil
.
createPassword
(
6
,
1
);
ssf
.
setCode
(
code
);
ssf
.
setType
(
2
);
/// 更换手机号验证验证码
CallBack
<
String
>
sms
=
smsClient
.
sendSms
(
ssf
);
if
(
sms
!=
null
&&
sms
.
isStatus
())
{
redis
.
set
(
phone
,
code
,
60
*
5
,
TimeUnit
.
SECONDS
);
redis
.
set
(
sendTime
,
"60"
,
60
);
}
else
{
throw
new
BaseException
(
18
,
"短信验证码发送失败"
);
}
return
CallBack
.
success
(
"发送成功"
);
}
@ApiOperation
(
value
=
"重置密码-2 验证手机短信"
,
notes
=
"0:成功;3:验证码不能为空;11:验证码已失效,请重新发送;20:验证码不能为空;21:手机号不能为空;"
)
@GetMapping
(
value
=
"/password"
+
2
)
public
CallBack
<
String
>
resetPassword2
(
String
phone
,
String
code
)
throws
Exception
{
if
(
StringUtils
.
isBlank
(
phone
))
{
throw
new
BaseException
(
21
,
"手机号不能为空。"
);
}
if
(
StringUtils
.
isBlank
(
code
))
{
throw
new
BaseException
(
20
,
"验证码不能为空。"
);
}
String
redisCode
=
redis
.
get
(
phone
);
if
(
redisCode
==
null
)
{
throw
new
BaseException
(
11
,
"验证码已失效,请重新发送。"
);
}
if
(!
code
.
toLowerCase
().
equals
(
redisCode
.
toLowerCase
()))
{
throw
new
BaseException
(
3
,
"验证码有误!"
);
}
redis
.
set
(
phone
,
phone
);
return
CallBack
.
success
(
"验证成功"
);
}
@ApiOperation
(
value
=
"重置密码-3 输入新密码"
,
notes
=
"0:成功;2:验证码不能为空;3:两次密码不一致;21:手机号不能为空;"
)
@PostMapping
(
value
=
"/password"
+
3
)
public
CallBack
<
String
>
resetPassword3
(
@RequestBody
UpdateNewPasswordForm
form
)
throws
Exception
{
if
(
StringUtils
.
isBlank
(
form
.
getPhone
()))
{
throw
new
BaseException
(
21
,
"手机号不能为空"
);
}
if
(
StringUtils
.
isBlank
(
form
.
getNewPassword1
())
||
StringUtils
.
isBlank
(
form
.
getNewPassword2
()))
{
throw
new
BaseException
(
2
,
"密码不能为空"
);
}
if
(!
form
.
getNewPassword1
().
equals
(
form
.
getNewPassword2
()))
{
throw
new
BaseException
(
3
,
"两次密码不一致"
);
}
String
redisCode
=
redis
.
get
(
form
.
getPhone
());
if
(
redisCode
==
null
||
!
form
.
getPhone
().
equals
(
redisCode
))
{
throw
new
BaseException
(
99
,
"请按照流程重置密码"
);
}
Example
example
=
userService
.
createExample
();
example
.
createCriteria
().
andEqualTo
(
"phone"
,
form
.
getPhone
());
User
user
=
new
User
();
user
.
setPassword
(
form
.
getNewPassword1
());
userService
.
UpdateByExampleSelective
(
user
,
example
);
redis
.
delete
(
form
.
getPhone
());
return
CallBack
.
success
(
"success"
);
}
@ApiOperation
(
value
=
"图片验证码"
,
notes
=
"验证码"
)
@GetMapping
(
value
=
"/code"
)
public
Map
<
String
,
String
>
code
()
throws
Exception
{
// 利用图片工具生成图片
// 第一个参数是生成的验证码,第二个参数是生成的图片
Object
[]
objs
=
VerifyUtil
.
createImage
();
// 将验证码存入Session
// session.setAttribute("imageCode",objs[0]);
String
uuid
=
UUIDUtil
.
getUUID
();
redis
.
set
(
uuid
,
objs
[
0
].
toString
(),
60
*
10
,
TimeUnit
.
SECONDS
);
// 将图片输出给浏览器
BufferedImage
image
=
(
BufferedImage
)
objs
[
1
];
/*
* response.setContentType("image/png"); OutputStream os =
* response.getOutputStream(); ImageIO.write(image, "png", os);
*/
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
ImageIO
.
write
(
image
,
"png"
,
baos
);
BASE64Encoder
encoder
=
new
BASE64Encoder
();
byte
[]
bytes
=
baos
.
toByteArray
();
// 转换成字节
String
png_base64
=
encoder
.
encodeBuffer
(
bytes
).
trim
();
// 转换成base64串
png_base64
=
png_base64
.
replaceAll
(
"\n"
,
""
).
replaceAll
(
"\r"
,
""
);
// 删除
// \r\n
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"uuid"
,
uuid
);
map
.
put
(
"img"
,
"data:image/png;base64,"
+
png_base64
);
return
map
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论