Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
auth-master
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Members
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
吴超
auth-master
Commits
6b12076f
Commit
6b12076f
authored
Jun 17, 2026
by
周海峰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
扫码登录,限制code3分钟
parent
c2c567be
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
28 行增加
和
1 行删除
+28
-1
src/main/java/com/metro/auth/platform/controller/AuthController.java
+28
-1
没有找到文件。
src/main/java/com/metro/auth/platform/controller/AuthController.java
View file @
6b12076f
...
@@ -6,6 +6,7 @@ import com.metro.auth.platform.domain.auth.*;
...
@@ -6,6 +6,7 @@ import com.metro.auth.platform.domain.auth.*;
import
com.metro.auth.platform.generallog.LogAnnotation
;
import
com.metro.auth.platform.generallog.LogAnnotation
;
import
com.metro.auth.platform.http.HttpAPIService
;
import
com.metro.auth.platform.http.HttpAPIService
;
import
com.metro.auth.platform.outlineapi.PlatformUrlManager
;
import
com.metro.auth.platform.outlineapi.PlatformUrlManager
;
import
com.metro.auth.platform.redis.RedisUtils
;
import
com.metro.auth.platform.service.AuthService
;
import
com.metro.auth.platform.service.AuthService
;
import
com.metro.auth.platform.utils.*
;
import
com.metro.auth.platform.utils.*
;
import
com.metro.auth.platform.wxmessage.ApiConfig
;
import
com.metro.auth.platform.wxmessage.ApiConfig
;
...
@@ -22,6 +23,7 @@ import javax.annotation.Resource;
...
@@ -22,6 +23,7 @@ import javax.annotation.Resource;
import
javax.mail.MessagingException
;
import
javax.mail.MessagingException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.Valid
;
import
javax.validation.Valid
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* @author zhouy
* @author zhouy
...
@@ -32,6 +34,9 @@ import javax.validation.Valid;
...
@@ -32,6 +34,9 @@ import javax.validation.Valid;
@Api
(
tags
=
"统一登录相关接口"
)
@Api
(
tags
=
"统一登录相关接口"
)
@RequestMapping
(
"/auth/v1"
)
@RequestMapping
(
"/auth/v1"
)
public
class
AuthController
{
public
class
AuthController
{
private
static
final
String
LOGIN_CODE_PRX
=
"sq_code_login_code_"
;
@Value
(
"${jwt.header}"
)
@Value
(
"${jwt.header}"
)
private
String
tokenHeader
;
private
String
tokenHeader
;
...
@@ -43,6 +48,9 @@ public class AuthController {
...
@@ -43,6 +48,9 @@ public class AuthController {
@Resource
@Resource
public
HttpAPIService
httpAPIService
;
public
HttpAPIService
httpAPIService
;
@Resource
private
RedisUtils
redisUtils
;
@Autowired
@Autowired
public
AuthController
(
AuthService
authService
)
{
public
AuthController
(
AuthService
authService
)
{
...
@@ -128,8 +136,12 @@ public class AuthController {
...
@@ -128,8 +136,12 @@ public class AuthController {
*/
*/
@LogAnnotation
(
operateContent
=
"用户内网扫码登录"
,
operateType
=
"登录"
)
@LogAnnotation
(
operateContent
=
"用户内网扫码登录"
,
operateType
=
"登录"
)
@PostMapping
(
value
=
"/logincode"
)
@PostMapping
(
value
=
"/logincode"
)
// @ApiOperation(value = "登录", notes = "根据随机码登录")
public
ResultJson
<
ResponseUserToken
>
logincode
(
@Valid
@RequestBody
User
user
)
{
public
ResultJson
<
ResponseUserToken
>
logincode
(
@Valid
@RequestBody
User
user
)
{
boolean
exists
=
redisUtils
.
exists
(
LOGIN_CODE_PRX
+
user
.
getCode
());
if
(!
exists
)
{
log
.
warn
(
"用户内网扫码登录code无效,code={}"
,
user
.
getCode
());
return
ResultJson
.
ok
(
false
);
}
//根据code查用户账户和密码
//根据code查用户账户和密码
PlatformPersonnel
platformPersonnel
=
authService
.
findUserInfoByCode
(
user
.
getCode
());
PlatformPersonnel
platformPersonnel
=
authService
.
findUserInfoByCode
(
user
.
getCode
());
if
(
platformPersonnel
!=
null
)
{
if
(
platformPersonnel
!=
null
)
{
...
@@ -171,8 +183,23 @@ public class AuthController {
...
@@ -171,8 +183,23 @@ public class AuthController {
return
ResultJson
.
failure
(
ResultCode
.
UNAUTHORIZED
);
return
ResultJson
.
failure
(
ResultCode
.
UNAUTHORIZED
);
}
}
String
userId
=
(
String
)
JSONUtil
.
getStringFromJSONObject
(
wxuserinfo
,
"UserId"
);
String
userId
=
(
String
)
JSONUtil
.
getStringFromJSONObject
(
wxuserinfo
,
"UserId"
);
// 检查登录验证码是否已存在,如果存在则验证用户ID是否匹配
boolean
exists
=
redisUtils
.
exists
(
LOGIN_CODE_PRX
+
saveSqCodeReq
.
getLoginCode
());
if
(
exists
)
{
Object
object
=
redisUtils
.
get
(
LOGIN_CODE_PRX
+
saveSqCodeReq
.
getLoginCode
());
log
.
warn
(
"登录验证码已存在,之前的用户ID为=={}"
,
object
);
if
(!
userId
.
equals
(
object
.
toString
()))
{
return
ResultJson
.
failure
(
ResultCode
.
BUSINESS_ERROR
);
}
else
{
return
ResultJson
.
ok
(
ResultCode
.
SUCCESS
);
}
}
int
flag
=
authService
.
updateCodeByUserid
(
userId
,
saveSqCodeReq
.
getLoginCode
());
int
flag
=
authService
.
updateCodeByUserid
(
userId
,
saveSqCodeReq
.
getLoginCode
());
if
(
flag
>
0
)
{
if
(
flag
>
0
)
{
// 将登录验证码和用户ID存入Redis,设置过期时间为3分钟
redisUtils
.
set
(
LOGIN_CODE_PRX
+
saveSqCodeReq
.
getLoginCode
(),
userId
,
3L
,
TimeUnit
.
MINUTES
);
return
ResultJson
.
ok
(
ResultCode
.
SUCCESS
);
return
ResultJson
.
ok
(
ResultCode
.
SUCCESS
);
}
else
{
}
else
{
return
ResultJson
.
failure
(
ResultCode
.
RESPONSE_ERROR
);
return
ResultJson
.
failure
(
ResultCode
.
RESPONSE_ERROR
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论