This commit is contained in:
tgq
2021-09-14 16:55:39 +08:00
parent db193a46e8
commit c3506762f7
15 changed files with 957 additions and 3 deletions

View File

@ -58,6 +58,12 @@
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-system</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-wxapi</artifactId>
<version>3.7.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -97,7 +97,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求
.authorizeRequests()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/register", "/captchaImage").anonymous()
.antMatchers("/login", "/register", "/captchaImage", "/api/wx/login").anonymous()
.antMatchers(
HttpMethod.GET,
"/",

View File

@ -1,5 +1,8 @@
package com.ruoyi.framework.web.service;
import com.ruoyi.common.core.domain.entity.WxUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.wxapi.service.IWxUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -30,9 +33,31 @@ public class UserDetailsServiceImpl implements UserDetailsService
@Autowired
private SysPermissionService permissionService;
@Autowired
private IWxUserService wxUserService;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
{
if (StringUtils.isNotEmpty(username) && username.startsWith("wx_openid_")){
String openId = username.replace("wx_openid_", "");
WxUser wxUser = wxUserService.selectWxUserByOpenId(openId);
wxUser.setPassword(SecurityUtils.encryptPassword(wxUser.getOpenId()));
if (StringUtils.isNull(wxUser))
{
log.info("登录用户:{} 不存在.", openId);
throw new ServiceException("登录用户不存在");
}
else if ("3".equals(wxUser.getStatus()))
{
log.info("登录用户:{} 已被停用.", openId);
throw new ServiceException("对不起,您的账号已停用");
}
return new LoginUser(wxUser);
}
SysUser user = userService.selectUserByUserName(username);
if (StringUtils.isNull(user))
{