parent
9aec66d1a7
commit
acf448e980
@ -1,44 +1,44 @@
|
||||
package cn.teammodel.manager;
|
||||
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiRobotSendRequest;
|
||||
import com.taobao.api.ApiException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 钉钉告警服务
|
||||
* @author winter
|
||||
* @create 2023-11-14 10:11
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DingAlertNotifier implements NotificationService{
|
||||
private final DingTalkClient client;
|
||||
@Autowired
|
||||
public DingAlertNotifier(@Value("${ding.server-url}") String dingServerUrl) {
|
||||
this.client = new DefaultDingTalkClient(dingServerUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(String message) {
|
||||
OapiRobotSendRequest request = new OapiRobotSendRequest();
|
||||
// 文本消息
|
||||
request.setMsgtype("text");
|
||||
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
|
||||
text.setContent(message);
|
||||
request.setText(text);
|
||||
// at 管理员提醒异常
|
||||
OapiRobotSendRequest.At atAll = new OapiRobotSendRequest.At();
|
||||
atAll.setIsAtAll(true);
|
||||
request.setAt(atAll);
|
||||
try {
|
||||
client.execute(request);
|
||||
} catch (ApiException e) {
|
||||
log.error("钉钉 robot 推送消息渠道异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
package cn.teammodel.manager.notification;
|
||||
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiRobotSendRequest;
|
||||
import com.taobao.api.ApiException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 钉钉告警服务
|
||||
* @author winter
|
||||
* @create 2023-11-14 10:11
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DingAlertNotifier implements NotificationService{
|
||||
private final DingTalkClient client;
|
||||
@Autowired
|
||||
public DingAlertNotifier(@Value("${ding.server-url}") String dingServerUrl) {
|
||||
this.client = new DefaultDingTalkClient(dingServerUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(String message) {
|
||||
OapiRobotSendRequest request = new OapiRobotSendRequest();
|
||||
// 文本消息
|
||||
request.setMsgtype("text");
|
||||
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
|
||||
text.setContent(message);
|
||||
request.setText(text);
|
||||
// at 管理员提醒异常
|
||||
OapiRobotSendRequest.At atAll = new OapiRobotSendRequest.At();
|
||||
atAll.setIsAtAll(true);
|
||||
request.setAt(atAll);
|
||||
try {
|
||||
client.execute(request);
|
||||
} catch (ApiException e) {
|
||||
log.error("钉钉 robot 推送消息渠道异常: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
package cn.teammodel.manager;
|
||||
|
||||
/**
|
||||
* 消息通知接口
|
||||
* @author winter
|
||||
* @create 2023-11-14 10:08
|
||||
*/
|
||||
public interface NotificationService {
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @author: winter
|
||||
* @date: 2023/11/14 10:09
|
||||
*/
|
||||
void send(String message);
|
||||
}
|
||||
package cn.teammodel.manager.notification;
|
||||
|
||||
/**
|
||||
* 消息通知接口
|
||||
* @author winter
|
||||
* @create 2023-11-14 10:08
|
||||
*/
|
||||
public interface NotificationService {
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @author: winter
|
||||
* @date: 2023/11/14 10:09
|
||||
*/
|
||||
void send(String message);
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package cn.teammodel.manager.wx;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author winter
|
||||
* @create 2024-03-26 11:08
|
||||
*/
|
||||
@Service
|
||||
public class MiniProgramSevice {
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package cn.teammodel.security.filter;
|
||||
|
||||
import cn.teammodel.security.utils.JwtTokenUtil;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContext;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 对外的 AI chat 接口的认证过滤器
|
||||
* @author winter
|
||||
* @create 2023-11-09 10:43
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ApiAuthTokenFilter extends OncePerRequestFilter {
|
||||
|
||||
@Resource
|
||||
private JwtTokenUtil jwtTokenUtil;
|
||||
|
||||
// todo: 修改 context 的值 + 写一下多过滤器链的复盘
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull FilterChain filterChain) throws ServletException, IOException {
|
||||
SecurityContext context = SecurityContextHolder.getContext();
|
||||
// 验证 authToken 合法
|
||||
String token = request.getHeader("token");
|
||||
if (StringUtils.isBlank(token)) {
|
||||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
Claims claims = jwtTokenUtil.validAndGetClaims(token, "fXO6ko/qyXeYrkecPeKdgXnuLXf9vMEtnBC9OB3s+aA=", 315360000);
|
||||
if (claims == null) {
|
||||
SecurityContextHolder.clearContext(); // 验证失败不应该在此处抛出异常,应该维护好 context 的值,以便整个过滤器链正常运行
|
||||
filterChain.doFilter(request, response);
|
||||
return;
|
||||
}
|
||||
// 组装 authToken 的 jwt 进 authentication
|
||||
UsernamePasswordAuthenticationToken finalAuthentication = new UsernamePasswordAuthenticationToken(claims, null, null);
|
||||
context.setAuthentication(finalAuthentication);
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue