This commit is contained in:
2024-05-09 21:48:20 +08:00
58 changed files with 3137 additions and 69 deletions

View File

@@ -31,7 +31,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<version>1.18.24</version>
</dependency>
</dependencies>
</project>

View File

@@ -14,6 +14,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
@@ -22,7 +23,7 @@
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<version>1.18.24</version>
</path>
<!-- 必须要加, 否则生成不了 MapperImpl 实现类 -->
<path>

View File

@@ -0,0 +1,32 @@
package com.schisandra.auth.application.config;
import com.schisandra.auth.application.convert.SchisandraSmsConfigDTOConvert;
import com.schisandra.auth.application.dto.SchisandraSmsConfigDTO;
import com.schisandra.auth.domain.bo.SchisandraSmsConfigBO;
import com.schisandra.auth.domain.service.SchisandraSmsConfigDomainService;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import javax.annotation.Resource;
import java.util.List;
@Configuration
public class SmsInitConfig {
@Resource
SmsReadConfig smsReadConfig;
@Resource
SchisandraSmsConfigDomainService schisandraSmsConfigDomainService;
@EventListener
public void init(ContextRefreshedEvent event){
List<SchisandraSmsConfigBO> SchisandraSmsConfigBOs= schisandraSmsConfigDomainService.queryAll();
List<SchisandraSmsConfigDTO> schisandraSmsConfigDTOS = SchisandraSmsConfigDTOConvert.INSTANCE.convertBOToDTOList(SchisandraSmsConfigBOs);
for (SchisandraSmsConfigDTO schisandraSmsConfig : schisandraSmsConfigDTOS){
System.out.println(schisandraSmsConfig.toString());
if (schisandraSmsConfig!=null){
// 创建SmsBlend 短信实例
SmsFactory.createSmsBlend(smsReadConfig);
};
}}
}

View File

@@ -0,0 +1,89 @@
package com.schisandra.auth.application.config;
import com.schisandra.auth.application.convert.SchisandraSmsConfigDTOConvert;
import com.schisandra.auth.application.dto.SchisandraSmsConfigDTO;
import com.schisandra.auth.domain.bo.SchisandraSmsConfigBO;
import com.schisandra.auth.domain.service.SchisandraSmsConfigDomainService;
import com.schisandra.auth.infra.basic.dao.SchisandraSmsConfigDao;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import org.dromara.sms4j.aliyun.config.AlibabaConfig;
import org.dromara.sms4j.huawei.config.HuaweiConfig;
import org.dromara.sms4j.provider.config.BaseConfig;
import org.dromara.sms4j.tencent.config.TencentConfig;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* @Classname SmsConfig
* @BelongsProject: schisandra-cloud-storage
* @BelongsPackage: com.schisandra.auth.common.config
* @Author: landaiqing
* @CreateTime: 2024-05-08 18:46
* @Description: TODO
* @Version: 1.0
*/
@Component
public class SmsReadConfig implements org.dromara.sms4j.core.datainterface.SmsReadConfig {
@Resource
SchisandraSmsConfigDomainService schisandraSmsConfigDomainService;
@Override
public BaseConfig getSupplierConfig(String configId) {
return null;
}
@Override
public List<BaseConfig> getSupplierConfigList() {
List<BaseConfig> configs = new ArrayList<>();
List<SchisandraSmsConfigBO> SchisandraSmsConfigBOs= schisandraSmsConfigDomainService.queryAll();
List<SchisandraSmsConfigDTO> schisandraSmsConfigDTOS = SchisandraSmsConfigDTOConvert.INSTANCE.convertBOToDTOList(SchisandraSmsConfigBOs);
for (SchisandraSmsConfigDTO schisandraSmsConfig : schisandraSmsConfigDTOS){
if ("alibaba".equals(schisandraSmsConfig.getConfigId())) {
AlibabaConfig alibabaConfig = new AlibabaConfig();
alibabaConfig.setConfigId(schisandraSmsConfig.getConfigId());
alibabaConfig.setRequestUrl(schisandraSmsConfig.getRequestUrl());
alibabaConfig.setAccessKeyId(schisandraSmsConfig.getAccessKeyId());
alibabaConfig.setAccessKeySecret(schisandraSmsConfig.getAccessKeySecret());
alibabaConfig.setSignature(schisandraSmsConfig.getSignature());
alibabaConfig.setTemplateId(schisandraSmsConfig.getTemplateId());
alibabaConfig.setTemplateName(schisandraSmsConfig.getTemplateName());
alibabaConfig.setSdkAppId(schisandraSmsConfig.getSdkAppId());
configs.add(alibabaConfig);
}
if ("tencent".equals(schisandraSmsConfig.getConfigId())) {
TencentConfig tencentConfig=new TencentConfig();
tencentConfig.setConfigId(schisandraSmsConfig.getConfigId());
tencentConfig.setAccessKeyId(schisandraSmsConfig.getAccessKeyId());
tencentConfig.setAccessKeySecret(schisandraSmsConfig.getAccessKeySecret());
tencentConfig.setSdkAppId(schisandraSmsConfig.getSdkAppId());
tencentConfig.setService(schisandraSmsConfig.getSdkAppId());
tencentConfig.setRequestUrl(schisandraSmsConfig.getRequestUrl());
tencentConfig.setTerritory(schisandraSmsConfig.getRegion());
tencentConfig.setAction(schisandraSmsConfig.getAction());
tencentConfig.setSignature(schisandraSmsConfig.getSignature());
tencentConfig.setTemplateId(schisandraSmsConfig.getTemplateId());
tencentConfig.setVersion(schisandraSmsConfig.getVersion());
tencentConfig.setConnTimeout(schisandraSmsConfig.getConnTimeout());
tencentConfig.setSdkAppId(schisandraSmsConfig.getSdkAppId());
configs.add(tencentConfig);
}
if ("huawei".equals(schisandraSmsConfig.getConfigId())) {
HuaweiConfig huaweiConfig = new HuaweiConfig();
huaweiConfig.setConfigId(schisandraSmsConfig.getConfigId());
huaweiConfig.setSdkAppId(schisandraSmsConfig.getSdkAppId());
huaweiConfig.setAccessKeySecret(schisandraSmsConfig.getAccessKeySecret());
huaweiConfig.setAccessKeyId(schisandraSmsConfig.getAccessKeyId());
huaweiConfig.setUrl(schisandraSmsConfig.getUrl());
huaweiConfig.setSignature(schisandraSmsConfig.getSignature());
huaweiConfig.setTemplateId(schisandraSmsConfig.getTemplateId());
configs.add(huaweiConfig);
}}
return configs;
}
}

View File

@@ -0,0 +1,107 @@
package com.schisandra.auth.application.controller;
import cn.hutool.core.lang.Assert;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Base64;
@RestController
@RequestMapping("/ReactRotateCaptcha/")
@Slf4j
public class ReactRotateCaptchaController {
@PostMapping (value = "get", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<String> get(){
//前端可以直接根据URL/image/{图片id} 来获取图片 注意:资源文件ID最好进行加密和设置有效期
// 在实际开发中 一般先通过图片id查看数据库有没有这条记录
String imageFilePath = "D:\\java_project\\schisandra-cloud-storage\\schisandra-cloud-storage-auth\\schisandra-cloud-storage-auth-application\\schisandra-cloud-storage-auth-application-controller\\src\\main\\java\\com\\schisandra\\auth\\application\\image\\test1.png";
File file = new File(imageFilePath);
try {
BufferedImage bufferedImage = ImageIO.read(file);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", byteArrayOutputStream);
byte[] imageBytes = byteArrayOutputStream.toByteArray(); // 读取图片数据的字节数组
// 将图片字节数组转换为Base64编码的字符串
String base64Image = Base64.getEncoder().encodeToString(imageBytes);
System.out.println(base64Image);
// 创建包含Base64编码的响应体的ResponseEntity对象并设置正确的媒体类型和内容长度
return ResponseEntity.ok().contentType(MediaType.IMAGE_PNG)
.body(base64Image);
}catch (Exception e) {
e.printStackTrace();
}
return ResponseEntity.ok().body(null);
}
/**
* 请求图片地址, 返回的结果进行base64编码
* @param imgUrl 图片地址
* @return
*/
// public static String requestUrlToBase64(String imgUrl) {
// //读取图片字节数组
// byte[] data = null;
// try {
// InputStream in = new FileInputStream(imgUrl);
//// System.out.println("文件大小(字节)=" + in.available());
// data = new byte[in.available()];
// in.read(data);
// in.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// //对字节数组进行Base64编码得到Base64编码的字符串
// return new String(Base64.encodeBase64(data));
//
// }
//
// public static File convertBase64ToFile(String fileBase64String, String filePath, String fileName) {
// BufferedOutputStream bos = null;
// FileOutputStream fos = null;
// File file = null;
// try {
// File dir = new File(filePath);
// //判断文件目录是否存在
// if (!dir.exists() && dir.isDirectory()) {
// dir.mkdirs();
// }
// byte[] bfile = Base64.decodeBase64(fileBase64String);
// file = new File(filePath + File.separator + fileName);
// fos = new FileOutputStream(file);
// bos = new BufferedOutputStream(fos);
// bos.write(bfile);
// return file;
// } catch (Exception e) {
// e.printStackTrace();
// } finally {
// if (bos != null) {
// try {
// bos.close();
// } catch (IOException e1) {
// e1.printStackTrace();
// }
// }
// if (fos != null) {
// try {
// fos.close();
// } catch (IOException e1) {
// e1.printStackTrace();
// }
// }
// }
// return null;
// }
}

View File

@@ -1,16 +1,13 @@
package com.schisandra.auth.application.controller;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Preconditions;
import com.schisandra.auth.application.convert.SchisandraAuthUserDTOConverter;
import com.schisandra.auth.application.dto.SchisandraAuthUserDTO;
import com.schisandra.auth.common.entity.Result;
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
import com.schisandra.auth.domain.service.SchisandraAuthUserDomainService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
@@ -28,7 +25,6 @@ import javax.annotation.Resource;
public class SchisandraAuthUserController {
@Resource
private SchisandraAuthUserDomainService schisandraAuthUserDomainService;
/**
* @description 更新用户信息
* @param schisandraAuthUserDTO

View File

@@ -0,0 +1,51 @@
package com.schisandra.auth.application.controller;
import com.schisandra.auth.common.entity.Result;
import com.schisandra.auth.common.redis.RedisUtil;
import com.schisandra.auth.common.utils.SmsCodeUtils;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import static java.util.concurrent.TimeUnit.SECONDS;
@RestController
@RequestMapping("/sms/")
@Slf4j
public class SchisandraSmsController {
@Resource
private RedisUtil redisUtil;
private final String authPhonePrefix="auth.phone";
/**
* @description: 发送短信验证码
* @param: [phone]
* @return: com.schisandra.auth.common.entity.Result
* @author zlg
* @date: 2024/5/8 22:53
*/
@GetMapping("/sendByTemplate")
public Result sendByTemplate(String phone) {
String prefix = redisUtil.buildKey(authPhonePrefix, phone);
String code = SmsCodeUtils.generateValidateCode(4).toString();
if (!redisUtil.exist(prefix)){
SmsResponse smsResponse=SmsFactory.getBySupplier("alibaba").sendMessage(phone,code);
if (smsResponse.isSuccess()){
redisUtil.setNx(prefix, code, 60L,SECONDS);
return Result.ok();
}else {
return Result.fail();
}
}else {
return Result.fail("发送频繁,请稍后重试");
}
}
}

View File

@@ -0,0 +1,43 @@
package com.schisandra.auth.application.convert;
import com.schisandra.auth.application.dto.SchisandraSmsConfigDTO;
import com.schisandra.auth.domain.bo.SchisandraSmsConfigBO;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* (SchisandraSmsConfig)实体类
*
* @author makejava
* @since 2024-05-08 20:09:54
*/
@Mapper(componentModel = "spring")
public interface SchisandraSmsConfigDTOConvert {
SchisandraSmsConfigDTOConvert INSTANCE = Mappers.getMapper(SchisandraSmsConfigDTOConvert.class);
/**
* @description 将bo转换为实体
* @param schisandraSmsConfigDTO
* @return com.schisandra.auth.infra.basic.entity.SchisandraAuthUser
* @author landaiqing
* @date 2024/3/21 23:13
*/
SchisandraSmsConfigBO convertDTOToBO(SchisandraSmsConfigDTO schisandraSmsConfigDTO);
/**
* @description 将实体转换为bo
* @param schisandraSmsConfigBO
* @return com.schisandra.auth.domain.bo.SchisandraAuthUserBO
* @author landaiqing
* @date 2024/3/21 23:13
*/
SchisandraSmsConfigDTO convertBOToDTO(SchisandraSmsConfigBO schisandraSmsConfigBO);
List<SchisandraSmsConfigDTO> convertBOToDTOList(List<SchisandraSmsConfigBO> schisandraSmsConfigBO);
}

View File

@@ -0,0 +1,155 @@
package com.schisandra.auth.application.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* (SchisandraSmsConfig)实体类
*
* @author makejava
* @since 2024-05-08 20:09:54
*/
@Data
public class SchisandraSmsConfigDTO implements Serializable {
/**
* id
*/
private Integer id;
/**
* 配置id
*/
private String configId;
/**
* 请求地址
*/
private String requestUrl;
/**
* 模板变量名称
*/
private String templateName;
/**
* 接口名称
*/
private String action;
/**
* 地域信息
*/
private String region;
private String accessKeyId;
private String accessKeySecret;
/**
* 厂商名称标识
*/
private String supplier;
/**
* 短信签名
*/
private String signature;
private String sdkAppId;
/**
* 模板ID
*/
private String templateId;
/**
* 权重
*/
private Integer weight;
/**
* 短信重试次数默认0次不重试
*/
private Integer retryInterval;
/**
* 短信重试次数默认0次不重试
*/
private Integer maxRetries;
/**
* 厂商的发送数量上限,默认不设置上限
*/
private Long maximum;
/**
* REST API Base URL
*/
private String baseUrl;
/**
* 请求域名
*/
private String serverIp;
/**
* 请求端口
*/
private Integer serverPort;
/**
* 国内短信签名通道号
*/
private String sender;
/**
* 短信状态报告接收地
*/
private String statusCallBack;
/**
* APP接入地址
*/
private String url;
/**
* 模板短信请求地址
*/
private String templateUrl;
/**
* 验证码短信请求地址
*/
private String codeUrl;
/**
* 验证码验证请求地址
*/
private String verifyUrl;
/**
* 是否需要支持短信上行。true:需要false:不需要false
*/
private String needUp;
/**
* 请求超时时间
*/
private Integer connTimeout;
/**
* 是否为简易模式
*/
private String isSimple;
/**
* 短信发送后将向这个地址推送(运营商返回的)发送报告
*/
private String callbackUrl;
/**
* 企业ID
*/
private Integer mchId;
private String appKey;
private Integer appId;
/**
* 版本号
*/
private String version;
/**
* 单发链接
*/
private String singleMsgUrl;
/**
* 群发链接
*/
private String massMsgUrl;
/**
* 签名ID
*/
private String signatureId;
}

View File

@@ -36,7 +36,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
@@ -128,5 +128,18 @@
<artifactId>guava</artifactId>
<version>29.0-jre</version>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.codec</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-extra</artifactId>
<version>5.8.27</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,46 @@
package com.schisandra.auth.common.redis;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* Redis的config处理
*
* @author: landaiqing
*/
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(redisSerializer);
redisTemplate.setHashKeySerializer(redisSerializer);
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer());
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer());
return redisTemplate;
}
private Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer() {
Jackson2JsonRedisSerializer<Object> jsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
jsonRedisSerializer.setObjectMapper(objectMapper);
return jsonRedisSerializer;
}
}

View File

@@ -0,0 +1,107 @@
package com.schisandra.auth.common.redis;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* RedisUtil工具类
*
* @author: landaiqing
* @date: 2024/2/19
*/
@Component
@Slf4j
public class RedisUtil {
@Resource
private RedisTemplate redisTemplate;
private static final String CACHE_KEY_SEPARATOR = ".";
/**
* 构建缓存key
*/
public String buildKey(String... strObjs) {
return Stream.of(strObjs).collect(Collectors.joining(CACHE_KEY_SEPARATOR));
}
/**
* 是否存在key
*/
public boolean exist(String key) {
return redisTemplate.hasKey(key);
}
/**
* 删除key
*/
public boolean del(String key) {
return redisTemplate.delete(key);
}
/**
* set(不带过期)
*/
public void set(String key, String value) {
redisTemplate.opsForValue().set(key, value);
}
/**
* set(带过期)
*/
public boolean setNx(String key, String value, Long time, TimeUnit timeUnit) {
return redisTemplate.opsForValue().setIfAbsent(key, value, time, timeUnit);
}
/**
* 获取string类型缓存
*/
public String get(String key) {
return (String) redisTemplate.opsForValue().get(key);
}
public Boolean zAdd(String key, String value, Long score) {
return redisTemplate.opsForZSet().add(key, value, Double.valueOf(String.valueOf(score)));
}
public Long countZset(String key) {
return redisTemplate.opsForZSet().size(key);
}
public Set<String> rangeZset(String key, long start, long end) {
return redisTemplate.opsForZSet().range(key, start, end);
}
public Long removeZset(String key, Object value) {
return redisTemplate.opsForZSet().remove(key, value);
}
public void removeZsetList(String key, Set<String> value) {
value.stream().forEach((val) -> redisTemplate.opsForZSet().remove(key, val));
}
public Double score(String key, Object value) {
return redisTemplate.opsForZSet().score(key, value);
}
public Set<String> rangeByScore(String key, long start, long end) {
return redisTemplate.opsForZSet().rangeByScore(key, Double.valueOf(String.valueOf(start)), Double.valueOf(String.valueOf(end)));
}
public Object addScore(String key, Object obj, double score) {
return redisTemplate.opsForZSet().incrementScore(key, obj, score);
}
public Object rank(String key, Object obj) {
return redisTemplate.opsForZSet().rank(key, obj);
}
}

View File

@@ -0,0 +1,110 @@
package com.schisandra.auth.common.utils;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.Random;
/**
* @ClassName AESUtils 一定要选择16位密钥长度也就是KEY_LENGTH=16*836的话就需要修改环境的jar包。
* @Description TODO
* @Author L
* @Date 2024/1/26 17:27
*/
public class AESUtils {
/**
* 加密算法AES
*/
private static final String KEY_ALGORITHM = "AES";
/**
* key的长度Wrong key size: must be equal to 128, 192 or 256
* 传入时需要16、24、36
*/
private static final int KEY_LENGTH = 16 * 8;
/**
* 算法名称/加密模式/数据填充方式
* 默认AES/ECB/PKCS5Padding
*/
private static final String ALGORITHMS = "AES/ECB/PKCS5Padding";
/**
* 后端AES的key由静态代码块赋值
*/
public static String key;
static {
key = getKey();
}
/**
* 获取key
*/
public static String getKey() {
int length = KEY_LENGTH / 8;
StringBuilder uid = new StringBuilder(length);
//产生32位的强随机数
Random rd = new SecureRandom();
for (int i = 0; i < length; i++) {
//产生0-2的3位随机数
switch (rd.nextInt(3)) {
case 0:
//0-9的随机数
uid.append(rd.nextInt(10));
break;
case 1:
//ASCII在65-90之间为大写,获取大写随机
uid.append((char) (rd.nextInt(26) + 65));
break;
case 2:
//ASCII在97-122之间为小写获取小写随机
uid.append((char) (rd.nextInt(26) + 97));
break;
default:
break;
}
}
return uid.toString();
}
/**
* AES 加密
*
* @param content 加密的字符串
* @param encryptKey key值
*/
public static String encrypt(String content, String encryptKey) throws Exception {
//设置Cipher对象
Cipher cipher = Cipher.getInstance(ALGORITHMS);
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(encryptKey.getBytes(), KEY_ALGORITHM));
//调用doFinal
// 转base64
return Base64.encodeBase64String(cipher.doFinal(content.getBytes(StandardCharsets.UTF_8)));
}
/**
* AES 解密
*
* @param encryptStr 解密的字符串
* @param decryptKey 解密的key值
*/
public static String decrypt(String encryptStr, String decryptKey) throws Exception {
//base64格式的key字符串转byte
byte[] decodeBase64 = Base64.decodeBase64(encryptStr);
//设置Cipher对象
Cipher cipher = Cipher.getInstance(ALGORITHMS);
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(decryptKey.getBytes(), KEY_ALGORITHM));
//调用doFinal解密
return new String(cipher.doFinal(decodeBase64));
}
}

View File

@@ -0,0 +1,61 @@
package com.schisandra.auth.common.utils;
import java.security.MessageDigest;
public class MD5Util {
//十六进制下数字到字符的映射数组
private final static String[] hexDigits = {"0", "1", "2", "3", "4",
"5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
/**
* 把inputString加密
*/
public static String md5(String inputString) {
return encodeByMD5(inputString);
}
/**
* 对字符串进行MD5加密
*/
private static String encodeByMD5(String originString) {
if (originString != null) {
try {
//创建具有指定算法名称的信息摘要
MessageDigest md = MessageDigest.getInstance("MD5");
//使用指定的字节数组对摘要进行最后更新,然后完成摘要计算
byte[] results = md.digest(originString.getBytes("utf-8"));
//将得到的字节数组变成字符串返回
String resultString = byteArrayToHexString(results);
return resultString.toUpperCase();
} catch (Exception ex) {
ex.printStackTrace();
}
}
return null;
}
/**
* 转换字节数组为十六进制字符串
*
* @param
* @return 十六进制字符串
*/
private static String byteArrayToHexString(byte[] b) {
StringBuffer resultSb = new StringBuffer();
for (int i = 0; i < b.length; i++) {
resultSb.append(byteToHexString(b[i]));
}
return resultSb.toString();
}
private static String byteToHexString(byte b) {
int n = b;
if (n < 0) {
n += 256;
}
int d1 = n / 16;
int d2 = n % 16;
return hexDigits[d1] + hexDigits[d2];
}
}

View File

@@ -0,0 +1,171 @@
package com.schisandra.auth.common.utils;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @ClassName RSAUtils
* @Description TODO
* @Author L
* @Date 2024/1/26 17:28
*/
public class RSAUtils {
/**
* 加密算法RSA
*/
private static final String KEY_ALGORITHM = "RSA";
/**
* 算法名称/加密模式/数据填充方式
* 默认RSA/ECB/PKCS1Padding
*/
private static final String ALGORITHMS = "RSA/ECB/PKCS1Padding";
/**
* RSA最大加密明文大小
*/
private static final int MAX_ENCRYPT_BLOCK = 245;
/**
* RSA最大解密密文大小
*/
private static final int MAX_DECRYPT_BLOCK = 256;
/**
* RSA 位数 如果采用2048 上面最大加密和最大解密则须填写: 245 256
*/
private static final int INITIALIZE_LENGTH = 2048;
/**
* 后端RSA的密钥对(公钥和私钥)Map由静态代码块赋值
*/
private static final Map<String, String> map = new LinkedHashMap<>(2);
/**
* 生成密钥对(公钥和私钥)
*/
public static Map<String,String> genKeyPair() throws Exception {
KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM);
keyPairGen.initialize(INITIALIZE_LENGTH);
KeyPair keyPair = keyPairGen.generateKeyPair();
// 获取公钥
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
// 获取私钥
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
// 得到公钥字符串
String publicKeyString = Base64.encodeBase64String(publicKey.getEncoded());
// 得到私钥字符串
String privateKeyString = Base64.encodeBase64String((privateKey.getEncoded()));
map.put("publicKey",publicKeyString);
map.put("privateKey",privateKeyString);
return map;
}
public static String getPrivateKey(){
return map.get("privateKey");
}
public static String getPublicKey(){
return map.get("publicKey");
}
/**
* RSA私钥解密
* @param data BASE64编码过的密文
* @param privateKey 私钥(BASE64编码)
* @return utf-8编码的明文
*/
public static byte[] decryptByPrivateKey(byte[] data, String privateKey) throws Exception {
//base64格式的key字符串转Key对象
Key privateK = KeyFactory.getInstance(KEY_ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)));
Cipher cipher = Cipher.getInstance(ALGORITHMS);
cipher.init(Cipher.DECRYPT_MODE, privateK);
//分段进行解密操作
return encryptAndDecryptOfSubsection(data, cipher, MAX_DECRYPT_BLOCK);
}
/**
* RSA公钥加密
* @param data BASE64编码过的密文
* @param publicKey 公钥(BASE64编码)
* @return utf-8编码的明文
*/
public static byte[] encryptByPublicKey(byte[] data, String publicKey) throws Exception {
//base64格式的key字符串转Key对象
Key publicK = KeyFactory.getInstance(KEY_ALGORITHM).generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(publicKey)));
Cipher cipher = Cipher.getInstance(ALGORITHMS);
cipher.init(Cipher.ENCRYPT_MODE, publicK);
//分段进行加密操作
return encryptAndDecryptOfSubsection(data, cipher, MAX_ENCRYPT_BLOCK);
}
/**
* RSA公钥解密
* @param data BASE64编码过的密文
* @param publicKey RSA公钥
* @return utf-8编码的明文
*/
public static byte[] pubKeyDec(byte[] data, String publicKey) throws Exception {
//base64格式的key字符串转Key对象
Key privateK = KeyFactory.getInstance(KEY_ALGORITHM).generatePublic(new X509EncodedKeySpec(Base64.decodeBase64(publicKey)));
Cipher cipher = Cipher.getInstance(ALGORITHMS);
cipher.init(Cipher.DECRYPT_MODE, privateK);
//分段进行解密操作
return encryptAndDecryptOfSubsection(data, cipher, MAX_DECRYPT_BLOCK);
}
/**
* RSA私钥加密
* @param data 待加密的明文
* @param privateKey RSA私钥
* @return 经BASE64编码后的密文
*/
public static byte[] privKeyEnc(byte[] data, String privateKey) throws Exception {
//base64格式的key字符串转Key对象
Key publicK = KeyFactory.getInstance(KEY_ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKey)));
Cipher cipher = Cipher.getInstance(ALGORITHMS);
cipher.init(Cipher.ENCRYPT_MODE, publicK);
//分段进行加密操作
return encryptAndDecryptOfSubsection(data, cipher, MAX_ENCRYPT_BLOCK);
}
/**
* 分段进行加密、解密操作
*/
private static byte[] encryptAndDecryptOfSubsection(byte[] data, Cipher cipher, int encryptBlock) throws Exception {
int inputLen = data.length;
ByteArrayOutputStream out = new ByteArrayOutputStream();
int offSet = 0;
byte[] cache;
int i = 0;
// 对数据分段加密
while (inputLen - offSet > 0) {
if (inputLen - offSet > encryptBlock) {
cache = cipher.doFinal(data, offSet, encryptBlock);
} else {
cache = cipher.doFinal(data, offSet, inputLen - offSet);
}
out.write(cache, 0, cache.length);
i++;
offSet = i * encryptBlock;
}
out.close();
return out.toByteArray();
}
}

View File

@@ -0,0 +1,32 @@
package com.schisandra.auth.common.utils;
import java.util.Random;
public class SmsCodeUtils {
public static Integer generateValidateCode(int length){
Integer code =null;
//长度为4
if(length == 4){
//生成随机数最大为9999
code = new Random().nextInt(9999);
if(code < 1000){
//保证随机数为4位数字
code = code + 1000;
}
//长度为6
}else if(length == 6){
//生成随机数最大为999999
code = new Random().nextInt(999999);
if(code < 100000){
//保证随机数为6位数字
code = code + 100000;
}
//其他情况
}else{
throw new RuntimeException("只能生成4位或6位数字验证码");
}
return code;
}
}

View File

@@ -13,6 +13,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
@@ -21,7 +22,7 @@
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<version>1.18.24</version>
</path>
<!-- 必须要加, 否则生成不了 MapperImpl 实现类 -->
<path>

View File

@@ -13,7 +13,8 @@ import java.util.Date;
* @since 2024-04-15 19:04:11
*/
@Data
public class SchisandraAuthPermissionBO implements Serializable {
public class
SchisandraAuthPermissionBO implements Serializable {
private Long id;

View File

@@ -0,0 +1,155 @@
package com.schisandra.auth.domain.bo;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* (SchisandraSmsConfig)实体类
*
* @author makejava
* @since 2024-05-08 20:09:54
*/
@Data
public class SchisandraSmsConfigBO implements Serializable {
/**
* id
*/
private Integer id;
/**
* 配置id
*/
private String configId;
/**
* 请求地址
*/
private String requestUrl;
/**
* 模板变量名称
*/
private String templateName;
/**
* 接口名称
*/
private String action;
/**
* 地域信息
*/
private String region;
private String accessKeyId;
private String accessKeySecret;
/**
* 厂商名称标识
*/
private String supplier;
/**
* 短信签名
*/
private String signature;
private String sdkAppId;
/**
* 模板ID
*/
private String templateId;
/**
* 权重
*/
private Integer weight;
/**
* 短信重试次数默认0次不重试
*/
private Integer retryInterval;
/**
* 短信重试次数默认0次不重试
*/
private Integer maxRetries;
/**
* 厂商的发送数量上限,默认不设置上限
*/
private Long maximum;
/**
* REST API Base URL
*/
private String baseUrl;
/**
* 请求域名
*/
private String serverIp;
/**
* 请求端口
*/
private Integer serverPort;
/**
* 国内短信签名通道号
*/
private String sender;
/**
* 短信状态报告接收地
*/
private String statusCallBack;
/**
* APP接入地址
*/
private String url;
/**
* 模板短信请求地址
*/
private String templateUrl;
/**
* 验证码短信请求地址
*/
private String codeUrl;
/**
* 验证码验证请求地址
*/
private String verifyUrl;
/**
* 是否需要支持短信上行。true:需要false:不需要false
*/
private String needUp;
/**
* 请求超时时间
*/
private Integer connTimeout;
/**
* 是否为简易模式
*/
private String isSimple;
/**
* 短信发送后将向这个地址推送(运营商返回的)发送报告
*/
private String callbackUrl;
/**
* 企业ID
*/
private Integer mchId;
private String appKey;
private Integer appId;
/**
* 版本号
*/
private String version;
/**
* 单发链接
*/
private String singleMsgUrl;
/**
* 群发链接
*/
private String massMsgUrl;
/**
* 签名ID
*/
private String signatureId;
}

View File

@@ -0,0 +1,48 @@
package com.schisandra.auth.domain.convert;
import com.schisandra.auth.domain.bo.SchisandraAuthUserBO;
import com.schisandra.auth.domain.bo.SchisandraSmsConfigBO;
import com.schisandra.auth.infra.basic.entity.SchisandraAuthUser;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* (SchisandraSmsConfig)实体类
*
* @author makejava
* @since 2024-05-08 20:09:54
*/
@Mapper(componentModel = "spring")
public interface SchisandraSmsConfigBOConvert {
SchisandraSmsConfigBOConvert INSTANCE = Mappers.getMapper(SchisandraSmsConfigBOConvert.class);
/**
* @description 将bo转换为实体
* @param schisandraSmsConfigBO
* @return com.schisandra.auth.infra.basic.entity.SchisandraAuthUser
* @author landaiqing
* @date 2024/3/21 23:13
*/
SchisandraSmsConfig convertBOToEntity(SchisandraSmsConfigBO schisandraSmsConfigBO);
/**
* @description 将实体转换为bo
* @param schisandraSmsConfig
* @return com.schisandra.auth.domain.bo.SchisandraAuthUserBO
* @author landaiqing
* @date 2024/3/21 23:13
*/
SchisandraSmsConfigBO convertEntityToBO(SchisandraSmsConfig schisandraSmsConfig);
List<SchisandraSmsConfigBO> convertEntityToBOList(List<SchisandraSmsConfig> schisandraSmsConfigs);
}

View File

@@ -8,6 +8,6 @@ public interface SchisandraAuthPermissionDomainService {
Object update(SchisandraAuthPermissionBO schisandraAuthPermissionBO);
Object delete(SchisandraAuthPermissionBO schisandraAuthPermissionBO);
Object insert(SchisandraAuthPermissionBO schisandraAuthPermissionBO);
SchisandraAuthPermission select(SchisandraAuthPermissionBO schisandraAuthPermissionBO);
SchisandraAuthPermissionBO select(SchisandraAuthPermissionBO schisandraAuthPermissionBO);
}

View File

@@ -27,7 +27,7 @@ public interface SchisandraAuthUserDomainService {
* @author msz
* @return com.schisandra.auth.infra.basic.entity.SchisandraAuthUser
*/
SchisandraAuthUser queryById(SchisandraAuthUserBO schisandraAuthUserBO);
SchisandraAuthUserBO queryById(SchisandraAuthUserBO schisandraAuthUserBO);
/**
* @description 添加用户信息
* @param schisandraAuthUserBO

View File

@@ -0,0 +1,22 @@
package com.schisandra.auth.domain.service;
import com.schisandra.auth.domain.bo.SchisandraSmsConfigBO;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import java.util.List;
/**
* 用户领域service
*
* @author landaiqing
* @date 2024/3/21
*/
public interface SchisandraSmsConfigDomainService {
List<SchisandraSmsConfigBO> queryAll();
}

View File

@@ -62,11 +62,12 @@ public class SchisandraAuthPermissionDomainServiceImpl implements SchisandraAuth
* @date: 2024/4/17 17:07
*/
@Override
public SchisandraAuthPermission select(SchisandraAuthPermissionBO schisandraAuthPermissionBO) {
public SchisandraAuthPermissionBO select(SchisandraAuthPermissionBO schisandraAuthPermissionBO) {
SchisandraAuthPermission schisandraAuthPermission = SchisandraAuthPermissionBOConverter.INSTANCE.convertBOToEntity(schisandraAuthPermissionBO);
SchisandraAuthPermission schisandraAuthPermission1 =schisandraAuthPermissionService.queryById(schisandraAuthPermission.getId());
return schisandraAuthPermission1;
SchisandraAuthPermissionBO schisandraAuthPermissionBO1 = SchisandraAuthPermissionBOConverter.INSTANCE.convertEntityToBO(schisandraAuthPermission1);
return schisandraAuthPermissionBO1;
}
}

View File

@@ -38,9 +38,10 @@ public class SchisandraAuthUserDomainServiceImpl implements SchisandraAuthUserDo
* @date 2024/4/3 22:10
*/
@Override
public SchisandraAuthUser queryById(SchisandraAuthUserBO schisandraAuthUserBO) {
public SchisandraAuthUserBO queryById(SchisandraAuthUserBO schisandraAuthUserBO) {
SchisandraAuthUser schisandraAuthUser = schisandraAuthUserService.queryById(schisandraAuthUserBO.getId());
return schisandraAuthUser;
SchisandraAuthUserBO schisandraAuthUserBO1 = SchisandraAuthUserBOConverter.INSTANCE.convertEntityToBO(schisandraAuthUser);
return schisandraAuthUserBO1;
}
/**
* @description 添加用户信息

View File

@@ -0,0 +1,26 @@
package com.schisandra.auth.domain.service.impl;
import com.schisandra.auth.domain.bo.SchisandraSmsConfigBO;
import com.schisandra.auth.domain.convert.SchisandraSmsConfigBOConvert;
import com.schisandra.auth.domain.service.SchisandraSmsConfigDomainService;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import com.schisandra.auth.infra.basic.service.SchisandraSmsConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
@Slf4j
public class SchisandraSmsConfigDomainServiceImpl implements SchisandraSmsConfigDomainService {
@Resource
private SchisandraSmsConfigService schisandraSmsConfigService;
@Override
public List<SchisandraSmsConfigBO> queryAll() {
List<SchisandraSmsConfig> schisandraSmsConfigs = schisandraSmsConfigService.queryAll();
return SchisandraSmsConfigBOConvert.INSTANCE.convertEntityToBOList(schisandraSmsConfigs);
}
}

View File

@@ -0,0 +1,86 @@
package com.schisandra.auth.infra.basic.dao;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import java.util.List;
/**
* (SchisandraSmsConfig)表数据库访问层
*
* @author makejava
* @since 2024-05-08 20:09:54
*/
public interface SchisandraSmsConfigDao {
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
SchisandraSmsConfig queryById(Integer id);
/**
* 查询指定行数据
*
* @param schisandraSmsConfig 查询条件
* @param pageable 分页对象
* @return 对象列表
*/
List<SchisandraSmsConfig> queryAllByLimit(SchisandraSmsConfig schisandraSmsConfig, @Param("pageable") Pageable pageable);
List<SchisandraSmsConfig> queryAll();
/**
* 统计总行数
*
* @param schisandraSmsConfig 查询条件
* @return 总行数
*/
long count(SchisandraSmsConfig schisandraSmsConfig);
/**
* 新增数据
*
* @param schisandraSmsConfig 实例对象
* @return 影响行数
*/
int insert(SchisandraSmsConfig schisandraSmsConfig);
/**
* 批量新增数据MyBatis原生foreach方法
*
* @param entities List<SchisandraSmsConfig> 实例对象列表
* @return 影响行数
*/
int insertBatch(@Param("entities") List<SchisandraSmsConfig> entities);
/**
* 批量新增或按主键更新数据MyBatis原生foreach方法
*
* @param entities List<SchisandraSmsConfig> 实例对象列表
* @return 影响行数
* @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常请自行校验入参
*/
int insertOrUpdateBatch(@Param("entities") List<SchisandraSmsConfig> entities);
/**
* 修改数据
*
* @param schisandraSmsConfig 实例对象
* @return 影响行数
*/
int update(SchisandraSmsConfig schisandraSmsConfig);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 影响行数
*/
int deleteById(Integer id);
}

View File

@@ -0,0 +1,174 @@
package com.schisandra.auth.infra.basic.entity;
import lombok.Data;
import java.util.Date;
import java.io.Serializable;
/**
* (SchisandraSmsConfig)实体类
*
* @author makejava
* @since 2024-05-08 20:09:54
*/
@Data
public class SchisandraSmsConfig implements Serializable {
/**
* id
*/
private Integer id;
/**
* 配置id
*/
private String configId;
/**
* 请求地址
*/
private String requestUrl;
/**
* 模板变量名称
*/
private String templateName;
/**
* 接口名称
*/
private String action;
/**
* 地域信息
*/
private String region;
private String accessKeyId;
private String accessKeySecret;
/**
* 厂商名称标识
*/
private String supplier;
/**
* 短信签名
*/
private String signature;
private String sdkAppId;
/**
* 模板ID
*/
private String templateId;
/**
* 权重
*/
private Integer weight;
/**
* 短信重试次数默认0次不重试
*/
private Integer retryInterval;
/**
* 短信重试次数默认0次不重试
*/
private Integer maxRetries;
/**
* 厂商的发送数量上限,默认不设置上限
*/
private Long maximum;
/**
* REST API Base URL
*/
private String baseUrl;
/**
* 请求域名
*/
private String serverIp;
/**
* 请求端口
*/
private Integer serverPort;
/**
* 国内短信签名通道号
*/
private String sender;
/**
* 短信状态报告接收地
*/
private String statusCallBack;
/**
* APP接入地址
*/
private String url;
/**
* 模板短信请求地址
*/
private String templateUrl;
/**
* 验证码短信请求地址
*/
private String codeUrl;
/**
* 验证码验证请求地址
*/
private String verifyUrl;
/**
* 是否需要支持短信上行。true:需要false:不需要false
*/
private String needUp;
/**
* 请求超时时间
*/
private Integer connTimeout;
/**
* 是否为简易模式
*/
private String isSimple;
/**
* 短信发送后将向这个地址推送(运营商返回的)发送报告
*/
private String callbackUrl;
/**
* 企业ID
*/
private Integer mchId;
private String appKey;
private Integer appId;
/**
* 版本号
*/
private String version;
/**
* 单发链接
*/
private String singleMsgUrl;
/**
* 群发链接
*/
private String massMsgUrl;
/**
* 签名ID
*/
private String signatureId;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 更新人
*/
private String updateBy;
/**
* 是否删除 0 未删除 1已删除
*/
private Integer isDeleted;
}

View File

@@ -0,0 +1,60 @@
package com.schisandra.auth.infra.basic.service;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import java.util.List;
/**
* (SchisandraSmsConfig)表服务接口
*
* @author makejava
* @since 2024-05-08 20:09:55
*/
public interface SchisandraSmsConfigService {
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
SchisandraSmsConfig queryById(Integer id);
List<SchisandraSmsConfig> queryAll();
/**
* 分页查询
*
* @param schisandraSmsConfig 筛选条件
* @param pageRequest 分页对象
* @return 查询结果
*/
Page<SchisandraSmsConfig> queryByPage(SchisandraSmsConfig schisandraSmsConfig, PageRequest pageRequest);
/**
* 新增数据
*
* @param schisandraSmsConfig 实例对象
* @return 实例对象
*/
SchisandraSmsConfig insert(SchisandraSmsConfig schisandraSmsConfig);
/**
* 修改数据
*
* @param schisandraSmsConfig 实例对象
* @return 实例对象
*/
SchisandraSmsConfig update(SchisandraSmsConfig schisandraSmsConfig);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 是否成功
*/
boolean deleteById(Integer id);
}

View File

@@ -0,0 +1,88 @@
package com.schisandra.auth.infra.basic.service.impl;
import com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig;
import com.schisandra.auth.infra.basic.dao.SchisandraSmsConfigDao;
import com.schisandra.auth.infra.basic.service.SchisandraSmsConfigService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import javax.annotation.Resource;
import java.util.List;
/**
* (SchisandraSmsConfig)表服务实现类
*
* @author makejava
* @since 2024-05-08 20:09:55
*/
@Service("schisandraSmsConfigService")
public class SchisandraSmsConfigServiceImpl implements SchisandraSmsConfigService {
@Resource
private SchisandraSmsConfigDao schisandraSmsConfigDao;
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
@Override
public SchisandraSmsConfig queryById(Integer id) {
return this.schisandraSmsConfigDao.queryById(id);
}
/**
* 分页查询
*
* @param schisandraSmsConfig 筛选条件
* @param pageRequest 分页对象
* @return 查询结果
*/
@Override
public Page<SchisandraSmsConfig> queryByPage(SchisandraSmsConfig schisandraSmsConfig, PageRequest pageRequest) {
long total = this.schisandraSmsConfigDao.count(schisandraSmsConfig);
return new PageImpl<>(this.schisandraSmsConfigDao.queryAllByLimit(schisandraSmsConfig, pageRequest), pageRequest, total);
}
@Override
public List<SchisandraSmsConfig> queryAll() {
return this.schisandraSmsConfigDao.queryAll();
}
/**
* 新增数据
*
* @param schisandraSmsConfig 实例对象
* @return 实例对象
*/
@Override
public SchisandraSmsConfig insert(SchisandraSmsConfig schisandraSmsConfig) {
this.schisandraSmsConfigDao.insert(schisandraSmsConfig);
return schisandraSmsConfig;
}
/**
* 修改数据
*
* @param schisandraSmsConfig 实例对象
* @return 实例对象
*/
@Override
public SchisandraSmsConfig update(SchisandraSmsConfig schisandraSmsConfig) {
this.schisandraSmsConfigDao.update(schisandraSmsConfig);
return this.queryById(schisandraSmsConfig.getId());
}
/**
* 通过主键删除数据
*
* @param id 主键
* @return 是否成功
*/
@Override
public boolean deleteById(Integer id) {
return this.schisandraSmsConfigDao.deleteById(id) > 0;
}
}

View File

@@ -44,7 +44,7 @@ public class DruidEncryptUtil {
}
public static void main(String[] args) throws Exception {
String encrypt = encrypt("$LDQ20020618xxx$");
String encrypt = encrypt("");
System.out.println("encrypt:" + encrypt);
}

View File

@@ -0,0 +1,499 @@
<?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.schisandra.auth.infra.basic.dao.SchisandraSmsConfigDao">
<resultMap type="com.schisandra.auth.infra.basic.entity.SchisandraSmsConfig" id="SchisandraSmsConfigMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="configId" column="config_id" jdbcType="VARCHAR"/>
<result property="requestUrl" column="request_url" jdbcType="VARCHAR"/>
<result property="templateName" column="template_name" jdbcType="VARCHAR"/>
<result property="action" column="action" jdbcType="VARCHAR"/>
<result property="region" column="region" jdbcType="VARCHAR"/>
<result property="accessKeyId" column="access_key_id" jdbcType="VARCHAR"/>
<result property="accessKeySecret" column="access_key_secret" jdbcType="VARCHAR"/>
<result property="supplier" column="supplier" jdbcType="VARCHAR"/>
<result property="signature" column="signature" jdbcType="VARCHAR"/>
<result property="sdkAppId" column="sdk_app_id" jdbcType="VARCHAR"/>
<result property="templateId" column="template_id" jdbcType="VARCHAR"/>
<result property="weight" column="weight" jdbcType="INTEGER"/>
<result property="retryInterval" column="retry_interval" jdbcType="INTEGER"/>
<result property="maxRetries" column="max_retries" jdbcType="INTEGER"/>
<result property="maximum" column="maximum" jdbcType="INTEGER"/>
<result property="baseUrl" column="base_url" jdbcType="VARCHAR"/>
<result property="serverIp" column="server_ip" jdbcType="VARCHAR"/>
<result property="serverPort" column="server_port" jdbcType="INTEGER"/>
<result property="sender" column="sender" jdbcType="VARCHAR"/>
<result property="statusCallBack" column="status_call_back" jdbcType="VARCHAR"/>
<result property="url" column="url" jdbcType="VARCHAR"/>
<result property="templateUrl" column="template_url" jdbcType="VARCHAR"/>
<result property="codeUrl" column="code_url" jdbcType="VARCHAR"/>
<result property="verifyUrl" column="verify_url" jdbcType="VARCHAR"/>
<result property="needUp" column="need_up" jdbcType="VARCHAR"/>
<result property="connTimeout" column="conn_timeout" jdbcType="INTEGER"/>
<result property="isSimple" column="is_simple" jdbcType="VARCHAR"/>
<result property="callbackUrl" column="callback_url" jdbcType="VARCHAR"/>
<result property="mchId" column="mch_id" jdbcType="INTEGER"/>
<result property="appKey" column="app_key" jdbcType="VARCHAR"/>
<result property="appId" column="app_id" jdbcType="INTEGER"/>
<result property="version" column="version" jdbcType="VARCHAR"/>
<result property="singleMsgUrl" column="single_msg_url" jdbcType="VARCHAR"/>
<result property="massMsgUrl" column="mass_msg_url" jdbcType="VARCHAR"/>
<result property="signatureId" column="signature_Id" jdbcType="VARCHAR"/>
<result property="createdBy" column="created_by" jdbcType="VARCHAR"/>
<result property="createdTime" column="created_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="isDeleted" column="is_deleted" jdbcType="INTEGER"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="SchisandraSmsConfigMap">
select id,config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted
from schisandra_sms_config
where id = #{id}
</select>
<select id="queryAll" resultMap="SchisandraSmsConfigMap">
select
id,config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted
from schisandra_sms_config
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="SchisandraSmsConfigMap">
select
id,config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted
from schisandra_sms_config
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="configId != null and configId != ''">
and config_id = #{configId}
</if>
<if test="requestUrl != null and requestUrl != ''">
and request_url = #{requestUrl}
</if>
<if test="templateName != null and templateName != ''">
and template_name = #{templateName}
</if>
<if test="action != null and action != ''">
and 'action' = #{action}
</if>
<if test="region != null and region != ''">
and region = #{region}
</if>
<if test="accessKeyId != null and accessKeyId != ''">
and access_key_id = #{accessKeyId}
</if>
<if test="accessKeySecret != null and accessKeySecret != ''">
and access_key_secret = #{accessKeySecret}
</if>
<if test="supplier != null and supplier != ''">
and supplier = #{supplier}
</if>
<if test="signature != null and signature != ''">
and signature = #{signature}
</if>
<if test="sdkAppId != null and sdkAppId != ''">
and sdk_app_id = #{sdkAppId}
</if>
<if test="templateId != null and templateId != ''">
and template_id = #{templateId}
</if>
<if test="weight != null">
and weight = #{weight}
</if>
<if test="retryInterval != null">
and retry_interval = #{retryInterval}
</if>
<if test="maxRetries != null">
and max_retries = #{maxRetries}
</if>
<if test="maximum != null">
and maximum = #{maximum}
</if>
<if test="baseUrl != null and baseUrl != ''">
and base_url = #{baseUrl}
</if>
<if test="serverIp != null and serverIp != ''">
and server_ip = #{serverIp}
</if>
<if test="serverPort != null">
and server_port = #{serverPort}
</if>
<if test="sender != null and sender != ''">
and sender = #{sender}
</if>
<if test="statusCallBack != null and statusCallBack != ''">
and status_call_back = #{statusCallBack}
</if>
<if test="url != null and url != ''">
and url = #{url}
</if>
<if test="templateUrl != null and templateUrl != ''">
and template_url = #{templateUrl}
</if>
<if test="codeUrl != null and codeUrl != ''">
and code_url = #{codeUrl}
</if>
<if test="verifyUrl != null and verifyUrl != ''">
and verify_url = #{verifyUrl}
</if>
<if test="needUp != null and needUp != ''">
and need_up = #{needUp}
</if>
<if test="connTimeout != null">
and conn_timeout = #{connTimeout}
</if>
<if test="isSimple != null and isSimple != ''">
and is_simple = #{isSimple}
</if>
<if test="callbackUrl != null and callbackUrl != ''">
and callback_url = #{callbackUrl}
</if>
<if test="mchId != null">
and mch_id = #{mchId}
</if>
<if test="appKey != null and appKey != ''">
and app_key = #{appKey}
</if>
<if test="appId != null">
and app_id = #{appId}
</if>
<if test="version != null and version != ''">
and version = #{version}
</if>
<if test="singleMsgUrl != null and singleMsgUrl != ''">
and single_msg_url = #{singleMsgUrl}
</if>
<if test="massMsgUrl != null and massMsgUrl != ''">
and mass_msg_url = #{massMsgUrl}
</if>
<if test="signatureId != null and signatureId != ''">
and signature_Id = #{signatureId}
</if>
<if test="createdBy != null and createdBy != ''">
and created_by = #{createdBy}
</if>
<if test="createdTime != null">
and created_time = #{createdTime}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="isDeleted != null">
and is_deleted = #{isDeleted}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from schisandra_sms_config
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="configId != null and configId != ''">
and config_id = #{configId}
</if>
<if test="requestUrl != null and requestUrl != ''">
and request_url = #{requestUrl}
</if>
<if test="templateName != null and templateName != ''">
and template_name = #{templateName}
</if>
<if test="action != null and action != ''">
and 'action' = #{action}
</if>
<if test="region != null and region != ''">
and region = #{region}
</if>
<if test="accessKeyId != null and accessKeyId != ''">
and access_key_id = #{accessKeyId}
</if>
<if test="accessKeySecret != null and accessKeySecret != ''">
and access_key_secret = #{accessKeySecret}
</if>
<if test="supplier != null and supplier != ''">
and supplier = #{supplier}
</if>
<if test="signature != null and signature != ''">
and signature = #{signature}
</if>
<if test="sdkAppId != null and sdkAppId != ''">
and sdk_app_id = #{sdkAppId}
</if>
<if test="templateId != null and templateId != ''">
and template_id = #{templateId}
</if>
<if test="weight != null">
and weight = #{weight}
</if>
<if test="retryInterval != null">
and retry_interval = #{retryInterval}
</if>
<if test="maxRetries != null">
and max_retries = #{maxRetries}
</if>
<if test="maximum != null">
and maximum = #{maximum}
</if>
<if test="baseUrl != null and baseUrl != ''">
and base_url = #{baseUrl}
</if>
<if test="serverIp != null and serverIp != ''">
and server_ip = #{serverIp}
</if>
<if test="serverPort != null">
and server_port = #{serverPort}
</if>
<if test="sender != null and sender != ''">
and sender = #{sender}
</if>
<if test="statusCallBack != null and statusCallBack != ''">
and status_call_back = #{statusCallBack}
</if>
<if test="url != null and url != ''">
and url = #{url}
</if>
<if test="templateUrl != null and templateUrl != ''">
and template_url = #{templateUrl}
</if>
<if test="codeUrl != null and codeUrl != ''">
and code_url = #{codeUrl}
</if>
<if test="verifyUrl != null and verifyUrl != ''">
and verify_url = #{verifyUrl}
</if>
<if test="needUp != null and needUp != ''">
and need_up = #{needUp}
</if>
<if test="connTimeout != null">
and conn_timeout = #{connTimeout}
</if>
<if test="isSimple != null and isSimple != ''">
and is_simple = #{isSimple}
</if>
<if test="callbackUrl != null and callbackUrl != ''">
and callback_url = #{callbackUrl}
</if>
<if test="mchId != null">
and mch_id = #{mchId}
</if>
<if test="appKey != null and appKey != ''">
and app_key = #{appKey}
</if>
<if test="appId != null">
and app_id = #{appId}
</if>
<if test="version != null and version != ''">
and version = #{version}
</if>
<if test="singleMsgUrl != null and singleMsgUrl != ''">
and single_msg_url = #{singleMsgUrl}
</if>
<if test="massMsgUrl != null and massMsgUrl != ''">
and mass_msg_url = #{massMsgUrl}
</if>
<if test="signatureId != null and signatureId != ''">
and signature_Id = #{signatureId}
</if>
<if test="createdBy != null and createdBy != ''">
and created_by = #{createdBy}
</if>
<if test="createdTime != null">
and created_time = #{createdTime}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="isDeleted != null">
and is_deleted = #{isDeleted}
</if>
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into schisandra_sms_config(config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted)
values (#{configId},#{requestUrl},#{templateName},#{action},#{region},#{accessKeyId},#{accessKeySecret},#{supplier},#{signature},#{sdkAppId},#{templateId},#{weight},#{retryInterval},#{maxRetries},#{maximum},#{baseUrl},#{serverIp},#{serverPort},#{sender},#{statusCallBack},#{url},#{templateUrl},#{codeUrl},#{verifyUrl},#{needUp},#{connTimeout},#{isSimple},#{callbackUrl},#{mchId},#{appKey},#{appId},#{version},#{singleMsgUrl},#{massMsgUrl},#{signatureId},#{createdBy},#{createdTime},#{updateTime},#{updateBy},#{isDeleted})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into
schisandra_sms_config(config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.configId},#{entity.requestUrl},#{entity.templateName},#{entity.action},#{entity.region},#{entity.accessKeyId},#{entity.accessKeySecret},#{entity.supplier},#{entity.signature},#{entity.sdkAppId},#{entity.templateId},#{entity.weight},#{entity.retryInterval},#{entity.maxRetries},#{entity.maximum},#{entity.baseUrl},#{entity.serverIp},#{entity.serverPort},#{entity.sender},#{entity.statusCallBack},#{entity.url},#{entity.templateUrl},#{entity.codeUrl},#{entity.verifyUrl},#{entity.needUp},#{entity.connTimeout},#{entity.isSimple},#{entity.callbackUrl},#{entity.mchId},#{entity.appKey},#{entity.appId},#{entity.version},#{entity.singleMsgUrl},#{entity.massMsgUrl},#{entity.signatureId},#{entity.createdBy},#{entity.createdTime},#{entity.updateTime},#{entity.updateBy},#{entity.isDeleted})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into
schisandra_sms_config(config_id,request_url,template_name,'action',region,access_key_id,access_key_secret,supplier,signature,sdk_app_id,template_id,weight,retry_interval,max_retries,maximum,base_url,server_ip,server_port,sender,status_call_back,url,template_url,code_url,verify_url,need_up,conn_timeout,is_simple,callback_url,mch_id,app_key,app_id,version,single_msg_url,mass_msg_url,signature_Id,created_by,created_time,update_time,update_by,is_deleted)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.configId},#{entity.requestUrl},#{entity.templateName},#{entity.action},#{entity.region},#{entity.accessKeyId},#{entity.accessKeySecret},#{entity.supplier},#{entity.signature},#{entity.sdkAppId},#{entity.templateId},#{entity.weight},#{entity.retryInterval},#{entity.maxRetries},#{entity.maximum},#{entity.baseUrl},#{entity.serverIp},#{entity.serverPort},#{entity.sender},#{entity.statusCallBack},#{entity.url},#{entity.templateUrl},#{entity.codeUrl},#{entity.verifyUrl},#{entity.needUp},#{entity.connTimeout},#{entity.isSimple},#{entity.callbackUrl},#{entity.mchId},#{entity.appKey},#{entity.appId},#{entity.version},#{entity.singleMsgUrl},#{entity.massMsgUrl},#{entity.signatureId},#{entity.createdBy},#{entity.createdTime},#{entity.updateTime},#{entity.updateBy},#{entity.isDeleted})
</foreach>
on duplicate key update
config_id = values(config_id)request_url = values(request_url)template_name = values(template_name)action =
values(action)region = values(region)access_key_id = values(access_key_id)access_key_secret =
values(access_key_secret)supplier = values(supplier)signature = values(signature)sdk_app_id =
values(sdk_app_id)template_id = values(template_id)weight = values(weight)retry_interval =
values(retry_interval)max_retries = values(max_retries)maximum = values(maximum)base_url =
values(base_url)server_ip = values(server_ip)server_port = values(server_port)sender =
values(sender)status_call_back = values(status_call_back)url = values(url)template_url =
values(template_url)code_url = values(code_url)verify_url = values(verify_url)need_up =
values(need_up)conn_timeout = values(conn_timeout)is_simple = values(is_simple)callback_url =
values(callback_url)mch_id = values(mch_id)app_key = values(app_key)app_id = values(app_id)version =
values(version)single_msg_url = values(single_msg_url)mass_msg_url = values(mass_msg_url)signature_Id =
values(signature_Id)created_by = values(created_by)created_time = values(created_time)update_time =
values(update_time)update_by = values(update_by)is_deleted = values(is_deleted)
</insert>
<!--通过主键修改数据-->
<update id="update">
update schisandra_sms_config
<set>
<if test="configId != null and configId != ''">
config_id = #{configId},
</if>
<if test="requestUrl != null and requestUrl != ''">
request_url = #{requestUrl},
</if>
<if test="templateName != null and templateName != ''">
template_name = #{templateName},
</if>
<if test="action != null and action != ''">
`action` = #{action},
</if>
<if test="region != null and region != ''">
region = #{region},
</if>
<if test="accessKeyId != null and accessKeyId != ''">
access_key_id = #{accessKeyId},
</if>
<if test="accessKeySecret != null and accessKeySecret != ''">
access_key_secret = #{accessKeySecret},
</if>
<if test="supplier != null and supplier != ''">
supplier = #{supplier},
</if>
<if test="signature != null and signature != ''">
signature = #{signature},
</if>
<if test="sdkAppId != null and sdkAppId != ''">
sdk_app_id = #{sdkAppId},
</if>
<if test="templateId != null and templateId != ''">
template_id = #{templateId},
</if>
<if test="weight != null">
weight = #{weight},
</if>
<if test="retryInterval != null">
retry_interval = #{retryInterval},
</if>
<if test="maxRetries != null">
max_retries = #{maxRetries},
</if>
<if test="maximum != null">
maximum = #{maximum},
</if>
<if test="baseUrl != null and baseUrl != ''">
base_url = #{baseUrl},
</if>
<if test="serverIp != null and serverIp != ''">
server_ip = #{serverIp},
</if>
<if test="serverPort != null">
server_port = #{serverPort},
</if>
<if test="sender != null and sender != ''">
sender = #{sender},
</if>
<if test="statusCallBack != null and statusCallBack != ''">
status_call_back = #{statusCallBack},
</if>
<if test="url != null and url != ''">
url = #{url},
</if>
<if test="templateUrl != null and templateUrl != ''">
template_url = #{templateUrl},
</if>
<if test="codeUrl != null and codeUrl != ''">
code_url = #{codeUrl},
</if>
<if test="verifyUrl != null and verifyUrl != ''">
verify_url = #{verifyUrl},
</if>
<if test="needUp != null and needUp != ''">
need_up = #{needUp},
</if>
<if test="connTimeout != null">
conn_timeout = #{connTimeout},
</if>
<if test="isSimple != null and isSimple != ''">
is_simple = #{isSimple},
</if>
<if test="callbackUrl != null and callbackUrl != ''">
callback_url = #{callbackUrl},
</if>
<if test="mchId != null">
mch_id = #{mchId},
</if>
<if test="appKey != null and appKey != ''">
app_key = #{appKey},
</if>
<if test="appId != null">
app_id = #{appId},
</if>
<if test="version != null and version != ''">
version = #{version},
</if>
<if test="singleMsgUrl != null and singleMsgUrl != ''">
single_msg_url = #{singleMsgUrl},
</if>
<if test="massMsgUrl != null and massMsgUrl != ''">
mass_msg_url = #{massMsgUrl},
</if>
<if test="signatureId != null and signatureId != ''">
signature_Id = #{signatureId},
</if>
<if test="createdBy != null and createdBy != ''">
created_by = #{createdBy},
</if>
<if test="createdTime != null">
created_time = #{createdTime},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
<if test="isDeleted != null">
is_deleted = #{isDeleted},
</if>
</set>
where id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete
from schisandra_sms_config
where id = #{id}
</delete>
</mapper>

View File

@@ -0,0 +1,144 @@
/*
Navicat Premium Data Transfer
Source Server : MySQL Cloud
Source Server Type : MySQL
Source Server Version : 50744 (5.7.44)
Source Host : 116.196.80.239:3306
Source Schema : schisandra-cloud-storage
Target Server Type : MySQL
Target Server Version : 50744 (5.7.44)
File Encoding : 65001
Date: 26/04/2024 01:28:16
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for schisandra_auth_permission
-- ----------------------------
DROP TABLE IF EXISTS `schisandra_auth_permission`;
CREATE TABLE `schisandra_auth_permission` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`parent_id` bigint(20) NULL DEFAULT NULL,
`type` tinyint(4) NULL DEFAULT NULL,
`menu_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`status` tinyint(4) NULL DEFAULT NULL,
`show` tinyint(4) NULL DEFAULT NULL,
`icon` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`permission_key` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`created_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建人',
`created_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '更新人',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` int(11) NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of schisandra_auth_permission
-- ----------------------------
INSERT INTO `schisandra_auth_permission` VALUES (1, '普通用户', 0, 1, '1adiwd/awdw', 0, 0, 'httt://1.png', 'subject:add', NULL, NULL, NULL, NULL, 1);
INSERT INTO `schisandra_auth_permission` VALUES (2, '管理员', 0, 1, '1adiwd/awdw', 0, 0, 'httt://1.png', 'subject:add', NULL, NULL, NULL, NULL, 0);
-- ----------------------------
-- Table structure for schisandra_auth_role
-- ----------------------------
DROP TABLE IF EXISTS `schisandra_auth_role`;
CREATE TABLE `schisandra_auth_role` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`role_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`role_key` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`created_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建人',
`created_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '更新人',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` int(11) NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of schisandra_auth_role
-- ----------------------------
INSERT INTO `schisandra_auth_role` VALUES (1, '普通用户', 'normal_user', NULL, NULL, NULL, NULL, 0);
INSERT INTO `schisandra_auth_role` VALUES (2, '管理员', 'admin', NULL, NULL, NULL, NULL, 0);
INSERT INTO `schisandra_auth_role` VALUES (3, '超级管理员', 'super_admin', NULL, NULL, NULL, NULL, 0);
-- ----------------------------
-- Table structure for schisandra_auth_role_permission
-- ----------------------------
DROP TABLE IF EXISTS `schisandra_auth_role_permission`;
CREATE TABLE `schisandra_auth_role_permission` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`role_id` bigint(20) NULL DEFAULT NULL,
`permission_id` bigint(20) NULL DEFAULT NULL,
`created_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建人',
`created_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '更新人',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` int(11) NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of schisandra_auth_role_permission
-- ----------------------------
INSERT INTO `schisandra_auth_role_permission` VALUES (1, 2, 1, NULL, NULL, NULL, NULL, 0);
INSERT INTO `schisandra_auth_role_permission` VALUES (2, 3, 2, NULL, NULL, NULL, NULL, 0);
INSERT INTO `schisandra_auth_role_permission` VALUES (3, 1, 1, NULL, NULL, NULL, NULL, 0);
-- ----------------------------
-- Table structure for schisandra_auth_user
-- ----------------------------
DROP TABLE IF EXISTS `schisandra_auth_user`;
CREATE TABLE `schisandra_auth_user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`nick_name` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`email` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`phone` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`password` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sex` tinyint(4) NULL DEFAULT NULL,
`avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`status` tinyint(4) NULL DEFAULT NULL,
`introduce` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`ext_json` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`created_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建人',
`created_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '更新人',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` int(11) NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of schisandra_auth_user
-- ----------------------------
INSERT INTO `schisandra_auth_user` VALUES (8, 'oF9UX6c2GNEHUpoQZRTrkHTmLYHs', NULL, NULL, NULL, NULL, NULL, 'http://117.72.10.84:9000/user/icon/微信图片_20231203153718(1).png', 0, NULL, NULL, NULL, NULL, NULL, NULL, 0);
INSERT INTO `schisandra_auth_user` VALUES (9, '666', '666', '666', '555', '666', 1, '', 1, '', '', NULL, NULL, NULL, NULL, 1);
-- ----------------------------
-- Table structure for schisandra_auth_user_role
-- ----------------------------
DROP TABLE IF EXISTS `schisandra_auth_user_role`;
CREATE TABLE `schisandra_auth_user_role` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NULL DEFAULT NULL,
`role_id` bigint(20) NULL DEFAULT NULL,
`created_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '创建人',
`created_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_by` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '更新人',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` int(11) NULL DEFAULT 0,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of schisandra_auth_user_role
-- ----------------------------
SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -101,6 +101,35 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</path>
<!-- 必须要加, 否则生成不了 MapperImpl 实现类 -->
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version>
</path>
<!-- 如果是 0.1.0 有可能出现生成了maptruct的实现类, 但该类只创建了对象, 没有进行赋值 -->
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -2,10 +2,10 @@ server:
port: 3000
spring:
datasource:
username: landaiqing
password: Z1JyO9hVmDLYbpWnM7oiFO3BEoDCrV6njYjl/2oudBHwTepxLxnaZ1aDfohrYwYpGWUodgu7gnRcZ5mfIm6lIg==
username: root
password: BZbVbGDBePiA2q8/mt0eMxKNpHniDzxBtOxFadQiAOTDzCDlopC4qOKwwBEi9CAZcuFsCrRJdwn0wP6jwsnzxw==
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://116.196.80.239:3306/schisandra-cloud-storage?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=true
url: jdbc:mysql://1.95.0.111:3306/schisandra-cloud-storage?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=true
type: com.alibaba.druid.pool.DruidDataSource
druid:
initial-size: 20
@@ -32,7 +32,7 @@ spring:
# Redis数据库索引默认为0
database: 1
# Redis服务器地址
host: 116.196.80.239
host: 1.95.0.111
# Redis服务器连接端口
port: 6379
# Redis服务器连接密码默认为空
@@ -49,7 +49,7 @@ spring:
max-idle: 10
# 连接池中的最小空闲连接
min-idle: 0
publicKey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKXX1HPAKowh8Ub9fDTGI5exGLMRppbVQFDlDBBxAWcbfdLN5hXgfg02D7wy+jCe9uCdV5vgZR72PFoe+mnLp80CAwEAAQ==
publicKey: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANUVxjcrVoirBZaNmDrUqatHEW4FOHbO5ynW6zvhIbRMo6hEFGgglbURkjuHOlgEduxJVz6Xa+sG+FMrxTguOJECAwEAAQ==
logging:
config: classpath:log4j2-spring.xml
############## Sa-Token 配置 (文档: https://sa-token.cc) ##############
@@ -67,41 +67,23 @@ sa-token:
# token 风格默认可取值uuid、simple-uuid、random-32、random-64、random-128、tik
token-style: random-32
# 是否输出操作日志
is-log: true
is-log: false
token-prefix: schisandra
is-print: false
#sms:
# # 标注从yml读取配置
# config-type: yaml
# blends:
# # 自定义的标识也就是configId这里可以是任意值最好不要是中文
# tx1:
# #厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
# supplier: tencent
# #您的accessKey
# access-key-id: 您的accessKey
# #您的accessKeySecret
# access-key-secret: 您的accessKeySecret
# #您的短信签名
# signature: 您的短信签名
# #模板ID 非必须配置如果使用sendMessage的快速发送需此配置
# template-id: xxxxxxxx
# #您的sdkAppId
# sdk-app-id: 您的sdkAppId
# # 自定义的标识也就是configId这里可以是任意值最好不要是中文
# tx2:
# #厂商标识,标定此配置是哪个厂商,详细请看厂商标识介绍部分
# supplier: tencent
# #您的accessKey
# access-key-id: 您的accessKey
# #您的accessKeySecret
# access-key-secret: 您的accessKeySecret
# #您的短信签名
# signature: 您的短信签名
# #模板ID 非必须配置如果使用sendMessage的快速发送需此配置
# template-id: xxxxxxxx
# #您的sdkAppId
# sdk-app-id: 您的sdkAppId
sms:
# 标注从yml读取配置
config-type: yaml
restricted: true
accountMax: 10
minuteMax: 1
isPrint: false
HttpLog: true
# mybatis-plus日志
mybatis-plus:
global-config:
banner: false
justauth:
enabled: true

View File

@@ -1,4 +1,4 @@
${AnsiColor.GREEN}
,---,
,--.' | ,--, ,---,

View File

@@ -6,12 +6,12 @@ spring:
cloud:
nacos:
config:
server-addr: 116.196.80.239:8848
server-addr: 1.95.0.111:8848
prefix: ${spring.application.name}
group: DEFAULT_GROUP
namespace:
file-extension: yaml
discovery:
enabled: true
server-addr: 116.196.80.239:8848
server-addr: 1.95.0.111:8848

View File

@@ -7,10 +7,10 @@
<Properties>
<!-- 格式化输出:%date表示日期%thread表示线程名%-5level级别从左显示5个字符宽度 %msg日志消息%n是换行符-->
<!-- %logger{36} 表示 Logger 名字最长36个字符 -->
<property name="LOG_PATTERN" value="%date{HH:mm:ss.SSS} %X{PFTID} [%thread] %-5level %logger{36} - %msg%n" />
<property name="LOG_PATTERN" value="%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%xwEx" />
<!-- 定义日志存储的路径 -->
<property name="FILE_PATH" value="../log" />
<property name="FILE_NAME" value="schisandra-cloud-album.log" />
<property name="FILE_NAME" value="schisandra-cloud-storage.log" />
</Properties>
<!--https://logging.apache.org/log4j/2.x/manual/appenders.html-->

View File

@@ -9,10 +9,125 @@
<name>schisandra-cloud-storage-gateway</name>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-boot.version>2.4.2</spring-boot.version>
<spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
<spring-cloud.version>2020.0.6</spring-cloud.version>
</properties>
<dependencies>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>
<!-- Sa-Token 权限认证Reactor响应式集成, 在线文档https://sa-token.cc -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-reactor-spring-boot-starter</artifactId>
<version>1.37.0</version>
</dependency>
<!-- Sa-Token 整合 Redis (使用 jackson 序列化方式) -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-redis-jackson</artifactId>
<version>1.37.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>${project.artifactId}</finalName>
<!--打包成jar包时的名字-->
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.0.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>central</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>

View File

@@ -0,0 +1,19 @@
package com.schisandra.gateway;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
/**
* 网关启动类
*
* @author: landaiqing
* @date: 2024/2/7
*/
@SpringBootApplication
@ComponentScan("com.schisandra")
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class);
}
}

View File

@@ -0,0 +1,32 @@
package com.schisandra.gateway.auth;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.reactor.filter.SaReactorFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 权限认证的配置器
*
* @author: landaiqing
*/
@Configuration
public class SaTokenConfigure {
@Bean
public SaReactorFilter getSaReactorFilter() {
return new SaReactorFilter()
// 拦截地址
.addInclude("/**")
// 鉴权方法:每次访问进入
.setAuth(obj -> {
System.out.println("-------- 前端访问path" + SaHolder.getRequest().getRequestPath());
// 登录校验 -- 拦截所有路由,并排除/user/doLogin 用于开放登录
//SaRouter.match("/auth/**", "/auth/user/doLogin", r -> StpUtil.checkRole("admin"));
// SaRouter.match("/oss/**", r -> StpUtil.checkLogin());
// SaRouter.match("/subject/subject/add", r -> StpUtil.checkPermission("subject:add"));
// SaRouter.match("/subject/**", r -> StpUtil.checkLogin());
})
;
}
}

View File

@@ -0,0 +1,62 @@
package com.schisandra.gateway.auth;
import cn.dev33.satoken.stp.StpInterface;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.schisandra.gateway.entity.AuthPermission;
import com.schisandra.gateway.entity.AuthRole;
import com.schisandra.gateway.redis.RedisUtil;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
/**
* 自定义权限验证接口扩展
*
* @author: landaiqing
*/
@Component
public class StpInterfaceImpl implements StpInterface {
@Resource
private RedisUtil redisUtil;
private String authPermissionPrefix = "auth.permission";
private String authRolePrefix = "auth.role";
@Override
public List<String> getPermissionList(Object loginId, String loginType) {
return getAuth(loginId.toString(), authPermissionPrefix);
}
@Override
public List<String> getRoleList(Object loginId, String loginType) {
return getAuth(loginId.toString(), authRolePrefix);
}
private List<String> getAuth(String loginId, String prefix) {
String authKey = redisUtil.buildKey(prefix, loginId.toString());
String authValue = redisUtil.get(authKey);
if (StringUtils.isBlank(authValue)) {
return Collections.emptyList();
}
List<String> authList = new LinkedList<>();
if (authRolePrefix.equals(prefix)) {
List<AuthRole> roleList = new Gson().fromJson(authValue, new TypeToken<List<AuthRole>>() {
}.getType());
authList = roleList.stream().map(AuthRole::getRoleKey).collect(Collectors.toList());
} else if (authPermissionPrefix.equals(prefix)) {
List<AuthPermission> permissionList = new Gson().fromJson(authValue, new TypeToken<List<AuthPermission>>() {
}.getType());
authList = permissionList.stream().map(AuthPermission::getPermissionKey).collect(Collectors.toList());
}
return authList;
}
}

View File

@@ -0,0 +1,53 @@
package com.schisandra.gateway.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* (AuthPermission)实体类
*
* @author landaiqing
*/
@Data
public class AuthPermission implements Serializable {
private Long id;
private String name;
private Long parentId;
private Integer type;
private String menuUrl;
private Integer status;
private Integer show;
private String icon;
private String permissionKey;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新时间
*/
private Date updateTime;
private Integer isDeleted;
}

View File

@@ -0,0 +1,42 @@
package com.schisandra.gateway.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* (AuthRole)实体类
*
* @author landaiqing
* @since 2024-2-18 18:55:50
*/
@Data
public class AuthRole implements Serializable {
private Long id;
private String roleName;
private String roleKey;
/**
* 创建人
*/
private String createdBy;
/**
* 创建时间
*/
private Date createdTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新时间
*/
private Date updateTime;
private Integer isDeleted;
}

View File

@@ -0,0 +1,59 @@
package com.schisandra.gateway.entity;
import com.schisandra.gateway.enums.ResultCodeEnum;
import lombok.Data;
@Data
public class Result<T> {
private Boolean success;
private Integer code;
private String message;
private T data;
public static Result ok(){
Result result = new Result();
result.setSuccess(true);
result.setCode(ResultCodeEnum.SUCCESS.getCode());
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
return result;
}
public static <T> Result ok(T data){
Result result = new Result();
result.setSuccess(true);
result.setCode(ResultCodeEnum.SUCCESS.getCode());
result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
result.setData(data);
return result;
}
public static Result fail(){
Result result = new Result();
result.setSuccess(false);
result.setCode(ResultCodeEnum.FAIL.getCode());
result.setMessage(ResultCodeEnum.FAIL.getDesc());
return result;
}
public static <T> Result fail(T data){
Result result = new Result();
result.setSuccess(false);
result.setCode(ResultCodeEnum.FAIL.getCode());
result.setMessage(ResultCodeEnum.FAIL.getDesc());
result.setData(data);
return result;
}
public static Result fail(Integer code,String message){
Result result = new Result();
result.setSuccess(false);
result.setCode(code);
result.setMessage(message);
return result;
}
}

View File

@@ -0,0 +1,24 @@
package com.schisandra.gateway.enums;
import lombok.Getter;
@Getter
public enum ResultCodeEnum {
SUCCESS(200,"成功"),
FAIL(500,"失败");
private int code;
private String desc;
ResultCodeEnum(int code,String desc){
this.code=code;
this.desc=desc;
}
public static ResultCodeEnum getByCode(int codeVal){
for(ResultCodeEnum resultCodeEnum:ResultCodeEnum.values()){
if(resultCodeEnum.code==codeVal){
return resultCodeEnum;
}
}
return null;
}
}

View File

@@ -0,0 +1,55 @@
package com.schisandra.gateway.exception;
import cn.dev33.satoken.exception.SaTokenException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.schisandra.gateway.entity.Result;
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
/**
* @Classname GatewayExceptionHandler
* @BelongsProject: qing-yu-club
* @BelongsPackage: com.landaiqing.club.gateway.exception
* @Author: landaiqing
* @CreateTime: 2024-05-18 17:52
* @Description: 网关全局异常处理
* @Version: 1.0
*/
@Component
public class GatewayExceptionHandler implements ErrorWebExceptionHandler {
private ObjectMapper objectMapper=new ObjectMapper();
@Override
public Mono<Void> handle(ServerWebExchange serverWebExchange, Throwable throwable) {
ServerHttpRequest request = serverWebExchange.getRequest();
ServerHttpResponse response = serverWebExchange.getResponse();
Integer code=200;
String message="";
if(throwable instanceof SaTokenException){
code=401;
message="用户无权限";
}else {
code=500;
message="系统繁忙";
}
Result result = Result.fail(code, message);
response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
return response.writeWith(Mono.fromSupplier(()->{
DataBufferFactory dataBufferFactory=response.bufferFactory();
byte[] bytes=null;
try {
bytes = objectMapper.writeValueAsBytes(result);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return dataBufferFactory.wrap(bytes);
}));
}
}

View File

@@ -0,0 +1,46 @@
package com.schisandra.gateway.filter;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
/**
* @Classname LoginFilter
* @BelongsProject: qing-yu-club
* @BelongsPackage: com.landaiqing.club.gateway.filter
* @Author: landaiqing
* @CreateTime: 2024-03-03 17:41
* @Description: 登录拦截器
* @Version: 1.0
*/
@Component
@Slf4j
public class LoginFilter implements GlobalFilter {
@Override
@SneakyThrows
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
ServerHttpRequest request = exchange.getRequest();
ServerHttpRequest.Builder mutate = request.mutate();
String url = request.getURI().getPath();
log.info("LoginFilter.filter.url:{}", url);
if (url.equals("/user/doLogin") || url.equals("/user/getUserInfo")) {
return chain.filter(exchange);
}
SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
String loginId = (String) tokenInfo.getLoginId();
if (StringUtils.isEmpty(loginId)) {
throw new Exception("未获取到用户信息");
}
mutate.header("loginId", loginId);
return chain.filter(exchange.mutate().request(mutate.build()).build());
}
}

View File

@@ -0,0 +1,49 @@
package com.schisandra.gateway.redis;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* @Classname RedisConfig
* @BelongsProject: qing-yu-club
* @BelongsPackage: com.landaiqing.club.gateway.redis
* @Author: landaiqing
* @CreateTime: 2024-02-18 18:10
* @Description: redis的config处理
* @Version: 1.0
*/
@Configuration
public class RedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(redisSerializer);
redisTemplate.setHashKeySerializer(redisSerializer);
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer());
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer());
return redisTemplate;
}
private Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer() {
Jackson2JsonRedisSerializer<Object> jsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
jsonRedisSerializer.setObjectMapper(objectMapper);
return jsonRedisSerializer;
}
}

View File

@@ -0,0 +1,107 @@
package com.schisandra.gateway.redis;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* RedisUtil工具类
*
* @author: landaiqing
* @date: 2024/2/19
*/
@Component
@Slf4j
public class RedisUtil {
@Resource
private RedisTemplate redisTemplate;
private static final String CACHE_KEY_SEPARATOR = ".";
/**
* 构建缓存key
*/
public String buildKey(String... strObjs) {
return Stream.of(strObjs).collect(Collectors.joining(CACHE_KEY_SEPARATOR));
}
/**
* 是否存在key
*/
public boolean exist(String key) {
return redisTemplate.hasKey(key);
}
/**
* 删除key
*/
public boolean del(String key) {
return redisTemplate.delete(key);
}
/**
* set(不带过期)
*/
public void set(String key, String value) {
redisTemplate.opsForValue().set(key, value);
}
/**
* set(带过期)
*/
public boolean setNx(String key, String value, Long time, TimeUnit timeUnit) {
return redisTemplate.opsForValue().setIfAbsent(key, value, time, timeUnit);
}
/**
* 获取string类型缓存
*/
public String get(String key) {
return (String) redisTemplate.opsForValue().get(key);
}
public Boolean zAdd(String key, String value, Long score) {
return redisTemplate.opsForZSet().add(key, value, Double.valueOf(String.valueOf(score)));
}
public Long countZset(String key) {
return redisTemplate.opsForZSet().size(key);
}
public Set<String> rangeZset(String key, long start, long end) {
return redisTemplate.opsForZSet().range(key, start, end);
}
public Long removeZset(String key, Object value) {
return redisTemplate.opsForZSet().remove(key, value);
}
public void removeZsetList(String key, Set<String> value) {
value.stream().forEach((val) -> redisTemplate.opsForZSet().remove(key, val));
}
public Double score(String key, Object value) {
return redisTemplate.opsForZSet().score(key, value);
}
public Set<String> rangeByScore(String key, long start, long end) {
return redisTemplate.opsForZSet().rangeByScore(key, Double.valueOf(String.valueOf(start)), Double.valueOf(String.valueOf(end)));
}
public Object addScore(String key, Object obj, double score) {
return redisTemplate.opsForZSet().incrementScore(key, obj, score);
}
public Object rank(String key, Object obj) {
return redisTemplate.opsForZSet().rank(key, obj);
}
}

View File

@@ -0,0 +1,57 @@
server:
port: 5000
spring:
cloud:
gateway:
routes:
- id: oss
uri: lb://schisandra-cloud-storage-oss-dev
predicates:
- Path=/oss/**
filters:
- StripPrefix=1
- id: auth
uri: lb://schisandra-cloud-storage-auth-dev
predicates:
- Path=/auth/**
filters:
- StripPrefix=1
# redis配置
redis:
# Redis数据库索引默认为0
database: 1
# Redis服务器地址
host: 116.196.80.239
# Redis服务器连接端口
port: 6379
# Redis服务器连接密码默认为空
password: LDQ20020618xxx
# 连接超时时间
timeout: 2s
lettuce:
pool:
# 连接池最大连接数
max-active: 200
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1ms
# 连接池中的最大空闲连接
max-idle: 10
# 连接池中的最小空闲连接
min-idle: 0
############## Sa-Token 配置 (文档: https://sa-token.cc) ##############
sa-token:
# token 名称(同时也是 cookie 名称)
token-name: token
# token 有效期(单位:秒) 默认30天-1 代表永久有效
timeout: 2592000
# token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结,默认-1 代表不限制,永不冻结
active-timeout: -1
# 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
is-concurrent: true
# 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token
is-share: true
# token 风格默认可取值uuid、simple-uuid、random-32、random-64、random-128、tik
token-style: random-32
# 是否输出操作日志
is-log: true
token-prefix: schisandra

View File

@@ -0,0 +1,17 @@
spring:
application:
name: schisandra-cloud-storage-gateway-dev
profiles:
active: dev
cloud:
nacos:
config:
server-addr: 116.196.80.239:8848
prefix: ${spring.application.name}
group: DEFAULT_GROUP
namespace:
file-extension: yaml
discovery:
enabled: true
server-addr: 116.196.80.239:8848

View File

@@ -38,7 +38,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>

View File

@@ -1,6 +1,6 @@
server:
port: 4000
minio:
url: http://116.196.80.239:9000/
url: http://1.95.0.111:9000/
accessKey: landaiqing
secretKey: LDQ20020618xxx

View File

@@ -6,12 +6,12 @@ spring:
cloud:
nacos:
config:
server-addr: 116.196.80.239:8848
server-addr: 1.95.0.111:8848
prefix: ${spring.application.name}
group: DEFAULT_GROUP
namespace:
file-extension: yaml
discovery:
enabled: true
server-addr: 116.196.80.239:8848
server-addr: 1.95.0.111:8848

View File

@@ -5,7 +5,7 @@
<groupId>com.schisandra</groupId>
<artifactId>schisandra-cloud-storage-wechat</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<packaging>jar</packaging>
<name>schisandra-cloud-storage-wechat</name>
<properties>
@@ -31,7 +31,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -1,12 +1,12 @@
server:
port: 3010
port: 80
spring:
# redis配置
redis:
# Redis数据库索引默认为0
database: 1
# Redis服务器地址
host: 116.196.80.239
host: 1.95.0.111
# Redis服务器连接端口
port: 6379
# Redis服务器连接密码默认为空