Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fj-captcha-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
郑磊
fj-captcha-service
Commits
c93b1cc3
You need to sign in or sign up before continuing.
Commit
c93b1cc3
authored
Jan 09, 2026
by
郑磊
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加代理ip解析
parent
88445649
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
12 deletions
+15
-12
CaptchaController.java
...in/java/com/fanjiao/captcha/server/CaptchaController.java
+15
-12
No files found.
server/src/main/java/com/fanjiao/captcha/server/CaptchaController.java
View file @
c93b1cc3
...
...
@@ -36,17 +36,7 @@ public class CaptchaController {
@RequestBody
(
required
=
false
)
GenerateCaptchaData
data
)
{
var
type
=
getRandomType
();
var
ip
=
request
.
getRemoteAddr
();
var
proxyIp
=
request
.
getHeader
(
"x-forwarded-for"
);
if
(
proxyIp
!=
null
&&
!
proxyIp
.
isEmpty
())
{
ip
=
proxyIp
.
split
(
","
)[
0
].
trim
();
}
else
{
proxyIp
=
request
.
getHeader
(
"x-real-ip"
);
if
(
proxyIp
!=
null
&&
!
proxyIp
.
isEmpty
())
{
ip
=
proxyIp
;
}
}
var
ip
=
getIpFromRequest
(
request
);
Map
<
String
,
Object
>
extra
=
null
;
if
(
data
!=
null
)
{
...
...
@@ -94,7 +84,7 @@ public class CaptchaController {
HttpServletRequest
request
,
@RequestBody
CheckCaptchaData
data
)
{
String
ip
=
request
.
getRemoteAddr
(
);
String
ip
=
getIpFromRequest
(
request
);
//校验验证码
var
result
=
imageCaptchaApplication
.
matching
(
data
.
getKey
(),
...
...
@@ -155,4 +145,17 @@ public class CaptchaController {
return
Response
.
success
(
info
);
}
}
protected
static
String
getIpFromRequest
(
HttpServletRequest
request
)
{
var
proxyIp
=
request
.
getHeader
(
"x-forwarded-for"
);
if
(
proxyIp
!=
null
&&
!
proxyIp
.
isEmpty
())
{
return
proxyIp
.
split
(
","
)[
0
].
trim
();
}
proxyIp
=
request
.
getHeader
(
"x-real-ip"
);
if
(
proxyIp
!=
null
&&
!
proxyIp
.
isEmpty
())
{
return
proxyIp
;
}
return
request
.
getRemoteAddr
();
}
}
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