dev_xds
haha 2024-04-11 00:18:53 +08:00
commit 42d9d37e17
10 changed files with 108 additions and 11 deletions

View File

@ -109,9 +109,9 @@ spring:
# 端口默认为6379
port: 6379
# 数据库索引
database: 0
database: 1
# 密码
password: 123456
password: aDlasdasasdjHjasasdkqmewqe
# 连接超时时间
timeout: 10s
lettuce:

View File

@ -15,6 +15,7 @@ import com.ruoyi.system.domain.SysUserOpenid;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.SysUserOpenidMapper;
import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
@ -52,6 +53,9 @@ public class GlobalEventListener extends AbstractFlowableEngineEventListener {
@Autowired
private RedisCache redisCache;
@Autowired
private ISysConfigService configService;
@Autowired
private TaskService taskService;
@ -245,7 +249,7 @@ public class GlobalEventListener extends AbstractFlowableEngineEventListener {
/**
*
*/
private boolean wxSwitch = true;
private boolean wxSwitch = false;
/**
*
@ -253,6 +257,7 @@ public class GlobalEventListener extends AbstractFlowableEngineEventListener {
*/
private void send(List<WxMpTemplateMessage> lsit, String messageType){
try {
wxSwitch = Convert.toBool(configService.selectConfigByKey("sys.wx.message"),false);
if(wxSwitch && StringUtils.isNotEmpty(lsit)){
for(WxMpTemplateMessage message:lsit){
if(StringUtils.isNotEmpty(message.getToUser())){

View File

@ -1,6 +1,10 @@
package com.ruoyi.framework.web.service;
import javax.annotation.Resource;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
@ -49,6 +53,9 @@ public class SysLoginService
@Autowired
private ISysUserService userService;
@Autowired
private SysUserMapper sysUserMapper;
@Autowired
private ISysConfigService configService;
@ -100,6 +107,56 @@ public class SysLoginService
return tokenService.createToken(loginUser);
}
/**
*
*
* @param username
* @param openId openId
* @return
*/
public String login(String username,String openId)
{
//进入这里先把用户的密码修改,登录成功后在修改回去
SysUser sysUser = sysUserMapper.selectUserByUserName(username);
String userAuth = sysUser.getPassword();
String password = Convert.toStr(System.currentTimeMillis());
sysUser.setPassword(SecurityUtils.encryptPassword(password));
sysUserMapper.updateUser(sysUser);
// 用户验证
Authentication authentication = null;
try
{
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
AuthenticationContextHolder.setContext(authenticationToken);
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
authentication = authenticationManager.authenticate(authenticationToken);
}
catch (Exception e)
{
if (e instanceof BadCredentialsException)
{
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
throw new UserPasswordNotMatchException();
}
else
{
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
throw new ServiceException(e.getMessage());
}
}
finally
{
AuthenticationContextHolder.clearContext();
sysUser.setPassword(userAuth);
sysUserMapper.updateUser(sysUser);
}
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
LoginUser loginUser = (LoginUser) authentication.getPrincipal();
recordLoginInfo(loginUser.getUserId());
// 生成token
return tokenService.createWxToken(loginUser,openId);
}
/**
*
*

View File

@ -131,6 +131,23 @@ public class TokenService
return createToken(claims);
}
/**
*
*
* @param loginUser
* @return
*/
public String createWxToken(LoginUser loginUser,String openId)
{
loginUser.setToken(openId);
setUserAgent(loginUser);
refreshToken(loginUser);
Map<String, Object> claims = new HashMap<>();
claims.put(Constants.LOGIN_USER_KEY, openId);
return createToken(claims);
}
/**
* 20
*

View File

@ -39,6 +39,10 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-system</artifactId>
</dependency>
</dependencies>

View File

@ -7,9 +7,9 @@ import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.MessageTypeEnum;
import com.ruoyi.common.enums.TemplateMessageEnum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.quartz.service.ITaskService;
import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
@ -41,6 +41,9 @@ public class FlowTaskExpiredTask {
@Autowired
private ITaskService taskService;
@Autowired
private ISysConfigService configService;
/**
* Flowable
* ::quartz.task.flowTaskExpiredTask.notifyExpiredData
@ -396,7 +399,7 @@ public class FlowTaskExpiredTask {
/**
*
*/
private boolean wxSwitch = true;
private boolean wxSwitch = false;
/**
*
@ -404,6 +407,7 @@ public class FlowTaskExpiredTask {
*/
private void send(List<WxMpTemplateMessage> lsit, String messageType){
try {
wxSwitch = Convert.toBool(configService.selectConfigByKey("sys.wx.message"),false);
if(wxSwitch && StringUtils.isNotEmpty(lsit)){
for(WxMpTemplateMessage message:lsit){
if(StringUtils.isNotEmpty(message.getToUser())){

View File

@ -5,6 +5,7 @@ import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.web.userLogin.service.IWechatUserLoginService;
@ -79,8 +80,11 @@ public class WechatUserLoginController extends BaseController {
ajax.put("data",data);
return ajax;
}
ajax.put(Constants.TOKEN, "");
data = wechatUserLoginService.getLoginUserByOpenId(loginBody.getOpenId());
String token = loginService.login(Convert.toStr(data.get("userName")),loginBody.getOpenId());
// 移动端这里刷新token有效期为长期
tokenService.refreshMobileToken(token);
ajax.put(Constants.TOKEN, token);
redisCache.setCacheObject(key, data, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
if(data!=null){
ajax.put("data",data);

View File

@ -141,6 +141,7 @@ public class WechatUserLoginServiceImpl implements IWechatUserLoginService {
wechatUserLoginMapper.addUserOpenId(map);
}
data.put("userinfo",userInfo);
data.put("userName",userData.get("user_name"));
return data;
}
@ -154,7 +155,7 @@ public class WechatUserLoginServiceImpl implements IWechatUserLoginService {
if(userMap!=null){
return this.findUserInfo(userMap.get("loginName").toString(),openId);
}else{
return null;
throw new RuntimeException("用户信息异常...");
}
}

View File

@ -106,13 +106,13 @@ spring:
# redis 配置
redis:
# 地址
host: 127.0.0.1
host: 192.168.126.20
# 端口默认为6379
port: 6379
# 数据库索引
database: 0
database: 1
# 密码
password: 123456
password: aDlasdasasdjHjasasdkqmewqe
# 连接超时时间
timeout: 10s
lettuce:

View File

@ -16,6 +16,7 @@ import com.ruoyi.system.domain.SysUserOpenid;
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.SysUserOpenidMapper;
import com.ruoyi.system.service.ISysConfigService;
import com.yanzhu.jh.project.domain.*;
import com.yanzhu.jh.project.mapper.SurProjectMapper;
import com.yanzhu.jh.trouble.domain.SmzSspProblemmodify;
@ -44,6 +45,9 @@ import java.util.stream.Collectors;
@EnableAsync
public class WeChatMessageServiceImpl {
@Autowired
private ISysConfigService configService;
@Autowired
private WxMpService wxMpService;
@ -643,7 +647,7 @@ public class WeChatMessageServiceImpl {
/**
*
*/
private boolean wxSwitch=true;
private boolean wxSwitch = false;
/**
*
@ -651,6 +655,7 @@ public class WeChatMessageServiceImpl {
*/
private void send(List<WxMpTemplateMessage> lsit,String messageType){
try {
wxSwitch = Convert.toBool(configService.selectConfigByKey("sys.wx.message"),false);
if(wxSwitch && StringUtils.isNotEmpty(lsit)){
for(WxMpTemplateMessage message:lsit){
if(StringUtils.isNotEmpty(message.getToUser())){