Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
safe-campus-bbs
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
万成波
safe-campus-bbs
Commits
d66c6978
Commit
d66c6978
authored
Oct 28, 2025
by
万成波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
后台企微登录
parent
a8a2a392
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
104 additions
and
40 deletions
+104
-40
safe-campus-admin/src/main/java/com/tangguo/web/controller/system/SysLoginController.java
...com/tangguo/web/controller/system/SysLoginController.java
+54
-9
safe-campus-admin/src/main/resources/application-jxfz.yml
safe-campus-admin/src/main/resources/application-jxfz.yml
+9
-4
safe-campus-admin/src/main/resources/application.yml
safe-campus-admin/src/main/resources/application.yml
+0
-11
safe-campus-admin/src/test/java/com/tangguo/ApplicationTest.java
...mpus-admin/src/test/java/com/tangguo/ApplicationTest.java
+2
-2
safe-campus-bbs-uniapp/manifest.json
safe-campus-bbs-uniapp/manifest.json
+2
-2
safe-campus-framework/src/main/java/com/tangguo/framework/config/SecurityConfig.java
...ain/java/com/tangguo/framework/config/SecurityConfig.java
+1
-1
safe-campus-framework/src/main/java/com/tangguo/framework/security/handle/AuthenticationEntryPointImpl.java
...amework/security/handle/AuthenticationEntryPointImpl.java
+5
-5
safe-campus-framework/src/main/java/com/tangguo/framework/web/service/SysLoginService.java
...va/com/tangguo/framework/web/service/SysLoginService.java
+1
-1
safe-campus-framework/src/main/java/com/tangguo/framework/wxcp/WxCpConfiguration.java
...in/java/com/tangguo/framework/wxcp/WxCpConfiguration.java
+25
-4
safe-campus-framework/src/main/java/com/tangguo/framework/wxcp/WxCpProperties.java
.../main/java/com/tangguo/framework/wxcp/WxCpProperties.java
+5
-1
No files found.
safe-campus-admin/src/main/java/com/tangguo/web/controller/system/SysLoginController.java
View file @
d66c6978
...
@@ -2,7 +2,6 @@ package com.tangguo.web.controller.system;
...
@@ -2,7 +2,6 @@ package com.tangguo.web.controller.system;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
com.alibaba.fastjson2.JSON
;
import
com.alibaba.fastjson2.JSON
;
import
com.tangguo.common.annotation.Log
;
import
com.tangguo.common.constant.Constants
;
import
com.tangguo.common.constant.Constants
;
import
com.tangguo.common.core.domain.AjaxResult
;
import
com.tangguo.common.core.domain.AjaxResult
;
import
com.tangguo.common.core.domain.entity.SysMenu
;
import
com.tangguo.common.core.domain.entity.SysMenu
;
...
@@ -11,10 +10,8 @@ import com.tangguo.common.core.domain.entity.SysUser;
...
@@ -11,10 +10,8 @@ import com.tangguo.common.core.domain.entity.SysUser;
import
com.tangguo.common.core.domain.model.LoginBody
;
import
com.tangguo.common.core.domain.model.LoginBody
;
import
com.tangguo.common.core.domain.model.LoginUser
;
import
com.tangguo.common.core.domain.model.LoginUser
;
import
com.tangguo.common.core.domain.model.WxcpCodeLogin
;
import
com.tangguo.common.core.domain.model.WxcpCodeLogin
;
import
com.tangguo.common.enums.BusinessType
;
import
com.tangguo.common.exception.ServiceException
;
import
com.tangguo.common.exception.ServiceException
;
import
com.tangguo.common.utils.SecurityUtils
;
import
com.tangguo.common.utils.SecurityUtils
;
import
com.tangguo.common.utils.StringUtils
;
import
com.tangguo.framework.config.ServerConfig
;
import
com.tangguo.framework.config.ServerConfig
;
import
com.tangguo.framework.web.service.SysLoginService
;
import
com.tangguo.framework.web.service.SysLoginService
;
import
com.tangguo.framework.web.service.SysPermissionService
;
import
com.tangguo.framework.web.service.SysPermissionService
;
...
@@ -59,7 +56,10 @@ public class SysLoginController {
...
@@ -59,7 +56,10 @@ public class SysLoginController {
private
TokenService
tokenService
;
private
TokenService
tokenService
;
@Autowired
@Autowired
private
WxCpService
wxCpService
;
private
WxCpService
mobileWxCpService
;
@Autowired
private
WxCpService
pcWxCpService
;
@Autowired
@Autowired
private
ServerConfig
serverConfig
;
private
ServerConfig
serverConfig
;
...
@@ -67,8 +67,12 @@ public class SysLoginController {
...
@@ -67,8 +67,12 @@ public class SysLoginController {
@Autowired
@Autowired
private
ISysUserService
userService
;
private
ISysUserService
userService
;
@Value
(
"${wx.cp.redirect-url}"
)
private
String
redirectUrl
;
@Value
(
"${wx.cp.pc-redirect-url}"
)
private
String
pcRedirectUrl
;
@Value
(
"${wx.cp.mobile-redirect-url}"
)
private
String
mobileRedirectUrl
;
...
@@ -88,6 +92,47 @@ public class SysLoginController {
...
@@ -88,6 +92,47 @@ public class SysLoginController {
return
ajax
;
return
ajax
;
}
}
/**
* 企微用户Code登录
*
* @param bo 登录参数
* @return 登录结果
*/
@PostMapping
(
"/pc/code/login"
)
public
AjaxResult
pcCodeLogin
(
@RequestBody
WxcpCodeLogin
bo
)
{
LoginUser
loginUser
=
SecurityUtils
.
getLoginUserNotEx
();
log
.
info
(
"=> 登录请求参数:{}"
,
bo
);
log
.
info
(
"=> 当前登录用户:{}"
,
loginUser
);
// 企微登录认证链接
String
authCode
=
bo
.
getCode
();
WxCpOAuth2Service
oauth2Service
=
this
.
pcWxCpService
.
getOauth2Service
();
if
(
Objects
.
isNull
(
loginUser
)
&&
StrUtil
.
isBlank
(
authCode
))
{
String
oauth2Url
=
oauth2Service
.
buildAuthorizationUrl
(
this
.
pcRedirectUrl
,
null
);
log
.
info
(
"=> 认证失败,返回Oauth2登录链接:{}"
,
oauth2Url
);
return
AjaxResult
.
error
(
401
,
"身份认证失败"
,
oauth2Url
);
}
// 查询企微用户信息
String
token
=
null
;
if
(
Objects
.
isNull
(
loginUser
)
&&
StrUtil
.
isNotBlank
(
authCode
))
{
try
{
WxCpOauth2UserInfo
userInfo
=
oauth2Service
.
getUserInfo
(
authCode
);
log
.
info
(
"=> 查询企微用户信息,返回结果:{},{}"
,
authCode
,
JSON
.
toJSONString
(
userInfo
));
UserDetails
userDetails
=
this
.
userDetailsServiceImpl
.
loadUserByUsername2
(
userInfo
.
getUserId
());
token
=
this
.
tokenService
.
createToken
((
LoginUser
)
userDetails
);
}
catch
(
Exception
e
)
{
log
.
error
(
"=> 查询用户信息失败:"
,
e
);
throw
new
ServiceException
(
"登录失败,查询用户信息失败。"
);
}
}
log
.
info
(
"=> 登录结果:{}"
,
token
);
return
AjaxResult
.
success
(
"登录成功"
,
token
);
}
/**
/**
* 获取用户信息
* 获取用户信息
*
*
...
@@ -129,16 +174,16 @@ public class SysLoginController {
...
@@ -129,16 +174,16 @@ public class SysLoginController {
* @return 登录结果
* @return 登录结果
*/
*/
@PostMapping
(
"/bbs/mobile/user/code/login"
)
@PostMapping
(
"/bbs/mobile/user/code/login"
)
public
AjaxResult
c
odeLogin
(
@RequestBody
WxcpCodeLogin
bo
)
{
public
AjaxResult
mobileC
odeLogin
(
@RequestBody
WxcpCodeLogin
bo
)
{
LoginUser
loginUser
=
SecurityUtils
.
getLoginUserNotEx
();
LoginUser
loginUser
=
SecurityUtils
.
getLoginUserNotEx
();
log
.
info
(
"=> 登录请求参数:{}"
,
bo
);
log
.
info
(
"=> 登录请求参数:{}"
,
bo
);
log
.
info
(
"=> 当前登录用户:{}"
,
loginUser
);
log
.
info
(
"=> 当前登录用户:{}"
,
loginUser
);
// 企微登录认证链接
// 企微登录认证链接
String
authCode
=
bo
.
getCode
();
String
authCode
=
bo
.
getCode
();
WxCpOAuth2Service
oauth2Service
=
this
.
w
xCpService
.
getOauth2Service
();
WxCpOAuth2Service
oauth2Service
=
this
.
mobileW
xCpService
.
getOauth2Service
();
if
(
Objects
.
isNull
(
loginUser
)
&&
StrUtil
.
isBlank
(
authCode
))
{
if
(
Objects
.
isNull
(
loginUser
)
&&
StrUtil
.
isBlank
(
authCode
))
{
String
oauth2Url
=
oauth2Service
.
buildAuthorizationUrl
(
this
.
r
edirectUrl
,
null
);
String
oauth2Url
=
oauth2Service
.
buildAuthorizationUrl
(
this
.
mobileR
edirectUrl
,
null
);
log
.
info
(
"=> 认证失败,返回Oauth2登录链接:{}"
,
oauth2Url
);
log
.
info
(
"=> 认证失败,返回Oauth2登录链接:{}"
,
oauth2Url
);
return
AjaxResult
.
error
(
401
,
"身份认证失败"
,
oauth2Url
);
return
AjaxResult
.
error
(
401
,
"身份认证失败"
,
oauth2Url
);
}
}
...
...
safe-campus-admin/src/main/resources/application-jxfz.yml
View file @
d66c6978
...
@@ -95,8 +95,13 @@ spring:
...
@@ -95,8 +95,13 @@ spring:
# 企业微信配置
# 企业微信配置
wx
:
wx
:
cp
:
cp
:
redirect-url
:
https://wecom.jift.edu.cn/bbsh5/pages/login/login
pc-redirect-url
:
https://wecom.jift.edu.cn/bbs/pc
mobile-redirect-url
:
https://wecom.jift.edu.cn/bbs/h5/pages/login/login
corp-id
:
wxd2a84aa7529d3801
corp-id
:
wxd2a84aa7529d3801
app-config
:
app-configs
:
agent-id
:
1000218
-
name
:
'
移动端应用配置'
secret
:
UubIP6xbLBzw3DwcIyOARYf1e4cm5GNJKNFZTlVfgyo
agent-id
:
1000218
secret
:
UubIP6xbLBzw3DwcIyOARYf1e4cm5GNJKNFZTlVfgyo
-
name
:
'
管理端应用配置'
agent-id
:
1000219
secret
:
OEMM3DAd-2FK-9Ggiu3xsD7Sg4SlPuV7os1hAWrTIwk
safe-campus-admin/src/main/resources/application.yml
View file @
d66c6978
...
@@ -119,14 +119,3 @@ xss:
...
@@ -119,14 +119,3 @@ xss:
excludes
:
/system/notice
excludes
:
/system/notice
# 匹配链接
# 匹配链接
urlPatterns
:
/system/*,/monitor/*,/tool/*
urlPatterns
:
/system/*,/monitor/*,/tool/*
mobile
:
auth
:
res-token-name
:
token
req-token-name
:
Authorization
issuer
:
Mobile-Auth
algorithm-id
:
HS512
sign-key
:
SignKey2025@.
effective-time
:
7d
path-patterns
:
/bbs/mobile/**
safe-campus-admin/src/test/java/com/tangguo/ApplicationTest.java
View file @
d66c6978
...
@@ -23,13 +23,13 @@ public class ApplicationTest {
...
@@ -23,13 +23,13 @@ public class ApplicationTest {
private
JmsTemplate
jmsTemplate
;
private
JmsTemplate
jmsTemplate
;
@Resource
@Resource
private
WxCpService
w
xCpService
;
private
WxCpService
mobileW
xCpService
;
@Test
@Test
public
void
test
()
{
public
void
test
()
{
WxCpOAuth2Service
oauth2Service
=
this
.
w
xCpService
.
getOauth2Service
();
WxCpOAuth2Service
oauth2Service
=
this
.
mobileW
xCpService
.
getOauth2Service
();
System
.
out
.
println
(
oauth2Service
.
buildAuthorizationUrl
(
"https://test.tangguo.ren/bbs/h5/pages/login/login/"
,
""
));
System
.
out
.
println
(
oauth2Service
.
buildAuthorizationUrl
(
"https://test.tangguo.ren/bbs/h5/pages/login/login/"
,
""
));
}
}
...
...
safe-campus-bbs-uniapp/manifest.json
View file @
d66c6978
{
{
"name"
:
"社区"
,
"name"
:
"社区"
,
"appid"
:
"__UNI__
E3457E1
"
,
"appid"
:
"__UNI__
69A40B9
"
,
"description"
:
""
,
"description"
:
""
,
"versionName"
:
"1.0.0"
,
"versionName"
:
"1.0.0"
,
"versionCode"
:
"100"
,
"versionCode"
:
"100"
,
...
@@ -72,7 +72,7 @@
...
@@ -72,7 +72,7 @@
"h5"
:
{
"h5"
:
{
"router"
:
{
"router"
:
{
"mode"
:
"history"
,
"mode"
:
"history"
,
"base"
:
"/bbsh5/"
"base"
:
"/bbs
/
h5/"
}
}
}
}
}
}
safe-campus-framework/src/main/java/com/tangguo/framework/config/SecurityConfig.java
View file @
d66c6978
...
@@ -110,7 +110,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -110,7 +110,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 过滤请求
// 过滤请求
.
authorizeRequests
()
.
authorizeRequests
()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
.
antMatchers
(
"/login"
,
"/bbs/mobile/user/code/login"
,
"/register"
,
"/captchaImage"
).
permitAll
()
.
antMatchers
(
"/login"
,
"/bbs/mobile/user/code/login"
,
"/
pc/code/login"
,
"/
register"
,
"/captchaImage"
).
permitAll
()
// 静态资源,可匿名访问
// 静态资源,可匿名访问
.
antMatchers
(
HttpMethod
.
GET
,
"/"
,
"/*.html"
,
"/**/*.html"
,
"/**/*.css"
,
"/**/*.js"
,
"/profile/**"
).
permitAll
()
.
antMatchers
(
HttpMethod
.
GET
,
"/"
,
"/*.html"
,
"/**/*.html"
,
"/**/*.css"
,
"/**/*.js"
,
"/profile/**"
).
permitAll
()
.
antMatchers
(
"/swagger-ui.html"
,
"/swagger-resources/**"
,
"/webjars/**"
,
"/*/api-docs"
,
"/druid/**"
).
permitAll
()
.
antMatchers
(
"/swagger-ui.html"
,
"/swagger-resources/**"
,
"/webjars/**"
,
"/*/api-docs"
,
"/druid/**"
).
permitAll
()
...
...
safe-campus-framework/src/main/java/com/tangguo/framework/security/handle/AuthenticationEntryPointImpl.java
View file @
d66c6978
...
@@ -33,10 +33,10 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
...
@@ -33,10 +33,10 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
private
static
final
long
serialVersionUID
=
-
8970718410437077606L
;
private
static
final
long
serialVersionUID
=
-
8970718410437077606L
;
@Autowired
@Autowired
private
WxCpService
w
xCpService
;
private
WxCpService
mobileW
xCpService
;
@Value
(
"${wx.cp.redirect-url}"
)
@Value
(
"${wx.cp.
mobile-
redirect-url}"
)
private
String
r
edirectUrl
;
private
String
mobileR
edirectUrl
;
@Override
@Override
public
void
commence
(
HttpServletRequest
request
,
HttpServletResponse
response
,
AuthenticationException
e
)
public
void
commence
(
HttpServletRequest
request
,
HttpServletResponse
response
,
AuthenticationException
e
)
...
@@ -47,8 +47,8 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
...
@@ -47,8 +47,8 @@ public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint, S
log
.
info
(
"=> 身份认证失败,Token:{}"
,
request
.
getHeader
(
"Authorization"
));
log
.
info
(
"=> 身份认证失败,Token:{}"
,
request
.
getHeader
(
"Authorization"
));
if
(
uri
.
startsWith
(
"/bbs/mobile"
))
{
if
(
uri
.
startsWith
(
"/bbs/mobile"
))
{
WxCpOAuth2Service
oauth2Service
=
this
.
w
xCpService
.
getOauth2Service
();
WxCpOAuth2Service
oauth2Service
=
this
.
mobileW
xCpService
.
getOauth2Service
();
String
oauth2Url
=
oauth2Service
.
buildAuthorizationUrl
(
this
.
r
edirectUrl
,
null
);
String
oauth2Url
=
oauth2Service
.
buildAuthorizationUrl
(
this
.
mobileR
edirectUrl
,
null
);
ServletUtils
.
renderString
(
response
,
JSON
.
toJSONString
(
AjaxResult
.
error
(
401
,
"身份认证失败"
,
oauth2Url
)));
ServletUtils
.
renderString
(
response
,
JSON
.
toJSONString
(
AjaxResult
.
error
(
401
,
"身份认证失败"
,
oauth2Url
)));
}
else
{
}
else
{
String
msg
=
StringUtils
.
format
(
"请求访问:{},认证失败,无法访问系统资源"
,
uri
);
String
msg
=
StringUtils
.
format
(
"请求访问:{},认证失败,无法访问系统资源"
,
uri
);
...
...
safe-campus-framework/src/main/java/com/tangguo/framework/web/service/SysLoginService.java
View file @
d66c6978
...
@@ -65,7 +65,7 @@ public class SysLoginService {
...
@@ -65,7 +65,7 @@ public class SysLoginService {
private
UserDetailsServiceImpl
userDetailsServiceImpl
;
private
UserDetailsServiceImpl
userDetailsServiceImpl
;
@Autowired
@Autowired
private
WxCpService
w
xCpService
;
private
WxCpService
mobileW
xCpService
;
/**
/**
...
...
safe-campus-framework/src/main/java/com/tangguo/framework/wxcp/WxCpConfiguration.java
View file @
d66c6978
...
@@ -9,6 +9,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
...
@@ -9,6 +9,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Objects
;
...
@@ -29,10 +30,11 @@ public class WxCpConfiguration {
...
@@ -29,10 +30,11 @@ public class WxCpConfiguration {
/**
/**
* 配置 WxCpService 实例
* 配置 WxCpService 实例
*/
*/
@Bean
@Bean
(
"mobileWxCpService"
)
public
WxCpService
wxCpService
()
{
public
WxCpService
mobileWxCpService
()
{
WxCpProperties
.
AppConfig
appConfig
=
this
.
properties
.
getAppConfig
();
List
<
WxCpProperties
.
AppConfig
>
appConfigs
=
this
.
properties
.
getAppConfigs
();
WxCpDefaultConfigImpl
configStorage
=
new
WxCpDefaultConfigImpl
();
WxCpProperties
.
AppConfig
appConfig
=
appConfigs
.
get
(
0
);
WxCpDefaultConfigImpl
configStorage
=
new
WxCpDefaultConfigImpl
();
configStorage
.
setCorpId
(
this
.
properties
.
getCorpId
());
configStorage
.
setCorpId
(
this
.
properties
.
getCorpId
());
configStorage
.
setAgentId
(
appConfig
.
getAgentId
());
configStorage
.
setAgentId
(
appConfig
.
getAgentId
());
configStorage
.
setCorpSecret
(
appConfig
.
getSecret
());
configStorage
.
setCorpSecret
(
appConfig
.
getSecret
());
...
@@ -43,4 +45,23 @@ public class WxCpConfiguration {
...
@@ -43,4 +45,23 @@ public class WxCpConfiguration {
return
service
;
return
service
;
}
}
/**
* 配置 WxCpService 实例
*/
@Bean
(
"pcWxCpService"
)
public
WxCpService
pcWxCpService
()
{
List
<
WxCpProperties
.
AppConfig
>
appConfigs
=
this
.
properties
.
getAppConfigs
();
WxCpProperties
.
AppConfig
appConfig
=
appConfigs
.
get
(
1
);
WxCpDefaultConfigImpl
configStorage
=
new
WxCpDefaultConfigImpl
();
configStorage
.
setCorpId
(
this
.
properties
.
getCorpId
());
configStorage
.
setAgentId
(
appConfig
.
getAgentId
());
configStorage
.
setCorpSecret
(
appConfig
.
getSecret
());
configStorage
.
setToken
(
appConfig
.
getToken
());
configStorage
.
setAesKey
(
appConfig
.
getAesKey
());
WxCpService
service
=
new
WxCpServiceImpl
();
service
.
setWxCpConfigStorage
(
configStorage
);
return
service
;
}
}
}
safe-campus-framework/src/main/java/com/tangguo/framework/wxcp/WxCpProperties.java
View file @
d66c6978
...
@@ -3,6 +3,8 @@ package com.tangguo.framework.wxcp;
...
@@ -3,6 +3,8 @@ package com.tangguo.framework.wxcp;
import
lombok.Data
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
java.util.List
;
/**
/**
* 企业微信配置类
* 企业微信配置类
*
*
...
@@ -21,12 +23,14 @@ public class WxCpProperties {
...
@@ -21,12 +23,14 @@ public class WxCpProperties {
/**
/**
* 多应用配置
* 多应用配置
*/
*/
private
AppConfig
appConfig
;
private
List
<
AppConfig
>
appConfigs
;
@Data
@Data
public
static
class
AppConfig
{
public
static
class
AppConfig
{
private
String
name
;
/**
/**
* 设置企业微信应用的AgentId
* 设置企业微信应用的AgentId
*/
*/
...
...
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