mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 06:03:42 +08:00
Merge branch 'main' into chat_context
# Conflicts: # mallchat-common/pom.xml # mallchat-custom-server/pom.xml # mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chatai/handler/GPTChatAIHandler.java
This commit is contained in:
@@ -123,6 +123,16 @@
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<version>5.3.19</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.abin.mallchat.common.chat.domain.entity.msg;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Description: 表情图片消息入参
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-06-04
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class EmojisMsgDTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("下载地址")
|
||||
@NotBlank
|
||||
private String url;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.abin.mallchat.common.chat.domain.entity.msg;
|
||||
|
||||
import com.abin.mallchat.common.common.utils.discover.domain.UrlInfo;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -23,7 +24,7 @@ import java.util.Map;
|
||||
public class MessageExtra implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
//url跳转链接
|
||||
private Map<String, String> urlTitleMap;
|
||||
private Map<String, UrlInfo> urlContentMap;
|
||||
//消息撤回详情
|
||||
private MsgRecall recall;
|
||||
//艾特的uid
|
||||
@@ -36,4 +37,9 @@ public class MessageExtra implements Serializable {
|
||||
private SoundMsgDTO soundMsgDTO;
|
||||
//文件消息
|
||||
private VideoMsgDTO videoMsgDTO;
|
||||
|
||||
/**
|
||||
* 表情图片信息
|
||||
*/
|
||||
private EmojisMsgDTO emojisMsgDTO;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ public enum MessageTypeEnum {
|
||||
FILE(4, "文件"),
|
||||
SOUND(5, "语音"),
|
||||
VIDEO(6, "视频"),
|
||||
EMOJI(7, "表情"),
|
||||
;
|
||||
|
||||
private final Integer type;
|
||||
|
||||
@@ -2,9 +2,8 @@ package com.abin.mallchat.common.common.aspect;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.abin.mallchat.common.common.annotation.FrequencyControl;
|
||||
import com.abin.mallchat.common.common.exception.BusinessException;
|
||||
import com.abin.mallchat.common.common.exception.CommonErrorEnum;
|
||||
import com.abin.mallchat.common.common.utils.RedisUtils;
|
||||
import com.abin.mallchat.common.common.domain.dto.FrequencyControlDTO;
|
||||
import com.abin.mallchat.common.common.service.frequencycontrol.FrequencyControlUtil;
|
||||
import com.abin.mallchat.common.common.utils.RequestHolder;
|
||||
import com.abin.mallchat.common.common.utils.SpElUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -15,7 +14,12 @@ import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.abin.mallchat.common.common.service.frequencycontrol.FrequencyControlStrategyFactory.TOTAL_COUNT_WITH_IN_FIX_TIME_FREQUENCY_CONTROLLER;
|
||||
|
||||
/**
|
||||
* Description: 频控实现
|
||||
@@ -48,25 +52,25 @@ public class FrequencyControlAspect {
|
||||
}
|
||||
keyMap.put(prefix + ":" + key, frequencyControl);
|
||||
}
|
||||
//批量获取redis统计的值
|
||||
ArrayList<String> keyList = new ArrayList<>(keyMap.keySet());
|
||||
List<Integer> countList = RedisUtils.mget(keyList, Integer.class);
|
||||
for (int i = 0; i < keyList.size(); i++) {
|
||||
String key = keyList.get(i);
|
||||
Integer count = countList.get(i);
|
||||
FrequencyControl frequencyControl = keyMap.get(key);
|
||||
if (Objects.nonNull(count) && count >= frequencyControl.count()) {//频率超过了
|
||||
log.warn("frequencyControl limit key:{},count:{}", key, count);
|
||||
throw new BusinessException(CommonErrorEnum.FREQUENCY_LIMIT);
|
||||
}
|
||||
}
|
||||
try {
|
||||
return joinPoint.proceed();
|
||||
} finally {
|
||||
//不管成功还是失败,都增加次数
|
||||
keyMap.forEach((k, v) -> {
|
||||
RedisUtils.inc(k, v.time(), v.unit());
|
||||
});
|
||||
}
|
||||
// 将注解的参数转换为编程式调用需要的参数
|
||||
List<FrequencyControlDTO> frequencyControlDTOS = keyMap.entrySet().stream().map(entrySet -> buildFrequencyControlDTO(entrySet.getKey(), entrySet.getValue())).collect(Collectors.toList());
|
||||
// 调用编程式注解
|
||||
return FrequencyControlUtil.executeWithFrequencyControlList(TOTAL_COUNT_WITH_IN_FIX_TIME_FREQUENCY_CONTROLLER, frequencyControlDTOS, joinPoint::proceed);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将注解参数转换为编程式调用所需要的参数
|
||||
*
|
||||
* @param key 频率控制Key
|
||||
* @param frequencyControl 注解
|
||||
* @return 编程式调用所需要的参数-FrequencyControlDTO
|
||||
*/
|
||||
private FrequencyControlDTO buildFrequencyControlDTO(String key, FrequencyControl frequencyControl) {
|
||||
FrequencyControlDTO frequencyControlDTO = new FrequencyControlDTO();
|
||||
frequencyControlDTO.setCount(frequencyControl.count());
|
||||
frequencyControlDTO.setTime(frequencyControl.time());
|
||||
frequencyControlDTO.setUnit(frequencyControl.unit());
|
||||
frequencyControlDTO.setKey(key);
|
||||
return frequencyControlDTO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.abin.mallchat.common.common.config;
|
||||
|
||||
import com.abin.mallchat.common.common.utils.sensitiveWord.DFAFilter;
|
||||
import com.abin.mallchat.common.common.utils.sensitiveWord.SensitiveWordBs;
|
||||
import com.abin.mallchat.common.sensitive.MyWordDeny;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class SensitiveWordConfig {
|
||||
|
||||
@Autowired
|
||||
private MyWordDeny myWordDeny;
|
||||
|
||||
/**
|
||||
* 初始化引导类
|
||||
*
|
||||
* @return 初始化引导类
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@Bean
|
||||
public SensitiveWordBs sensitiveWordBs() {
|
||||
return SensitiveWordBs.newInstance()
|
||||
.filterStrategy(DFAFilter.getInstance())
|
||||
.sensitiveWord(myWordDeny)
|
||||
.init();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.abin.mallchat.common.common.domain.dto;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Data
|
||||
@ToString
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
/** 限流策略定义
|
||||
* @author linzhihan
|
||||
* @date 2023/07/03
|
||||
*
|
||||
*/
|
||||
public class FrequencyControlDTO {
|
||||
/**
|
||||
* 代表频控的Key 如果target为Key的话 这里要传值用于构建redis的Key target为Ip或者UID的话会从上下文取值 Key字段无需传值
|
||||
*/
|
||||
private String key;
|
||||
/**
|
||||
* 频控时间范围,默认单位秒
|
||||
*
|
||||
* @return 时间范围
|
||||
*/
|
||||
private Integer time;
|
||||
|
||||
/**
|
||||
* 频控时间单位,默认秒
|
||||
*
|
||||
* @return 单位
|
||||
*/
|
||||
private TimeUnit unit;
|
||||
|
||||
/**
|
||||
* 单位时间内最大访问次数
|
||||
*
|
||||
* @return 次数
|
||||
*/
|
||||
private Integer count;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.abin.mallchat.common.common.domain.vo.request;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author zhongzb create on 2021/05/31
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class IdReqVO {
|
||||
@ApiModelProperty("id")
|
||||
@NotNull
|
||||
private long id;
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import lombok.Getter;
|
||||
public enum CommonErrorEnum implements ErrorEnum {
|
||||
|
||||
SYSTEM_ERROR(-1, "系统出小差了,请稍后再试哦~~"),
|
||||
PARAM_VALID(-2, "参数校验失败"),
|
||||
PARAM_VALID(-2, "参数校验失败{0}"),
|
||||
FREQUENCY_LIMIT(-3, "请求太频繁了,请稍后再试哦~~"),
|
||||
LOCK_LIMIT(-4, "请求太频繁了,请稍后再试哦~~"),
|
||||
;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.abin.mallchat.common.common.exception;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 自定义限流异常
|
||||
*
|
||||
* @author linzhihan
|
||||
* @date 2023/07/034
|
||||
*/
|
||||
@Data
|
||||
public class FrequencyControlException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
protected Integer errorCode;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
protected String errorMsg;
|
||||
|
||||
public FrequencyControlException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public FrequencyControlException(String errorMsg) {
|
||||
super(errorMsg);
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
|
||||
public FrequencyControlException(ErrorEnum error) {
|
||||
super(error.getErrorMsg());
|
||||
this.errorCode = error.getErrorCode();
|
||||
this.errorMsg = error.getErrorMsg();
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class GlobalExceptionHandler {
|
||||
*/
|
||||
@ExceptionHandler(value = NullPointerException.class)
|
||||
public ApiResult exceptionHandler(NullPointerException e) {
|
||||
log.error("null point exception!The reason is:{}", e.getMessage(), e);
|
||||
log.error("null point exception!The reason is: ", e);
|
||||
return ApiResult.fail(CommonErrorEnum.SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
@@ -73,4 +73,12 @@ public class GlobalExceptionHandler {
|
||||
return ApiResult.fail(-1, String.format("不支持'%s'请求", e.getMethod()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 限流异常
|
||||
*/
|
||||
@ExceptionHandler(value = FrequencyControlException.class)
|
||||
public ApiResult frequencyControlExceptionHandler(FrequencyControlException e) {
|
||||
log.info("frequencyControl exception!The reason is:{}", e.getMessage(), e);
|
||||
return ApiResult.fail(e.getErrorCode(), e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ public class GlobalUncaughtExceptionHandler implements Thread.UncaughtException
|
||||
@Override
|
||||
public void uncaughtException(Thread t, Throwable e) {
|
||||
log.error("Exception in thread {} ", t.getName(), e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.abin.mallchat.common.common.service.frequencycontrol;
|
||||
|
||||
import com.abin.mallchat.common.common.domain.dto.FrequencyControlDTO;
|
||||
import com.abin.mallchat.common.common.exception.CommonErrorEnum;
|
||||
import com.abin.mallchat.common.common.exception.FrequencyControlException;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 抽象类频控服务 其他类如果要实现限流服务 直接注入使用通用限流类
|
||||
* 后期会通过继承此类实现令牌桶等算法
|
||||
*
|
||||
* @author linzhihan
|
||||
* @date 2023/07/03
|
||||
* @see TotalCountWithInFixTimeFrequencyController 通用限流类
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractFrequencyControlService<K extends FrequencyControlDTO> {
|
||||
|
||||
@PostConstruct
|
||||
protected void registerMyselfToFactory() {
|
||||
FrequencyControlStrategyFactory.registerFrequencyController(getStrategyName(), this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param frequencyControlMap 定义的注解频控 Map中的Key-对应redis的单个频控的Key Map中的Value-对应redis的单个频控的Key限制的Value
|
||||
* @param supplier 函数式入参-代表每个频控方法执行的不同的业务逻辑
|
||||
* @return 业务方法执行的返回值
|
||||
* @throws Throwable
|
||||
*/
|
||||
private <T> T executeWithFrequencyControlMap(Map<String, K> frequencyControlMap, SupplierThrowWithoutParam<T> supplier) throws Throwable {
|
||||
if (reachRateLimit(frequencyControlMap)) {
|
||||
throw new FrequencyControlException(CommonErrorEnum.FREQUENCY_LIMIT);
|
||||
}
|
||||
try {
|
||||
return supplier.get();
|
||||
} finally {
|
||||
//不管成功还是失败,都增加次数
|
||||
addFrequencyControlStatisticsCount(frequencyControlMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 多限流策略的编程式调用方法 无参的调用方法
|
||||
*
|
||||
* @param frequencyControlList 频控列表 包含每一个频率控制的定义以及顺序
|
||||
* @param supplier 函数式入参-代表每个频控方法执行的不同的业务逻辑
|
||||
* @return 业务方法执行的返回值
|
||||
* @throws Throwable 被限流或者限流策略定义错误
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T executeWithFrequencyControlList(List<K> frequencyControlList, SupplierThrowWithoutParam<T> supplier) throws Throwable {
|
||||
boolean existsFrequencyControlHasNullKey = frequencyControlList.stream().anyMatch(frequencyControl -> ObjectUtils.isEmpty(frequencyControl.getKey()));
|
||||
AssertUtil.isFalse(existsFrequencyControlHasNullKey, "限流策略的Key字段不允许出现空值");
|
||||
Map<String, FrequencyControlDTO> frequencyControlDTOMap = frequencyControlList.stream().collect(Collectors.groupingBy(FrequencyControlDTO::getKey, Collectors.collectingAndThen(Collectors.toList(), list -> list.get(0))));
|
||||
return executeWithFrequencyControlMap((Map<String, K>) frequencyControlDTOMap, supplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单限流策略的调用方法-编程式调用
|
||||
*
|
||||
* @param frequencyControl 单个频控对象
|
||||
* @param supplier 服务提供着
|
||||
* @return 业务方法执行结果
|
||||
* @throws Throwable
|
||||
*/
|
||||
public <T> T executeWithFrequencyControl(K frequencyControl, SupplierThrowWithoutParam<T> supplier) throws Throwable {
|
||||
return executeWithFrequencyControlList(Collections.singletonList(frequencyControl), supplier);
|
||||
}
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SupplierThrowWithoutParam<T> {
|
||||
|
||||
/**
|
||||
* Gets a result.
|
||||
*
|
||||
* @return a result
|
||||
*/
|
||||
T get() throws Throwable;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Executor {
|
||||
|
||||
/**
|
||||
* Gets a result.
|
||||
*
|
||||
* @return a result
|
||||
*/
|
||||
void execute() throws Throwable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否达到限流阈值 子类实现 每个子类都可以自定义自己的限流逻辑判断
|
||||
*
|
||||
* @param frequencyControlMap 定义的注解频控 Map中的Key-对应redis的单个频控的Key Map中的Value-对应redis的单个频控的Key限制的Value
|
||||
* @return true-方法被限流 false-方法没有被限流
|
||||
*/
|
||||
protected abstract boolean reachRateLimit(Map<String, K> frequencyControlMap);
|
||||
|
||||
/**
|
||||
* 增加限流统计次数 子类实现 每个子类都可以自定义自己的限流统计信息增加的逻辑
|
||||
*
|
||||
* @param frequencyControlMap 定义的注解频控 Map中的Key-对应redis的单个频控的Key Map中的Value-对应redis的单个频控的Key限制的Value
|
||||
*/
|
||||
protected abstract void addFrequencyControlStatisticsCount(Map<String, K> frequencyControlMap);
|
||||
|
||||
/**
|
||||
* 获取策略名称
|
||||
*
|
||||
* @return 策略名称
|
||||
*/
|
||||
protected abstract String getStrategyName();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.abin.mallchat.common.common.service.frequencycontrol;
|
||||
|
||||
import com.abin.mallchat.common.common.domain.dto.FrequencyControlDTO;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 限流策略工厂
|
||||
*
|
||||
* @author linzhihan
|
||||
* @date 2023/07/03
|
||||
*/
|
||||
public class FrequencyControlStrategyFactory {
|
||||
/**
|
||||
* 指定时间内总次数限流
|
||||
*/
|
||||
public static final String TOTAL_COUNT_WITH_IN_FIX_TIME_FREQUENCY_CONTROLLER = "TotalCountWithInFixTime";
|
||||
/**
|
||||
* 限流策略集合
|
||||
*/
|
||||
static Map<String, AbstractFrequencyControlService<?>> frequencyControlServiceStrategyMap = new ConcurrentHashMap<>(8);
|
||||
|
||||
/**
|
||||
* 将策略类放入工厂
|
||||
*
|
||||
* @param strategyName 策略名称
|
||||
* @param abstractFrequencyControlService 策略类
|
||||
*/
|
||||
public static <K extends FrequencyControlDTO> void registerFrequencyController(String strategyName, AbstractFrequencyControlService<K> abstractFrequencyControlService) {
|
||||
frequencyControlServiceStrategyMap.put(strategyName, abstractFrequencyControlService);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名称获取策略类
|
||||
*
|
||||
* @param strategyName 策略名称
|
||||
* @return 对应的限流策略类
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <K extends FrequencyControlDTO> AbstractFrequencyControlService<K> getFrequencyControllerByName(String strategyName) {
|
||||
return (AbstractFrequencyControlService<K>) frequencyControlServiceStrategyMap.get(strategyName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造器私有
|
||||
*/
|
||||
private FrequencyControlStrategyFactory() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.abin.mallchat.common.common.service.frequencycontrol;
|
||||
|
||||
import com.abin.mallchat.common.common.domain.dto.FrequencyControlDTO;
|
||||
import com.abin.mallchat.common.common.utils.AssertUtil;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 限流工具类 提供编程式的限流调用方法
|
||||
*
|
||||
* @author linzhihan
|
||||
* @date 2023/07/03
|
||||
*/
|
||||
public class FrequencyControlUtil {
|
||||
|
||||
/**
|
||||
* 单限流策略的调用方法-编程式调用
|
||||
*
|
||||
* @param strategyName 策略名称
|
||||
* @param frequencyControl 单个频控对象
|
||||
* @param supplier 服务提供着
|
||||
* @return 业务方法执行结果
|
||||
* @throws Throwable
|
||||
*/
|
||||
public static <T, K extends FrequencyControlDTO> T executeWithFrequencyControl(String strategyName, K frequencyControl, AbstractFrequencyControlService.SupplierThrowWithoutParam<T> supplier) throws Throwable {
|
||||
AbstractFrequencyControlService<K> frequencyController = FrequencyControlStrategyFactory.getFrequencyControllerByName(strategyName);
|
||||
return frequencyController.executeWithFrequencyControl(frequencyControl, supplier);
|
||||
}
|
||||
|
||||
public static <K extends FrequencyControlDTO> void executeWithFrequencyControl(String strategyName, K frequencyControl, AbstractFrequencyControlService.Executor executor) throws Throwable {
|
||||
AbstractFrequencyControlService<K> frequencyController = FrequencyControlStrategyFactory.getFrequencyControllerByName(strategyName);
|
||||
frequencyController.executeWithFrequencyControl(frequencyControl, () -> {
|
||||
executor.execute();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 多限流策略的编程式调用方法调用方法
|
||||
*
|
||||
* @param strategyName 策略名称
|
||||
* @param frequencyControlList 频控列表 包含每一个频率控制的定义以及顺序
|
||||
* @param supplier 函数式入参-代表每个频控方法执行的不同的业务逻辑
|
||||
* @return 业务方法执行的返回值
|
||||
* @throws Throwable 被限流或者限流策略定义错误
|
||||
*/
|
||||
public static <T, K extends FrequencyControlDTO> T executeWithFrequencyControlList(String strategyName, List<K> frequencyControlList, AbstractFrequencyControlService.SupplierThrowWithoutParam<T> supplier) throws Throwable {
|
||||
boolean existsFrequencyControlHasNullKey = frequencyControlList.stream().anyMatch(frequencyControl -> ObjectUtils.isEmpty(frequencyControl.getKey()));
|
||||
AssertUtil.isFalse(existsFrequencyControlHasNullKey, "限流策略的Key字段不允许出现空值");
|
||||
AbstractFrequencyControlService<K> frequencyController = FrequencyControlStrategyFactory.getFrequencyControllerByName(strategyName);
|
||||
return frequencyController.executeWithFrequencyControlList(frequencyControlList, supplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造器私有
|
||||
*/
|
||||
private FrequencyControlUtil() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.abin.mallchat.common.common.service.frequencycontrol;
|
||||
|
||||
import com.abin.mallchat.common.common.domain.dto.FrequencyControlDTO;
|
||||
import com.abin.mallchat.common.common.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.abin.mallchat.common.common.service.frequencycontrol.FrequencyControlStrategyFactory.TOTAL_COUNT_WITH_IN_FIX_TIME_FREQUENCY_CONTROLLER;
|
||||
|
||||
/**
|
||||
* 抽象类频控服务 -使用redis实现 固定时间内不超过固定次数的限流类
|
||||
*
|
||||
* @author linzhihan
|
||||
* @date 2023/07/03
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TotalCountWithInFixTimeFrequencyController extends AbstractFrequencyControlService<FrequencyControlDTO> {
|
||||
|
||||
|
||||
/**
|
||||
* 是否达到限流阈值 子类实现 每个子类都可以自定义自己的限流逻辑判断
|
||||
*
|
||||
* @param frequencyControlMap 定义的注解频控 Map中的Key-对应redis的单个频控的Key Map中的Value-对应redis的单个频控的Key限制的Value
|
||||
* @return true-方法被限流 false-方法没有被限流
|
||||
*/
|
||||
@Override
|
||||
protected boolean reachRateLimit(Map<String, FrequencyControlDTO> frequencyControlMap) {
|
||||
//批量获取redis统计的值
|
||||
List<String> frequencyKeys = new ArrayList<>(frequencyControlMap.keySet());
|
||||
List<Integer> countList = RedisUtils.mget(frequencyKeys, Integer.class);
|
||||
for (int i = 0; i < frequencyKeys.size(); i++) {
|
||||
String key = frequencyKeys.get(i);
|
||||
Integer count = countList.get(i);
|
||||
int frequencyControlCount = frequencyControlMap.get(key).getCount();
|
||||
if (Objects.nonNull(count) && count >= frequencyControlCount) {
|
||||
//频率超过了
|
||||
log.warn("frequencyControl limit key:{},count:{}", key, count);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加限流统计次数 子类实现 每个子类都可以自定义自己的限流统计信息增加的逻辑
|
||||
*
|
||||
* @param frequencyControlMap 定义的注解频控 Map中的Key-对应redis的单个频控的Key Map中的Value-对应redis的单个频控的Key限制的Value
|
||||
*/
|
||||
@Override
|
||||
protected void addFrequencyControlStatisticsCount(Map<String, FrequencyControlDTO> frequencyControlMap) {
|
||||
frequencyControlMap.forEach((k, v) -> RedisUtils.inc(k, v.getTime(), v.getUnit()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getStrategyName() {
|
||||
return TOTAL_COUNT_WITH_IN_FIX_TIME_FREQUENCY_CONTROLLER;
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class JwtUtils {
|
||||
DecodedJWT jwt = verifier.verify(token);
|
||||
return jwt.getClaims();
|
||||
} catch (Exception e) {
|
||||
log.info("decode error,token:{}", token, e);
|
||||
log.error("decode error,token:{}", token, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ package com.abin.mallchat.common.common.utils.discover;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.abin.mallchat.common.common.utils.FutureUtils;
|
||||
import com.abin.mallchat.common.common.utils.discover.domain.UrlInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jsoup.Connection;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.springframework.data.util.Pair;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -20,46 +20,55 @@ import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Description: urlTitle查询抽象类
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-05-27
|
||||
* @author zhaoqichao
|
||||
* @date 2023/7/3 16:38
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class AbstractUrlTitleDiscover implements UrlTitleDiscover {
|
||||
public abstract class AbstractUrlDiscover implements UrlDiscover {
|
||||
//链接识别的正则
|
||||
private static final Pattern PATTERN = Pattern.compile("((http|https)://)?(www.)?([\\w_-]+(?:(?:\\.[\\w_-]+)+))([\\w.,@?^=%&:/~+#-]*[\\w@?^=%&/~+#-])?");
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<String, String> getContentTitleMap(String content) {
|
||||
public Map<String, UrlInfo> getUrlContentMap(String content) {
|
||||
|
||||
if (StrUtil.isBlank(content)) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
List<String> matchList = ReUtil.findAll(PATTERN, content, 0);
|
||||
|
||||
//并行请求
|
||||
List<CompletableFuture<Pair<String, String>>> futures = matchList.stream().map(match -> CompletableFuture.supplyAsync(() -> {
|
||||
String title = getUrlTitle(match);
|
||||
return StringUtils.isNotEmpty(title) ? Pair.of(match, title) : null;
|
||||
List<CompletableFuture<Pair<String, UrlInfo>>> futures = matchList.stream().map(match -> CompletableFuture.supplyAsync(() -> {
|
||||
UrlInfo urlInfo = getContent(match);
|
||||
return Objects.isNull(urlInfo) ? null : Pair.of(match, urlInfo);
|
||||
})).collect(Collectors.toList());
|
||||
CompletableFuture<List<Pair<String, String>>> future = FutureUtils.sequenceNonNull(futures);
|
||||
CompletableFuture<List<Pair<String, UrlInfo>>> future = FutureUtils.sequenceNonNull(futures);
|
||||
//结果组装
|
||||
return future.join().stream().collect(Collectors.toMap(Pair::getFirst, Pair::getSecond, (a, b) -> a));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUrlTitle(String url) {
|
||||
public UrlInfo getContent(String url) {
|
||||
Document document = getUrlDocument(assemble(url));
|
||||
if (Objects.isNull(document)) {
|
||||
return null;
|
||||
}
|
||||
return getDocTitle(document);
|
||||
|
||||
return UrlInfo.builder()
|
||||
.title(getTitle(document))
|
||||
.description(getDescription(document))
|
||||
.image(getImage(assemble(url),document)).build();
|
||||
}
|
||||
|
||||
|
||||
private String assemble(String url) {
|
||||
|
||||
if (!StrUtil.startWith(url, "http")) {
|
||||
return "http://" + url;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
@@ -69,8 +78,9 @@ public abstract class AbstractUrlTitleDiscover implements UrlTitleDiscover {
|
||||
connect.timeout(2000);
|
||||
return connect.get();
|
||||
} catch (Exception e) {
|
||||
log.error("find title error:url:{}", matchUrl, e);
|
||||
log.error("find error:url:{}", matchUrl, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.abin.mallchat.common.common.utils.discover;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.jsonwebtoken.lang.Objects;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
/**
|
||||
* @author zhaoqichao
|
||||
* @date 2023/7/3 16:54
|
||||
*/
|
||||
public class CommonUrlDiscover extends AbstractUrlDiscover {
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTitle(Document document) {
|
||||
return document.title();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getDescription(Document document) {
|
||||
String description = document.head().select("meta[name=description]").attr("content");
|
||||
String keywords = document.head().select("meta[name=keywords]").attr("content");
|
||||
String content = StrUtil.isNotBlank(description) ? description : keywords;
|
||||
//只保留一句话的描述
|
||||
return StrUtil.isNotBlank(content) ? content.substring(0, content.indexOf("。")) : content;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getImage(String url, Document document) {
|
||||
String image = document.select("link[type=image/x-icon]").attr("href");
|
||||
//如果没有去匹配含有icon属性的logo
|
||||
String href = StrUtil.isEmpty(image) ? document.select("link[rel$=icon]").attr("href") : image;
|
||||
//如果icon中已经包含了url部分域名
|
||||
if (StrUtil.isNotBlank(StrUtil.removeAny(StrUtil.removeAny(href, "/"), "favicon.ico")) &&
|
||||
StrUtil.containsAny(StrUtil.removePrefix(url, "http://"), StrUtil.removeAny(StrUtil.removeAny(href, "/"), "favicon.ico"))) {
|
||||
return "http://" + StrUtil.removePrefix(href, "/");
|
||||
}
|
||||
//如果url已经包含了logo
|
||||
if (StrUtil.containsAny(url, "favicon")) {
|
||||
return url;
|
||||
}
|
||||
//如果logo中有url
|
||||
if (StrUtil.containsAny(href, "http") || StrUtil.containsAny(href, "https")) {
|
||||
return href;
|
||||
}
|
||||
return StrUtil.format("{}/{}", url, StrUtil.removePrefix(href, "/"));
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.abin.mallchat.common.common.utils.discover;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
/**
|
||||
* Description: 通用的标题解析类
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-05-27
|
||||
*/
|
||||
public class CommonUrlTitleDiscover extends AbstractUrlTitleDiscover {
|
||||
@Override
|
||||
public String getDocTitle(Document document) {
|
||||
return document.title();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.abin.mallchat.common.common.utils.discover;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description: 具有优先级的title查询器
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-05-27
|
||||
*/
|
||||
public class PrioritizedUrlDiscover extends AbstractUrlDiscover {
|
||||
|
||||
private final List<UrlDiscover> urlDiscovers = new ArrayList<>(2);
|
||||
|
||||
public PrioritizedUrlDiscover() {
|
||||
urlDiscovers.add(new WxUrlDiscover());
|
||||
urlDiscovers.add(new CommonUrlDiscover());
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTitle(Document document) {
|
||||
for (UrlDiscover urlDiscover : urlDiscovers) {
|
||||
String urlTitle = urlDiscover.getTitle(document);
|
||||
if (StrUtil.isNotBlank(urlTitle)) {
|
||||
return urlTitle;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getDescription(Document document) {
|
||||
for (UrlDiscover urlDiscover : urlDiscovers) {
|
||||
String urlDescription = urlDiscover.getDescription(document);
|
||||
if (StrUtil.isNotBlank(urlDescription)) {
|
||||
return urlDescription;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getImage(String url, Document document) {
|
||||
for (UrlDiscover urlDiscover : urlDiscovers) {
|
||||
String urlImage = urlDiscover.getImage(url,document);
|
||||
if (StrUtil.isNotBlank(urlImage)) {
|
||||
return urlImage;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.abin.mallchat.common.common.utils.discover;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Description: 具有优先级的title查询器
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-05-27
|
||||
*/
|
||||
public class PrioritizedUrlTitleDiscover extends AbstractUrlTitleDiscover {
|
||||
|
||||
private final List<UrlTitleDiscover> urlTitleDiscovers = new ArrayList<>(2);
|
||||
|
||||
public PrioritizedUrlTitleDiscover() {
|
||||
urlTitleDiscovers.add(new CommonUrlTitleDiscover());
|
||||
urlTitleDiscovers.add(new WxUrlTitleDiscover());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDocTitle(Document document) {
|
||||
for (UrlTitleDiscover urlTitleDiscover : urlTitleDiscovers) {
|
||||
String urlTitle = urlTitleDiscover.getDocTitle(document);
|
||||
if (StrUtil.isNotBlank(urlTitle)) {
|
||||
return urlTitle;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.abin.mallchat.common.common.utils.discover;
|
||||
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.abin.mallchat.common.common.utils.discover.domain.UrlInfo;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zhaoqichao
|
||||
* @date 2023/7/3 16:34
|
||||
*/
|
||||
public interface UrlDiscover {
|
||||
|
||||
|
||||
@Nullable
|
||||
Map<String,UrlInfo> getUrlContentMap(String content);
|
||||
|
||||
@Nullable
|
||||
UrlInfo getContent(String url);
|
||||
|
||||
@Nullable
|
||||
String getTitle(Document document);
|
||||
|
||||
@Nullable
|
||||
String getDescription(Document document);
|
||||
|
||||
@Nullable
|
||||
String getImage(String url, Document document);
|
||||
|
||||
public static void main(String[] args) {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
String longStr = "其中包含一个URL www.baidu.com,一个带有端口号的URL http://www.jd.com:80, 一个带有路径的URL http://mallchat.cn, 还有美团技术文章https://mp.weixin.qq.com/s/hwTf4bDck9_tlFpgVDeIKg ";
|
||||
// String longStr = "一个带有端口号的URL http://www.jd.com:80,";
|
||||
// String longStr = "一个带有路径的URL http://mallchat.cn";
|
||||
PrioritizedUrlDiscover discover = new PrioritizedUrlDiscover();
|
||||
final Map<String, UrlInfo> map = discover.getUrlContentMap(longStr);
|
||||
System.out.println(map);
|
||||
stopWatch.stop();
|
||||
long cost = stopWatch.getTotalTimeMillis();
|
||||
System.out.println(cost);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.abin.mallchat.common.common.utils.discover;
|
||||
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
public interface UrlTitleDiscover {
|
||||
|
||||
|
||||
@Nullable
|
||||
Map<String, String> getContentTitleMap(String content);
|
||||
|
||||
|
||||
@Nullable
|
||||
String getUrlTitle(String url);
|
||||
|
||||
@Nullable
|
||||
String getDocTitle(Document document);
|
||||
|
||||
public static void main(String[] args) {//用异步多任务查询并合并 974 //串行访问的速度1349 1291 1283 1559
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
String longStr = "这是一个很长的字符串再来 www.github.com,其中包含一个URL www.baidu.com,, 一个带有端口号的URL http://www.jd.com:80, 一个带有路径的URL http://mallchat.cn, 还有美团技术文章https://mp.weixin.qq.com/s/hwTf4bDck9_tlFpgVDeIKg ";
|
||||
PrioritizedUrlTitleDiscover discover = new PrioritizedUrlTitleDiscover();
|
||||
Map<String, String> contentTitleMap = discover.getContentTitleMap(longStr);
|
||||
System.out.println(contentTitleMap);
|
||||
//
|
||||
// Jsoup.connect("http:// www.github.com");
|
||||
stopWatch.stop();
|
||||
long cost = stopWatch.getTotalTimeMillis();
|
||||
System.out.println(cost);
|
||||
}//{http://mallchat.cn=MallChat, www.baidu.com=百度一下,你就知道, https://mp.weixin.qq.com/s/hwTf4bDck9_tlFpgVDeIKg=超大规模数据库集群保稳系列之二:数据库攻防演练建设实践, http://www.jd.com:80=京东(JD.COM)-正品低价、品质保障、配送及时、轻松购物!}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.abin.mallchat.common.common.utils.discover;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
/**
|
||||
* Description: 针对微信公众号文章的标题获取类
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-05-27
|
||||
*/
|
||||
public class WxUrlDiscover extends AbstractUrlDiscover {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTitle(Document document) {
|
||||
return document.getElementsByAttributeValue("property", "og:title").attr("content");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getDescription(Document document) {
|
||||
return document.getElementsByAttributeValue("property", "og:description").attr("content");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getImage(String url, Document document) {
|
||||
return document.getElementsByAttributeValue("property", "og:image").attr("content");
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package com.abin.mallchat.common.common.utils.discover;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
/**
|
||||
* Description: 针对微信公众号文章的标题获取类
|
||||
* Author: <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* Date: 2023-05-27
|
||||
*/
|
||||
public class WxUrlTitleDiscover extends AbstractUrlTitleDiscover {
|
||||
@Override
|
||||
public String getDocTitle(Document document) {
|
||||
return document.getElementsByAttributeValue("property", "og:title").attr("content");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.abin.mallchat.common.common.utils.discover.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author zhaoqichao
|
||||
* @date 2023/7/3 16:12
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UrlInfo {
|
||||
/**
|
||||
* 标题
|
||||
**/
|
||||
String title;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
**/
|
||||
String description;
|
||||
|
||||
/**
|
||||
* 网站LOGO
|
||||
**/
|
||||
String image;
|
||||
|
||||
}
|
||||
@@ -136,8 +136,8 @@ public class MinIOTemplate {
|
||||
String uid = Optional.ofNullable(req.getUid()).map(String::valueOf).orElse("000000");
|
||||
cn.hutool.core.lang.UUID uuid = cn.hutool.core.lang.UUID.fastUUID();
|
||||
String suffix = FileNameUtil.getSuffix(req.getFileName());
|
||||
String year = DateUtil.format(new Date(), DatePattern.NORM_YEAR_PATTERN);
|
||||
return req.getFilePath() + StrUtil.SLASH + year + StrUtil.SLASH + uid + StrUtil.SLASH + uuid + StrUtil.DOT + suffix;
|
||||
String yearAndMonth = DateUtil.format(new Date(), DatePattern.NORM_MONTH_PATTERN);
|
||||
return req.getFilePath() + StrUtil.SLASH + yearAndMonth + StrUtil.SLASH + uid + StrUtil.SLASH + uuid + StrUtil.DOT + suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.abin.mallchat.common.common.utils;
|
||||
package com.abin.mallchat.common.common.utils.sensitiveWord;
|
||||
|
||||
import com.abin.mallchat.common.common.algorithm.ac.ACTrie;
|
||||
import com.abin.mallchat.common.common.algorithm.ac.MatchResult;
|
||||
@@ -15,7 +15,7 @@ import java.util.Objects;
|
||||
*
|
||||
* Created by berg on 2023/6/18.
|
||||
*/
|
||||
public class SensitiveWordUtils0 {
|
||||
public class ACFilter implements SensitiveWordFilter {
|
||||
|
||||
private final static char mask_char = '*'; // 替代字符
|
||||
|
||||
@@ -27,7 +27,7 @@ public class SensitiveWordUtils0 {
|
||||
* @param text 文本
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean hasSensitiveWord(String text) {
|
||||
public boolean hasSensitiveWord(String text) {
|
||||
if (StringUtils.isBlank(text)) return false;
|
||||
return !Objects.equals(filter(text), text);
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class SensitiveWordUtils0 {
|
||||
* @param text 待替换文本
|
||||
* @return 替换后的文本
|
||||
*/
|
||||
public static String filter(String text) {
|
||||
public String filter(String text) {
|
||||
if (StringUtils.isBlank(text)) return text;
|
||||
List<MatchResult> matchResults = ac_trie.matches(text);
|
||||
StringBuffer result = new StringBuffer(text);
|
||||
@@ -62,7 +62,7 @@ public class SensitiveWordUtils0 {
|
||||
*
|
||||
* @param words 敏感词数组
|
||||
*/
|
||||
public static void loadWord(List<String> words) {
|
||||
public void loadWord(List<String> words) {
|
||||
if (words == null) return;
|
||||
ac_trie = new ACTrie(words);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.abin.mallchat.common.common.utils;
|
||||
package com.abin.mallchat.common.common.utils.sensitiveWord;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -18,7 +18,10 @@ import java.util.*;
|
||||
* @author zhaoyuhang
|
||||
* @date 2023/06/19
|
||||
*/
|
||||
public final class SensitiveWordUtils {
|
||||
public final class DFAFilter implements SensitiveWordFilter {
|
||||
|
||||
private DFAFilter() {
|
||||
}
|
||||
private static Word root = new Word(' '); // 敏感词字典的根节点
|
||||
private final static char replace = '*'; // 替代字符
|
||||
private final static String skipChars = " !*-+_=,,.@;:;:。、??()()【】[]《》<>“”\"‘’"; // 遇到这些字符就会跳过
|
||||
@@ -30,6 +33,10 @@ public final class SensitiveWordUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static DFAFilter getInstance() {
|
||||
return new DFAFilter();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断文本中是否存在敏感词
|
||||
@@ -37,7 +44,7 @@ public final class SensitiveWordUtils {
|
||||
* @param text 文本
|
||||
* @return true: 存在敏感词, false: 不存在敏感词
|
||||
*/
|
||||
public static boolean hasSensitiveWord(String text) {
|
||||
public boolean hasSensitiveWord(String text) {
|
||||
if (StringUtils.isBlank(text)) return false;
|
||||
return !Objects.equals(filter(text), text);
|
||||
}
|
||||
@@ -48,7 +55,7 @@ public final class SensitiveWordUtils {
|
||||
* @param text 待替换文本
|
||||
* @return 替换后的文本
|
||||
*/
|
||||
public static String filter(String text) {
|
||||
public String filter(String text) {
|
||||
StringBuilder result = new StringBuilder(text);
|
||||
int index = 0;
|
||||
while (index < result.length()) {
|
||||
@@ -93,7 +100,7 @@ public final class SensitiveWordUtils {
|
||||
*
|
||||
* @param words 敏感词数组
|
||||
*/
|
||||
public static void loadWord(List<String> words) {
|
||||
public void loadWord(List<String> words) {
|
||||
if (!CollectionUtils.isEmpty(words)) {
|
||||
Word newRoot = new Word(' ');
|
||||
words.forEach(word -> loadWord(word, newRoot));
|
||||
@@ -106,7 +113,7 @@ public final class SensitiveWordUtils {
|
||||
*
|
||||
* @param word 词
|
||||
*/
|
||||
public static void loadWord(String word, Word root) {
|
||||
public void loadWord(String word, Word root) {
|
||||
if (StringUtils.isBlank(word)) {
|
||||
return;
|
||||
}
|
||||
@@ -136,7 +143,7 @@ public final class SensitiveWordUtils {
|
||||
*
|
||||
* @param path 文本文件的绝对路径
|
||||
*/
|
||||
public static void loadWordFromFile(String path) {
|
||||
public void loadWordFromFile(String path) {
|
||||
try (InputStream inputStream = Files.newInputStream(Paths.get(path))) {
|
||||
loadWord(inputStream);
|
||||
} catch (IOException e) {
|
||||
@@ -150,7 +157,7 @@ public final class SensitiveWordUtils {
|
||||
* @param inputStream 文本文件输入流
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
public static void loadWord(InputStream inputStream) throws IOException {
|
||||
public void loadWord(InputStream inputStream) throws IOException {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
@@ -167,7 +174,7 @@ public final class SensitiveWordUtils {
|
||||
* @param c 待检测字符
|
||||
* @return true: 需要跳过, false: 不需要跳过
|
||||
*/
|
||||
private static boolean skip(char c) {
|
||||
private boolean skip(char c) {
|
||||
return skipSet.contains(c);
|
||||
}
|
||||
|
||||
@@ -186,17 +193,7 @@ public final class SensitiveWordUtils {
|
||||
|
||||
public Word(char c) {
|
||||
this.c = c;
|
||||
this.end = false;
|
||||
this.next = new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String text = "白日,梦";
|
||||
String filter = filter(text);
|
||||
System.out.println(filter);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.abin.mallchat.common.common.utils.sensitiveWord;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 敏感词
|
||||
*
|
||||
* @author zhaoyuhang
|
||||
* @date 2023/07/09
|
||||
*/
|
||||
public interface IWordDeny {
|
||||
/**
|
||||
* 获取结果
|
||||
* @return 结果
|
||||
* @since 0.0.13
|
||||
*/
|
||||
List<String> deny();
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.abin.mallchat.common.common.utils.sensitiveWord;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 敏感词引导类
|
||||
*
|
||||
* @author zhaoyuhang
|
||||
* @date 2023/07/08
|
||||
*/
|
||||
public class SensitiveWordBs {
|
||||
|
||||
/**
|
||||
* 私有化构造器
|
||||
*/
|
||||
private SensitiveWordBs() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 脱敏策略
|
||||
*/
|
||||
private SensitiveWordFilter sensitiveWordFilter = DFAFilter.getInstance();
|
||||
|
||||
/**
|
||||
* 敏感词列表
|
||||
*/
|
||||
private IWordDeny wordDeny;
|
||||
|
||||
public static SensitiveWordBs newInstance() {
|
||||
return new SensitiveWordBs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
* 1. 根据配置,初始化对应的 map。比较消耗性能。
|
||||
* @since 0.0.13
|
||||
* @return this
|
||||
*/
|
||||
public SensitiveWordBs init() {
|
||||
|
||||
List<String> words = wordDeny.deny();
|
||||
loadWord(words);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤策略
|
||||
*
|
||||
* @param filter 过滤器
|
||||
* @return 结果
|
||||
* @since 0.7.0
|
||||
*/
|
||||
public SensitiveWordBs filterStrategy(SensitiveWordFilter filter) {
|
||||
if (filter == null) {
|
||||
throw new IllegalArgumentException("filter can not be null");
|
||||
}
|
||||
this.sensitiveWordFilter = filter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SensitiveWordBs sensitiveWord(IWordDeny wordDeny) {
|
||||
if (wordDeny == null) {
|
||||
throw new IllegalArgumentException("wordDeny can not be null");
|
||||
}
|
||||
this.wordDeny = wordDeny;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 有敏感词
|
||||
*
|
||||
* @param text 文本
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean hasSensitiveWord(String text) {
|
||||
return sensitiveWordFilter.hasSensitiveWord(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤
|
||||
*
|
||||
* @param text 文本
|
||||
* @return {@link String}
|
||||
*/
|
||||
public String filter(String text) {
|
||||
return sensitiveWordFilter.filter(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载敏感词列表
|
||||
*
|
||||
* @param words 敏感词数组
|
||||
*/
|
||||
private void loadWord(List<String> words) {
|
||||
sensitiveWordFilter.loadWord(words);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.abin.mallchat.common.common.utils.sensitiveWord;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 敏感词过滤
|
||||
*
|
||||
* @author zhaoyuhang
|
||||
* @date 2023/07/08
|
||||
*/
|
||||
public interface SensitiveWordFilter {
|
||||
/**
|
||||
* 有敏感词
|
||||
*
|
||||
* @param text 文本
|
||||
* @return boolean
|
||||
*/
|
||||
boolean hasSensitiveWord(String text);
|
||||
|
||||
/**
|
||||
* 过滤
|
||||
*
|
||||
* @param text 文本
|
||||
* @return {@link String}
|
||||
*/
|
||||
String filter(String text);
|
||||
|
||||
/**
|
||||
* 加载敏感词列表
|
||||
*
|
||||
* @param words 敏感词数组
|
||||
*/
|
||||
void loadWord(List<String> words);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.abin.mallchat.common.sensitive;
|
||||
|
||||
import com.abin.mallchat.common.common.utils.sensitiveWord.IWordDeny;
|
||||
import com.abin.mallchat.common.sensitive.dao.SensitiveWordDao;
|
||||
import com.abin.mallchat.common.sensitive.domain.SensitiveWord;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class MyWordDeny implements IWordDeny {
|
||||
@Autowired
|
||||
private SensitiveWordDao sensitiveWordDao;
|
||||
|
||||
@Override
|
||||
public List<String> deny() {
|
||||
return sensitiveWordDao.list()
|
||||
.stream()
|
||||
.map(SensitiveWord::getWord)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.abin.mallchat.common.sensitive.service;
|
||||
|
||||
public interface ISensitiveWordService {
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.abin.mallchat.common.sensitive.service.impl;
|
||||
|
||||
import com.abin.mallchat.common.common.utils.SensitiveWordUtils;
|
||||
import com.abin.mallchat.common.sensitive.dao.SensitiveWordDao;
|
||||
import com.abin.mallchat.common.sensitive.domain.SensitiveWord;
|
||||
import com.abin.mallchat.common.sensitive.service.ISensitiveWordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SensitiveWordServiceImpl implements ISensitiveWordService {
|
||||
@Autowired
|
||||
private SensitiveWordDao sensitiveWordDao;
|
||||
@Autowired
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
@PostConstruct
|
||||
public void initSensitiveWord() {
|
||||
threadPoolTaskExecutor.execute(() -> {
|
||||
log.info("[initSensitiveWord] start");
|
||||
List<SensitiveWord> list = sensitiveWordDao.list();
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
List<String> wordList = list.stream()
|
||||
.map(SensitiveWord::getWord)
|
||||
.collect(Collectors.toList());
|
||||
SensitiveWordUtils.loadWord(wordList);
|
||||
}
|
||||
log.info("[initSensitiveWord] end; loading sensitiveWords num:{}", list.size());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.abin.mallchat.common.user.dao;
|
||||
|
||||
import com.abin.mallchat.common.user.domain.entity.UserEmoji;
|
||||
import com.abin.mallchat.common.user.mapper.UserEmojiMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表情包 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* @since 2023-07-09
|
||||
*/
|
||||
@Service
|
||||
public class UserEmojiDao extends ServiceImpl<UserEmojiMapper, UserEmoji> {
|
||||
|
||||
public List<UserEmoji> listByUid(Long uid) {
|
||||
return lambdaQuery().eq(UserEmoji::getUid, uid).list();
|
||||
}
|
||||
|
||||
public int countByUid(Long uid) {
|
||||
return lambdaQuery().eq(UserEmoji::getUid, uid).count();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.abin.mallchat.common.user.domain.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表情包
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* @since 2023-07-09
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("user_emoji")
|
||||
public class UserEmoji implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户表ID
|
||||
*/
|
||||
@TableField("uid")
|
||||
private Long uid;
|
||||
|
||||
/**
|
||||
* 表情地址
|
||||
*/
|
||||
@TableField("expression_url")
|
||||
private String expressionUrl;
|
||||
|
||||
/**
|
||||
* 逻辑删除(0-正常,1-删除)
|
||||
*/
|
||||
@TableField("delete_status")
|
||||
@TableLogic(value = "0", delval = "1")
|
||||
private Integer deleteStatus;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField("create_time")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField("update_time")
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.abin.mallchat.common.user.mapper;
|
||||
|
||||
import com.abin.mallchat.common.user.domain.entity.UserEmoji;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表情包 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author <a href="https://github.com/zongzibinbin">abin</a>
|
||||
* @since 2023-07-09
|
||||
*/
|
||||
public interface UserEmojiMapper extends BaseMapper<UserEmoji> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.abin.mallchat.common.user.mapper;
|
||||
|
||||
import com.abin.mallchat.common.user.domain.entity.UserEmoji;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 用户表情包 Mapper
|
||||
*
|
||||
* @author: WuShiJie
|
||||
* @createTime: 2023/7/3 14:24
|
||||
*/
|
||||
public interface UserEmojisMapper extends BaseMapper<UserEmoji> {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.abin.mallchat.common.user.mapper.UserEmojiMapper">
|
||||
|
||||
</mapper>
|
||||
@@ -1,63 +0,0 @@
|
||||
package com.abin.mallchat.common.common.algorithm.ac;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by berg on 2023/6/18.
|
||||
*/
|
||||
public class ACTrieTest {
|
||||
|
||||
private final static List<String> ALPHABET = Lists.newArrayList("abc", "bcd", "cde");
|
||||
|
||||
private static ACTrie trie(List<String> keywords) {
|
||||
return new ACTrie(keywords);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_TextIsLongerThanKeyword() {
|
||||
final ACTrie trie = trie(ALPHABET);
|
||||
final String text = " " + ALPHABET.get(0);
|
||||
List<MatchResult> matchResults = trie.matches(text);
|
||||
checkResult(matchResults.get(0), 1, 4, ALPHABET.get(0), text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_VariousKeywordsOneMatch() {
|
||||
final ACTrie trie = trie(ALPHABET);
|
||||
final String text = "bcd";
|
||||
List<MatchResult> matchResults = trie.matches(text);
|
||||
checkResult(matchResults.get(0), 0, 3, ALPHABET.get(1), text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_VariousKeywordsMultiMatch() {
|
||||
final ACTrie trie = trie(ALPHABET);
|
||||
final String text = "abcd";
|
||||
List<MatchResult> matchResults = trie.matches(text);
|
||||
assertEquals(2, matchResults.size());
|
||||
checkResult(matchResults.get(0), 0, 3, ALPHABET.get(0), text);
|
||||
checkResult(matchResults.get(1), 1, 4, ALPHABET.get(1), text);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_VariousKeywordsMultiMatch2() {
|
||||
final ACTrie trie = trie(ALPHABET);
|
||||
final String text = "abcde";
|
||||
List<MatchResult> matchResults = trie.matches(text);
|
||||
assertEquals(3, matchResults.size());
|
||||
checkResult(matchResults.get(0), 0, 3, ALPHABET.get(0), text);
|
||||
checkResult(matchResults.get(1), 1, 4, ALPHABET.get(1), text);
|
||||
checkResult(matchResults.get(2), 2, 5, ALPHABET.get(2), text);
|
||||
}
|
||||
|
||||
private void checkResult(MatchResult matchResult, int expectedStart, int expectedEnd, String expectedKeyword, String text) {
|
||||
assertEquals("Start of match should have been " + expectedStart, expectedStart, matchResult.getStartIndex());
|
||||
assertEquals("End of match should have been " + expectedEnd, expectedEnd, matchResult.getEndIndex());
|
||||
assertEquals(expectedKeyword, text.substring(expectedStart, expectedEnd));
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.abin.mallchat.common.common.algorithm.ac;
|
||||
|
||||
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
import com.auth0.jwt.interfaces.JWTVerifier;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class CreateTokenTest {
|
||||
|
||||
@Test
|
||||
public void create(){
|
||||
String token = JWT.create()
|
||||
.withClaim("uid", 123L) // 只存一个uid信息,其他的自己去redis查
|
||||
.withClaim("createTime", new Date())
|
||||
.sign(Algorithm.HMAC256("dsfsdfsdfsdfsd")); // signature
|
||||
log.info("生成的token为 {}",token);
|
||||
|
||||
|
||||
try {
|
||||
JWTVerifier verifier = JWT.require(Algorithm.HMAC256("dsfsdfsdfsdfsd")).build();
|
||||
DecodedJWT jwt = verifier.verify(token);
|
||||
log.info(jwt.getClaims().toString());
|
||||
} catch (Exception e) {
|
||||
log.info("decode error,token:{}", token, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyToken(){
|
||||
String token = JWT.create()
|
||||
.withClaim("uid", 1) // 只存一个uid信息,其他的自己去redis查
|
||||
.withClaim("createTime", new Date())
|
||||
.sign(Algorithm.HMAC256("dsfsdfsdfsdfsd")); // signature
|
||||
log.info("生成的token为{}",token);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user