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 # 端口默认为6379
port: 6379 port: 6379
# 数据库索引 # 数据库索引
database: 0 database: 1
# 密码 # 密码
password: 123456 password: aDlasdasasdjHjasasdkqmewqe
# 连接超时时间 # 连接超时时间
timeout: 10s timeout: 10s
lettuce: lettuce:

View File

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

View File

@ -1,6 +1,10 @@
package com.ruoyi.framework.web.service; package com.ruoyi.framework.web.service;
import javax.annotation.Resource; 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.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.BadCredentialsException;
@ -49,6 +53,9 @@ public class SysLoginService
@Autowired @Autowired
private ISysUserService userService; private ISysUserService userService;
@Autowired
private SysUserMapper sysUserMapper;
@Autowired @Autowired
private ISysConfigService configService; private ISysConfigService configService;
@ -100,6 +107,56 @@ public class SysLoginService
return tokenService.createToken(loginUser); 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); 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 * 20
* *

View File

@ -39,6 +39,10 @@
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-system</artifactId>
</dependency>
</dependencies> </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.core.text.Convert;
import com.ruoyi.common.enums.MessageTypeEnum; import com.ruoyi.common.enums.MessageTypeEnum;
import com.ruoyi.common.enums.TemplateMessageEnum; import com.ruoyi.common.enums.TemplateMessageEnum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.quartz.service.ITaskService; import com.ruoyi.quartz.service.ITaskService;
import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
@ -41,6 +41,9 @@ public class FlowTaskExpiredTask {
@Autowired @Autowired
private ITaskService taskService; private ITaskService taskService;
@Autowired
private ISysConfigService configService;
/** /**
* Flowable * Flowable
* ::quartz.task.flowTaskExpiredTask.notifyExpiredData * ::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){ private void send(List<WxMpTemplateMessage> lsit, String messageType){
try { try {
wxSwitch = Convert.toBool(configService.selectConfigByKey("sys.wx.message"),false);
if(wxSwitch && StringUtils.isNotEmpty(lsit)){ if(wxSwitch && StringUtils.isNotEmpty(lsit)){
for(WxMpTemplateMessage message:lsit){ for(WxMpTemplateMessage message:lsit){
if(StringUtils.isNotEmpty(message.getToUser())){ 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.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginBody; import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.redis.RedisCache; 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.SysLoginService;
import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.web.userLogin.service.IWechatUserLoginService; import com.ruoyi.web.userLogin.service.IWechatUserLoginService;
@ -79,8 +80,11 @@ public class WechatUserLoginController extends BaseController {
ajax.put("data",data); ajax.put("data",data);
return ajax; return ajax;
} }
ajax.put(Constants.TOKEN, "");
data = wechatUserLoginService.getLoginUserByOpenId(loginBody.getOpenId()); 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); redisCache.setCacheObject(key, data, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
if(data!=null){ if(data!=null){
ajax.put("data",data); ajax.put("data",data);

View File

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

View File

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

View File

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