master
parent
f7f3323a6f
commit
ba9419239e
@ -1,89 +1,89 @@
|
||||
package com.bsd.cases.conf;
|
||||
|
||||
import com.bsd.cases.shiro.CommonRealm;
|
||||
import com.bsd.cases.shiro.JWTFilter;
|
||||
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
||||
import org.apache.shiro.mgt.DefaultSubjectDAO;
|
||||
import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
||||
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Configuration
|
||||
public class ShiroConfig {
|
||||
|
||||
@Bean("securityManager")
|
||||
public DefaultWebSecurityManager getManager() {
|
||||
|
||||
DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
|
||||
// 使用自己的realm
|
||||
manager.setRealm(MyRealm());
|
||||
DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
|
||||
DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
|
||||
defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
|
||||
subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
|
||||
manager.setSubjectDAO(subjectDAO);
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
@Bean("shiroFilter")
|
||||
public ShiroFilterFactoryBean factory(DefaultWebSecurityManager securityManager) {
|
||||
ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
|
||||
|
||||
// 添加自己的过滤器并且取名为jwt
|
||||
Map<String, Filter> filterMap = new HashMap<>();
|
||||
filterMap.put("jwt", new JWTFilter());
|
||||
factoryBean.setFilters(filterMap);
|
||||
|
||||
factoryBean.setSecurityManager(securityManager);
|
||||
factoryBean.setUnauthorizedUrl("/api/401");
|
||||
|
||||
Map<String, String> filterRuleMap = new HashMap<>();
|
||||
// 所有请求通过我们自己的JWT Filter
|
||||
filterRuleMap.put("/**", "jwt");
|
||||
// 访问401和404页面不通过我们的Filter
|
||||
filterRuleMap.put("/api/adminlogin", "anon");
|
||||
filterRuleMap.put("/api/autologin", "anon");
|
||||
filterRuleMap.put("/api/401", "anon");
|
||||
factoryBean.setFilterChainDefinitionMap(filterRuleMap);
|
||||
return factoryBean;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@DependsOn("lifecycleBeanPostProcessor")
|
||||
public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
|
||||
|
||||
DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
|
||||
defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
|
||||
return defaultAdvisorAutoProxyCreator;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommonRealm MyRealm() {
|
||||
return new CommonRealm();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
|
||||
return new LifecycleBeanPostProcessor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(DefaultWebSecurityManager securityManager) {
|
||||
AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
|
||||
advisor.setSecurityManager(securityManager);
|
||||
return advisor;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.bsd.cases.conf;
|
||||
//
|
||||
//import com.bsd.cases.shiro.CommonRealm;
|
||||
//import com.bsd.cases.shiro.JWTFilter;
|
||||
//import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
|
||||
//import org.apache.shiro.mgt.DefaultSubjectDAO;
|
||||
//import org.apache.shiro.spring.LifecycleBeanPostProcessor;
|
||||
//import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
|
||||
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
|
||||
//import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
|
||||
//import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.context.annotation.DependsOn;
|
||||
//
|
||||
//import javax.servlet.Filter;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//@Configuration
|
||||
//public class ShiroConfig {
|
||||
//
|
||||
// @Bean("securityManager")
|
||||
// public DefaultWebSecurityManager getManager() {
|
||||
//
|
||||
// DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
|
||||
// // 使用自己的realm
|
||||
// manager.setRealm(MyRealm());
|
||||
// DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();
|
||||
// DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();
|
||||
// defaultSessionStorageEvaluator.setSessionStorageEnabled(false);
|
||||
// subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);
|
||||
// manager.setSubjectDAO(subjectDAO);
|
||||
//
|
||||
// return manager;
|
||||
// }
|
||||
//
|
||||
// @Bean("shiroFilter")
|
||||
// public ShiroFilterFactoryBean factory(DefaultWebSecurityManager securityManager) {
|
||||
// ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
|
||||
//
|
||||
// // 添加自己的过滤器并且取名为jwt
|
||||
// Map<String, Filter> filterMap = new HashMap<>();
|
||||
// filterMap.put("jwt", new JWTFilter());
|
||||
// factoryBean.setFilters(filterMap);
|
||||
//
|
||||
// factoryBean.setSecurityManager(securityManager);
|
||||
// factoryBean.setUnauthorizedUrl("/api/401");
|
||||
//
|
||||
// Map<String, String> filterRuleMap = new HashMap<>();
|
||||
// // 所有请求通过我们自己的JWT Filter
|
||||
// filterRuleMap.put("/**", "jwt");
|
||||
// // 访问401和404页面不通过我们的Filter
|
||||
// filterRuleMap.put("/api/adminlogin", "anon");
|
||||
// filterRuleMap.put("/api/autologin", "anon");
|
||||
// filterRuleMap.put("/api/401", "anon");
|
||||
// factoryBean.setFilterChainDefinitionMap(filterRuleMap);
|
||||
// return factoryBean;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Bean
|
||||
// @DependsOn("lifecycleBeanPostProcessor")
|
||||
// public DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator() {
|
||||
//
|
||||
// DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
|
||||
// defaultAdvisorAutoProxyCreator.setProxyTargetClass(true);
|
||||
// return defaultAdvisorAutoProxyCreator;
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public CommonRealm MyRealm() {
|
||||
// return new CommonRealm();
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public LifecycleBeanPostProcessor lifecycleBeanPostProcessor() {
|
||||
// return new LifecycleBeanPostProcessor();
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(DefaultWebSecurityManager securityManager) {
|
||||
// AuthorizationAttributeSourceAdvisor advisor = new AuthorizationAttributeSourceAdvisor();
|
||||
// advisor.setSecurityManager(securityManager);
|
||||
// return advisor;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
@ -1,31 +1,31 @@
|
||||
package com.bsd.cases.event;
|
||||
|
||||
import com.bsd.cases.enums.BoBusinessEnum;
|
||||
import com.bsd.cases.model.BoActivityInstance;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* 加载日志时间
|
||||
*/
|
||||
public class LogEvent extends ApplicationEvent {
|
||||
|
||||
private BoActivityInstance boActivityInstance;
|
||||
private BoBusinessEnum boBusinessEnum;
|
||||
|
||||
|
||||
public LogEvent(Object source, BoActivityInstance boActivityInstance, BoBusinessEnum boBusinessEnum) {
|
||||
super(source);
|
||||
this.boActivityInstance = boActivityInstance;
|
||||
this.boBusinessEnum = boBusinessEnum;
|
||||
|
||||
}
|
||||
|
||||
public BoActivityInstance getBoActivityInstance() {
|
||||
return boActivityInstance;
|
||||
}
|
||||
|
||||
public BoBusinessEnum getBoBusinessEnum() {
|
||||
return boBusinessEnum;
|
||||
}
|
||||
|
||||
}
|
||||
//package com.bsd.cases.event;
|
||||
//
|
||||
//import com.bsd.cases.enums.BoBusinessEnum;
|
||||
//import com.bsd.cases.model.BoActivityInstance;
|
||||
//import org.springframework.context.ApplicationEvent;
|
||||
//
|
||||
///**
|
||||
// * 加载日志时间
|
||||
// */
|
||||
//public class LogEvent extends ApplicationEvent {
|
||||
//
|
||||
// private BoActivityInstance boActivityInstance;
|
||||
// private BoBusinessEnum boBusinessEnum;
|
||||
//
|
||||
//
|
||||
// public LogEvent(Object source, BoActivityInstance boActivityInstance, BoBusinessEnum boBusinessEnum) {
|
||||
// super(source);
|
||||
// this.boActivityInstance = boActivityInstance;
|
||||
// this.boBusinessEnum = boBusinessEnum;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public BoActivityInstance getBoActivityInstance() {
|
||||
// return boActivityInstance;
|
||||
// }
|
||||
//
|
||||
// public BoBusinessEnum getBoBusinessEnum() {
|
||||
// return boBusinessEnum;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
@ -1,76 +1,76 @@
|
||||
package com.bsd.cases.listener;
|
||||
|
||||
import com.bsd.cases.enums.BoActionEnum;
|
||||
import com.bsd.cases.enums.BoBusinessEnum;
|
||||
import com.bsd.cases.event.LogEvent;
|
||||
import com.bsd.cases.model.BoActivityInstance;
|
||||
import com.bsd.cases.model.BoBussinessLog;
|
||||
import com.bsd.cases.model.BoUsers;
|
||||
import com.bsd.cases.service.BoBussinessLogService;
|
||||
import com.bsd.cases.service.BoUsersService;
|
||||
import com.bsd.cases.util.DateUtils;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Component
|
||||
public class LogEventListener {
|
||||
|
||||
@Resource
|
||||
BoUsersService boUsersService;
|
||||
@Resource
|
||||
BoBussinessLogService boBussinessLogService;
|
||||
|
||||
@Async
|
||||
@EventListener
|
||||
public void LogEvent(LogEvent logEvent) {
|
||||
|
||||
BoBussinessLog boBussinessLog = new BoBussinessLog();
|
||||
BoBusinessEnum logEnum = logEvent.getBoBusinessEnum();
|
||||
BoActivityInstance boActivityInstance = logEvent.getBoActivityInstance();
|
||||
String source = logEvent.getSource().toString();
|
||||
boBussinessLog.setActionTime(DateUtils.date());
|
||||
boBussinessLog.setSource(source);
|
||||
BoUsers boUsers = boUsersService.currentUser();
|
||||
|
||||
switch (logEnum) {
|
||||
|
||||
case IDNEXPAGE:
|
||||
boBussinessLog.setAction(BoActionEnum.VISIT.getCategory());
|
||||
boBussinessLog.setPageName("首页");
|
||||
break;
|
||||
case LOGIN:
|
||||
boBussinessLog.setAction(BoActionEnum.SUBMIT.getCategory());
|
||||
break;
|
||||
case AcvityDETAIL:
|
||||
boBussinessLog.setAction(BoActionEnum.VISIT.getCategory());
|
||||
boBussinessLog.setPageName("活动详情页");
|
||||
boBussinessLog.setActivityInstanceId(boActivityInstance.getId());
|
||||
break;
|
||||
case MYACTIVITIES:
|
||||
boBussinessLog.setAction(BoActionEnum.VISIT.getCategory());
|
||||
boBussinessLog.setPageName("我的活动");
|
||||
case SHARECODE:
|
||||
boBussinessLog.setAction(BoActionEnum.SUBMIT.getCategory());
|
||||
boBussinessLog.setPageName("分享活动");
|
||||
break;
|
||||
case SIGNUP:
|
||||
boBussinessLog.setAction(BoActionEnum.SUBMIT.getCategory());
|
||||
boBussinessLog.setPageName("分享活动");
|
||||
break;
|
||||
case REGISTER:
|
||||
boBussinessLog.setAction(BoActionEnum.SUBMIT.getCategory());
|
||||
boBussinessLog.setPageName("注册");
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
Long operatorId = boUsers == null ? 0L : boUsers.getId();
|
||||
boBussinessLog.setUserId(operatorId);
|
||||
boBussinessLogService.saveOrUpdate(boBussinessLog, operatorId);
|
||||
}
|
||||
}
|
||||
//package com.bsd.cases.listener;
|
||||
//
|
||||
//import com.bsd.cases.enums.BoActionEnum;
|
||||
//import com.bsd.cases.enums.BoBusinessEnum;
|
||||
//import com.bsd.cases.event.LogEvent;
|
||||
//import com.bsd.cases.model.BoActivityInstance;
|
||||
//import com.bsd.cases.model.BoBussinessLog;
|
||||
//import com.bsd.cases.model.BoUsers;
|
||||
//import com.bsd.cases.service.BoBussinessLogService;
|
||||
//import com.bsd.cases.service.BoUsersService;
|
||||
//import com.bsd.cases.util.DateUtils;
|
||||
//import org.springframework.context.event.EventListener;
|
||||
//import org.springframework.scheduling.annotation.Async;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//
|
||||
//@Component
|
||||
//public class LogEventListener {
|
||||
//
|
||||
// @Resource
|
||||
// BoUsersService boUsersService;
|
||||
// @Resource
|
||||
// BoBussinessLogService boBussinessLogService;
|
||||
//
|
||||
// @Async
|
||||
// @EventListener
|
||||
// public void LogEvent(LogEvent logEvent) {
|
||||
//
|
||||
// BoBussinessLog boBussinessLog = new BoBussinessLog();
|
||||
// BoBusinessEnum logEnum = logEvent.getBoBusinessEnum();
|
||||
// BoActivityInstance boActivityInstance = logEvent.getBoActivityInstance();
|
||||
// String source = logEvent.getSource().toString();
|
||||
// boBussinessLog.setActionTime(DateUtils.date());
|
||||
// boBussinessLog.setSource(source);
|
||||
// BoUsers boUsers = boUsersService.currentUser();
|
||||
//
|
||||
// switch (logEnum) {
|
||||
//
|
||||
// case IDNEXPAGE:
|
||||
// boBussinessLog.setAction(BoActionEnum.VISIT.getCategory());
|
||||
// boBussinessLog.setPageName("首页");
|
||||
// break;
|
||||
// case LOGIN:
|
||||
// boBussinessLog.setAction(BoActionEnum.SUBMIT.getCategory());
|
||||
// break;
|
||||
// case AcvityDETAIL:
|
||||
// boBussinessLog.setAction(BoActionEnum.VISIT.getCategory());
|
||||
// boBussinessLog.setPageName("活动详情页");
|
||||
// boBussinessLog.setActivityInstanceId(boActivityInstance.getId());
|
||||
// break;
|
||||
// case MYACTIVITIES:
|
||||
// boBussinessLog.setAction(BoActionEnum.VISIT.getCategory());
|
||||
// boBussinessLog.setPageName("我的活动");
|
||||
// case SHARECODE:
|
||||
// boBussinessLog.setAction(BoActionEnum.SUBMIT.getCategory());
|
||||
// boBussinessLog.setPageName("分享活动");
|
||||
// break;
|
||||
// case SIGNUP:
|
||||
// boBussinessLog.setAction(BoActionEnum.SUBMIT.getCategory());
|
||||
// boBussinessLog.setPageName("分享活动");
|
||||
// break;
|
||||
// case REGISTER:
|
||||
// boBussinessLog.setAction(BoActionEnum.SUBMIT.getCategory());
|
||||
// boBussinessLog.setPageName("注册");
|
||||
// break;
|
||||
// default:
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// Long operatorId = boUsers == null ? 0L : boUsers.getId();
|
||||
// boBussinessLog.setUserId(operatorId);
|
||||
// boBussinessLogService.saveOrUpdate(boBussinessLog, operatorId);
|
||||
// }
|
||||
//}
|
||||
|
||||
@ -1,105 +0,0 @@
|
||||
package com.bsd.cases.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.bsd.cases.mapper.BoWechatMiniMapper;
|
||||
import com.bsd.cases.mapper.ScheduledTaskMapper;
|
||||
import com.bsd.cases.model.BoWechatMini;
|
||||
import com.bsd.cases.service.WxSubscribeMessageService;
|
||||
import com.bsd.cases.util.HttpRequestUtils;
|
||||
import com.bsd.cases.util.LogUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
|
||||
@Service("wxSubscribeMessageService")
|
||||
@Transactional
|
||||
public class WxSubscribeMessageServiceImpl implements WxSubscribeMessageService {
|
||||
|
||||
@Value("${wx.SIGNUP_TEMPLATE_ID}")
|
||||
private String SIGNUP_TEMPLATE_ID;
|
||||
|
||||
@Value("${wx.SEND_MESSAGE_URL}")
|
||||
private String SEND_MESSAGE_URL;
|
||||
@Value("${wx.APPID}")
|
||||
private String APPID;
|
||||
@Resource
|
||||
private BoWechatMiniMapper boWechatMiniMapper;
|
||||
@Resource
|
||||
private ScheduledTaskMapper scheduledTaskMapper;
|
||||
private Logger logger = LogUtils.getBussinessLogger();
|
||||
/**
|
||||
* 报名发模板消息
|
||||
* @param activityState 活动状态
|
||||
* @param activityName 活动名称
|
||||
* @param activityPlace 活动地点
|
||||
* @param activityStartTime 活动开始时间
|
||||
* @param note 备注
|
||||
*/
|
||||
@Override
|
||||
public void activitySendMessage(String activityState,String activityName,String activityPlace,
|
||||
String activityStartTime,String note,String openId,String page) {
|
||||
BoWechatMini findBoWechatMini = new BoWechatMini();
|
||||
findBoWechatMini.setMiniAppid(APPID);
|
||||
findBoWechatMini.setState(1);
|
||||
BoWechatMini boWechatMini = boWechatMiniMapper.selectOne(findBoWechatMini);
|
||||
String accessToken = boWechatMini.getAccessToken();
|
||||
String sendUrl = SEND_MESSAGE_URL + accessToken;
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("touser",openId);
|
||||
jsonObject.put("template_id",SIGNUP_TEMPLATE_ID);
|
||||
jsonObject.put("page",page);
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject phrase1Data = new JSONObject();
|
||||
phrase1Data.put("value",activityState);
|
||||
data.put("phrase1",phrase1Data);
|
||||
JSONObject thing2Data = new JSONObject();
|
||||
thing2Data.put("value",activityName);
|
||||
data.put("thing2",thing2Data);
|
||||
JSONObject thing3Data = new JSONObject();
|
||||
thing3Data.put("value",activityPlace);
|
||||
data.put("thing3",thing3Data);
|
||||
JSONObject date6Data = new JSONObject();
|
||||
date6Data.put("value",activityStartTime);
|
||||
data.put("date6",date6Data);
|
||||
JSONObject thing9Data = new JSONObject();
|
||||
thing9Data.put("value",note);
|
||||
data.put("thing9",thing9Data);
|
||||
jsonObject.put("data",data);
|
||||
try {
|
||||
String result = HttpRequestUtils.sendPost(sendUrl,jsonObject);
|
||||
logger.info("发送活动报名微信模板消息结果:"+result);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动取消发模板消息
|
||||
* @param activityName 活动名称
|
||||
* @param activityTime 活动时间
|
||||
* @param note 备注
|
||||
*/
|
||||
@Override
|
||||
public void cancelActivity(String activityName, String activityTime, String note,String openId) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeActivityPlace(String activityName, String changeTime, String changePlace, String note,String openId) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新定时任务状态,执行完的定时任务置为0,不再初始化
|
||||
* @param scheduledId
|
||||
*/
|
||||
@Override
|
||||
public void updateTaskState(Long scheduledId) {
|
||||
scheduledTaskMapper.updateScheduledTaskInit(scheduledId,0);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue