前后端加密

pull/166/head
让无线电飞BG8GLR 2025-01-10 12:35:15 +08:00
parent b76ae7dc54
commit 8cfc9728fb
14 changed files with 790 additions and 223 deletions

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.gateway.filter.front;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
*
*
* @author feng
*/
@Data
public class ResponseDto implements Serializable {
@Serial
private static final long serialVersionUID = -6354714160436354659L;
private Integer code;
private String msg;
private Object data;
}

View File

@ -0,0 +1,216 @@
package cn.iocoder.yudao.gateway.util.secret;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
/**
* AES
*
* @author fir
* @date 2020-5-20 11:25
*/
@Slf4j
@SuppressWarnings("all")
public class AESUtils {
private static final Logger logger = LoggerFactory.getLogger(AESUtils.class);
public final static String KEY_ALGORITHMS = "AES";
public final static int KEY_SIZE = 128;
/**
* AESbase64 (128)
* @return
* @throws Exception
*/
public static String getKeyAES_128() throws Exception{
KeyGenerator keyGen = KeyGenerator.getInstance(KEY_ALGORITHMS);
keyGen.init(KEY_SIZE);
SecretKey key = keyGen.generateKey();
String base64str = Base64.encodeBase64String(key.getEncoded());
return base64str;
}
/**
* AESbase64 (256)
* @return
* @throws Exception
*/
public static String getKeyAES_256() throws Exception{
// 256需要换jar包暂时用128
String base64str = getKeyAES_128();
return base64str;
}
/**
* base64KeySecretKey
* @param base64Key
* @return
*/
public static SecretKey loadKeyAES(String base64Key) {
byte[] bytes = Base64.decodeBase64(base64Key);
SecretKeySpec secretKeySpec = new SecretKeySpec(bytes, KEY_ALGORITHMS);
return secretKeySpec;
}
/**
* SecretKey, base64
*
* @return
*/
public static String generateKeyAES() {
String keyBase64Str = null;
String base64Key = "";
try {
base64Key = AESUtils.getKeyAES_128();
} catch (Exception e) {
e.printStackTrace();
log.error("AES密钥生成失败");
}
if(!base64Key.equals("")){
byte[] bytes = Base64.decodeBase64(base64Key);
SecretKeySpec secretKeySpec = new SecretKeySpec(bytes, KEY_ALGORITHMS);
keyBase64Str = Base64.encodeBase64String(secretKeySpec.getEncoded());
}
return keyBase64Str;
}
/**
* AES SecretKey
*
* @param encryptData
* @param key
* @param encode
* @return
*/
public static String encrypt(String encryptData, SecretKey key, String encode) {
try {
final Cipher cipher = Cipher.getInstance(KEY_ALGORITHMS);
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptBytes = encryptData.getBytes(encode);
byte[] result = cipher.doFinal(encryptBytes);
return Base64.encodeBase64String(result);
} catch (Exception e) {
logger.error("加密异常:" + e.getMessage());
return null;
}
}
/**
* AES base64Key
*
* @param encryptData
* @param base64Key
* @param encode
* @return
*/
public static String encrypt(String encryptData, String base64Key, String encode) {
SecretKey key = loadKeyAES(base64Key);
try {
final Cipher cipher = Cipher.getInstance(KEY_ALGORITHMS);
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptBytes = encryptData.getBytes(encode);
byte[] result = cipher.doFinal(encryptBytes);
return Base64.encodeBase64String(result);
} catch (Exception e) {
logger.error("加密异常:" + e.getMessage());
return null;
}
}
/**
* AES base64Key
*
* @param encryptData
* @param base64Key
* @return
*/
public static String encrypt(String encryptData, String base64Key) {
SecretKey key = loadKeyAES(base64Key);
try {
final Cipher cipher = Cipher.getInstance(KEY_ALGORITHMS);
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptBytes = encryptData.getBytes(String.valueOf(StandardCharsets.UTF_8));
byte[] result = cipher.doFinal(encryptBytes);
return Base64.encodeBase64String(result);
} catch (Exception e) {
logger.error("加密异常:" + e.getMessage());
return null;
}
}
/**
* AES SecretKey
*
* @param decryptData
* @param key
* @param encode
* @return
*/
public static String decrypt(String decryptData, SecretKey key, String encode) {
try {
final Cipher cipher = Cipher.getInstance(KEY_ALGORITHMS);
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decryptBytes = Base64.decodeBase64(decryptData);
byte[] result = cipher.doFinal(decryptBytes);
return new String(result, encode);
} catch (Exception e) {
logger.error("加密异常:" + e.getMessage());
return null;
}
}
/**
* AES base64Key
*
* @param decryptData
* @param base64Key
* @param encode
* @return
*/
public static String decrypt(String decryptData, String base64Key, String encode) {
SecretKey key = loadKeyAES(base64Key);
try {
final Cipher cipher = Cipher.getInstance(KEY_ALGORITHMS);
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decryptBytes = Base64.decodeBase64(decryptData);
byte[] result = cipher.doFinal(decryptBytes);
return new String(result, encode);
} catch (Exception e) {
logger.error("加密异常:" + e.getMessage());
return null;
}
}
/**
* AES base64Key
*
* @param decryptData
* @param base64Key
* @return
*/
public static String decrypt(String decryptData, String base64Key) {
SecretKey key = loadKeyAES(base64Key);
try {
final Cipher cipher = Cipher.getInstance(KEY_ALGORITHMS);
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] decryptBytes = Base64.decodeBase64(decryptData);
byte[] result = cipher.doFinal(decryptBytes);
return new String(result, String.valueOf(StandardCharsets.UTF_8));
} catch (Exception e) {
logger.error("解密异常:" + e.getMessage());
return null;
}
}
}

View File

@ -0,0 +1,88 @@
package cn.iocoder.yudao.gateway.util.secret;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @author fir
*/
public class MD5Utils {
private static MessageDigest md;
static {
try {
//初始化摘要对象
md = MessageDigest.getInstance("md5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
/**
* md5
*
* @param str
* @return MD5
*/
public static String generateMd5ForString(String str){
//更新摘要数据
md.update(str.getBytes());
//生成摘要数组
byte[] digest = md.digest();
//清空摘要数据,以便下次使用
md.reset();
return formatByteArrayToString(digest);
}
/**
* md5
*
* @param file
* @return MD5
* @throws IOException
*/
public static String generateMd5ForFile(File file) throws IOException {
//创建文件输入流
FileInputStream fis = new FileInputStream(file);
//将文件中的数据写入md对象
byte[] buffer = new byte[1024];
int len;
while ((len = fis.read(buffer)) != -1) {
md.update(buffer, 0, len);
}
fis.close();
//生成摘要数组
byte[] digest = md.digest();
//清空摘要数据,以便下次使用
md.reset();
return formatByteArrayToString(digest);
}
/**
* md5
*
* @param digest
* @return MD5
*/
public static String formatByteArrayToString(byte[] digest) {
//创建sb用于保存md5值
StringBuilder sb = new StringBuilder();
int temp;
for (byte b : digest) {
//将数据转化为0到255之间的数据
temp = b & 0xff;
if (temp < 16) {
sb.append(0);
}
//Integer.toHexString(temp)将10进制数字转换为16进制
sb.append(Integer.toHexString(temp));
}
return sb.toString();
}
}

View File

@ -0,0 +1,327 @@
package cn.iocoder.yudao.gateway.util.secret;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.io.file.FileWriter;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;
/**
*
*
* @author fir
*/
@Slf4j
public class RSAUtils {
private static final String SIGNATURE_ALGORITHM = "SHA256withRSA";
/**
*
*/
public static final String ENCRYPT_TYPE = "RSA";
/**
*
*/
public static final String PUBLIC_KEY = "publicKey";
/**
*
*/
public static final String PRIVATE_KEY = "privateKey";
/**
*
*
* @return
*/
public static Map<String, String> generateKey() {
Map<String, String> map = new HashMap<>();
KeyPair pair = SecureUtil.generateKeyPair(ENCRYPT_TYPE);
PrivateKey privateKey = pair.getPrivate();
PublicKey publicKey = pair.getPublic();
String publicKeyStr = Base64.encodeBase64String(publicKey.getEncoded());
String privateKeyStr = Base64.encodeBase64String(privateKey.getEncoded());
map.put(PUBLIC_KEY, publicKeyStr);
map.put(PRIVATE_KEY, privateKeyStr);
return map;
}
/**
*
*
* @param filename
* @return
*/
public static String getPublicKey(String filename) {
//默认UTF-8编码可以在构造中传入第二个参数做为编码
FileReader fileReader = new FileReader(filename);
return fileReader.readString();
}
/**
*
*
* @param filename
* @return
*/
public static String getPrivateKey(String filename) {
//默认UTF-8编码可以在构造中传入第二个参数做为编码
FileReader fileReader = new FileReader(filename);
return fileReader.readString();
}
/**
*
*
* @param content
* @param publicKey
*/
public static String encrypt(String content, PublicKey publicKey) {
try {
RSA rsa = new RSA(null, publicKey);
return rsa.encryptBase64(content, KeyType.PublicKey);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
*
*
* @param content
* @param publicKey base64
*/
public static String encrypt(String content, String publicKey) {
try {
RSA rsa = new RSA(null, publicKey);
return rsa.encryptBase64(content, KeyType.PublicKey);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* -
*
* @param t (Json)
* @param publicKey base64
*/
public static <T> String encryptSection(T t, String publicKey) {
String content = JSONObject.toJSONString(t);
try {
return encryptSection(content, publicKey);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* -
*
* @param content
* @param publicKey base64
*/
public static String encryptSection(String content, String publicKey) {
try {
RSA rsa = new RSA(null, publicKey);
int blockSize = 117;
int encryptedLength = content.length();
StringBuilder decryptedBlocks = new StringBuilder();
// 拆分加密文本为块并逐个解密
for (int i = 0; i < encryptedLength; i += blockSize) {
int b = i + blockSize;
if (b > encryptedLength) {
b = encryptedLength;
}
String block = content.substring(i, b);
String decryptedBlock = rsa.encryptBase64(block, KeyType.PublicKey);
decryptedBlocks.append(decryptedBlock);
}
return decryptedBlocks.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
*
*
* @param content
* @param privateKey
*/
public static String decrypt(String content, PrivateKey privateKey) {
try {
RSA rsa = new RSA(privateKey, null);
return rsa.decryptStr(content, KeyType.PrivateKey);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
*
*
* @param content
* @param privateKey base64
*/
public static String decrypt(String content, String privateKey) {
try {
RSA rsa = new RSA(privateKey, null);
return rsa.decryptStr(content, KeyType.PrivateKey);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* -
*
* @param content
* @param privateKey base64
*/
public static String decryptSection(String content, String privateKey) {
try {
RSA rsa = new RSA(privateKey, null);
int blockSize = 172;
int encryptedLength = content.length();
StringBuilder decryptedBlocks = new StringBuilder();
// 拆分加密文本为块并逐个解密
for (int i = 0; i < encryptedLength; i += blockSize) {
int b = i + blockSize;
if (b > encryptedLength) {
b = encryptedLength;
}
String block = content.substring(i, b);
String decryptedBlock = rsa.decryptStr(block, KeyType.PrivateKey);
decryptedBlocks.append(decryptedBlock);
}
return decryptedBlocks.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* -使
*
* @param publicKeyFilename
* @param privateKeyFilename
*/
public static void generateKeyPair(String publicKeyFilename, String privateKeyFilename) {
try {
KeyPair pair = SecureUtil.generateKeyPair(ENCRYPT_TYPE);
PrivateKey privateKey = pair.getPrivate();
PublicKey publicKey = pair.getPublic();
// 获取 公钥和私钥 的 编码格式(通过该 编码格式 可以反过来 生成公钥和私钥对象)
byte[] pubEncBytes = publicKey.getEncoded();
byte[] priEncBytes = privateKey.getEncoded();
// 把 公钥和私钥 的 编码格式 转换为 Base64文本 方便保存
String pubEncBase64 = Base64.encodeBase64String(pubEncBytes);//new BASE64Encoder().encode(pubEncBytes);
String priEncBase64 = Base64.encodeBase64String(priEncBytes);//new BASE64Encoder().encode(priEncBytes);
FileWriter pub = new FileWriter(publicKeyFilename);
FileWriter pri = new FileWriter(privateKeyFilename);
pub.write(pubEncBase64);
pri.write(priEncBase64);
} catch (Exception e) {
e.printStackTrace();
}
}
// - - - - - - - - - - - - - - - - - - - - SIGN 签名,验签 - - - - - - - - - - - - - - - - - - - - //
/**
*
*
* @param content
* @param privateKey
* @param encode
* @return
*/
public static String doSign(String content, String privateKey, String encode) {
try {
String unSign = Base64.encodeBase64String(content.getBytes(StandardCharsets.UTF_8));
byte[] privateKeys = Base64.decodeBase64(privateKey.getBytes());
PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateKeys);
KeyFactory mykeyFactory = KeyFactory.getInstance(ENCRYPT_TYPE);
PrivateKey psbcPrivateKey = mykeyFactory.generatePrivate(privateKeySpec);
Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
signature.initSign(psbcPrivateKey);
signature.update(unSign.getBytes(encode));
byte[] signed = signature.sign();
return Base64.encodeBase64String(signed);
} catch (Exception e) {
log.error("生成报文签名出现异常");
}
return null;
}
/**
*
*
* @param content
* @param signed
* @param publicKey
* @param encode
* @return /
*/
public static boolean doCheck(String content, String signed, PublicKey publicKey, String encode) {
try {
// 解密之前先把content明文进行base64转码
String unsigned = Base64.encodeBase64String(content.getBytes(encode));
Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
signature.initVerify(publicKey);
signature.update(unsigned.getBytes(encode));
return signature.verify(Base64.decodeBase64(signed));
} catch (Exception e) {
log.error("报文验证签名出现异常");
}
return false;
}
}

View File

@ -0,0 +1,75 @@
package cn.iocoder.yudao.gateway.util.secret;
import org.springframework.security.crypto.bcrypt.BCrypt;
import java.security.SecureRandom;
/**
*
*
* @author fir
* @date 2023/7/13 21:19
*/
public class SaltedHashUtils {
/**
*
*/
private static final int SALT_LENGTH = 16;
/**
*
*
* @return 16
*/
public static String generateSalt() {
SecureRandom secureRandom = new SecureRandom();
byte[] salt = new byte[SALT_LENGTH];
secureRandom.nextBytes(salt);
return bytesToHex(salt);
}
/**
*
*
* @param password
* @param salt
* @return
*/
public static String generateHash(String password, String salt) {
String saltedPassword = salt + password;
return BCrypt.hashpw(saltedPassword, BCrypt.gensalt());
}
/**
*
*
* @param password
* @param salt
* @return :true/:false
*/
public static boolean validatePassword(String password, String salt, String hashedPassword) {
String saltedPassword = salt + password;
return BCrypt.checkpw(saltedPassword, hashedPassword);
}
/**
* 16
*
* @param bytes
* @return
*/
private static String bytesToHex(byte[] bytes) {
StringBuilder result = new StringBuilder();
for (byte b : bytes) {
result.append(String.format("%02x", b));
}
return result.toString();
}
}

View File

@ -1,4 +1,19 @@
--- #################### 注册中心 + 配置中心相关配置 ####################
spring:
cloud:
nacos:
server-addr: ${NACOS_HOST_ADDR:nacos.default}:${NACOS_HOST_PORT:8848}
username: ${NACOS_USERNAME}
password: ${NACOS_PASSWORD}
discovery: # 【配置中心】配置项
namespace: ${NACOS_NAMESPACE:ebe55be3-9630-4f18-9f8a-71b578896355} # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
metadata:
version: 1.0.0 # 服务实例的版本号,可用于灰度发布
config: # 【注册中心】配置项
namespace: ${NACOS_NAMESPACE:ebe55be3-9630-4f18-9f8a-71b578896355} # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
application:
name: gateway-server
@ -13,165 +28,7 @@ spring:
- optional:classpath:application-${spring.profiles.active}.yaml # 加载【本地】配置
- optional:nacos:${spring.application.name}-${spring.profiles.active}.yaml # 加载【Nacos】的配置
cloud:
# Spring Cloud Gateway 配置项,对应 GatewayProperties 类
gateway:
# 路由配置项,对应 RouteDefinition 数组
routes:
## system-server 服务
- id: system-admin-api # 路由的编号
uri: grayLb://system-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/system/**
filters:
- RewritePath=/admin-api/system/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
- id: system-app-api # 路由的编号
uri: grayLb://system-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/app-api/system/**
filters:
- RewritePath=/app-api/system/v3/api-docs, /v3/api-docs
## infra-server 服务
- id: infra-admin-api # 路由的编号
uri: grayLb://infra-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/infra/**
filters:
- RewritePath=/admin-api/infra/v3/api-docs, /v3/api-docs
- id: infra-app-api # 路由的编号
uri: grayLb://infra-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/app-api/infra/**
filters:
- RewritePath=/app-api/infra/v3/api-docs, /v3/api-docs
- id: infra-spring-boot-admin # 路由的编号Spring Boot Admin
uri: grayLb://infra-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin/**
- id: infra-websocket # 路由的编号WebSocket
uri: grayLb://infra-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/infra/ws/**
## member-server 服务
- id: member-admin-api # 路由的编号
uri: grayLb://member-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/member/**
filters:
- RewritePath=/admin-api/member/v3/api-docs, /v3/api-docs
- id: member-app-api # 路由的编号
uri: grayLb://member-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/app-api/member/**
filters:
- RewritePath=/app-api/member/v3/api-docs, /v3/api-docs
## bpm-server 服务
- id: bpm-admin-api # 路由的编号
uri: grayLb://bpm-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/bpm/**
filters:
- RewritePath=/admin-api/bpm/v3/api-docs, /v3/api-docs
## report-server 服务
- id: report-admin-api # 路由的编号
uri: grayLb://report-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/report/**
filters:
- RewritePath=/admin-api/report/v3/api-docs, /v3/api-docs
- id: report-jimu # 路由的编号(积木报表)
uri: grayLb://report-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/jmreport/**
## pay-server 服务
- id: pay-admin-api # 路由的编号
uri: grayLb://pay-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/pay/**
filters:
- RewritePath=/admin-api/pay/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
- id: pay-app-api # 路由的编号
uri: grayLb://pay-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/app-api/pay/**
filters:
- RewritePath=/app-api/pay/v3/api-docs, /v3/api-docs
## mp-server 服务
- id: mp-admin-api # 路由的编号
uri: grayLb://mp-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/mp/**
filters:
- RewritePath=/admin-api/mp/v3/api-docs, /v3/api-docs
## product-server 服务
- id: product-admin-api # 路由的编号
uri: grayLb://product-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/product/**
filters:
- RewritePath=/admin-api/product/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
- id: product-app-api # 路由的编号
uri: grayLb://product-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/app-api/product/**
filters:
- RewritePath=/app-api/product/v3/api-docs, /v3/api-docs
## promotion-server 服务
- id: promotion-admin-api # 路由的编号
uri: grayLb://promotion-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/promotion/**
filters:
- RewritePath=/admin-api/promotion/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
- id: promotion-app-api # 路由的编号
uri: grayLb://promotion-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/app-api/promotion/**
filters:
- RewritePath=/app-api/promotion/v3/api-docs, /v3/api-docs
## trade-server 服务
- id: trade-admin-api # 路由的编号
uri: grayLb://trade-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/trade/**
filters:
- RewritePath=/admin-api/trade/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
- id: trade-app-api # 路由的编号
uri: grayLb://trade-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/app-api/trade/**
filters:
- RewritePath=/app-api/trade/v3/api-docs, /v3/api-docs
## statistics-server 服务
- id: statistics-admin-api # 路由的编号
uri: grayLb://statistics-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/statistics/**
filters:
- RewritePath=/admin-api/statistics/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
## erp-server 服务
- id: erp-admin-api # 路由的编号
uri: grayLb://erp-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/erp/**
filters:
- RewritePath=/admin-api/erp/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
## crm-server 服务
- id: crm-admin-api # 路由的编号
uri: grayLb://crm-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/crm/**
filters:
- RewritePath=/admin-api/crm/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
## ai-server 服务
- id: ai-admin-api # 路由的编号
uri: grayLb://ai-server
predicates: # 断言,作为路由的匹配条件,对应 RouteDefinition 数组
- Path=/admin-api/ai/**
filters:
- RewritePath=/admin-api/ai/v3/api-docs, /v3/api-docs # 配置,保证转发到 /v3/api-docs
x-forwarded:
prefix-enabled: false # 避免 Swagger 重复带上额外的 /admin-api/system 前缀
server:
port: 48080
@ -179,54 +36,3 @@ server:
logging:
file:
name: ${user.home}/logs/${spring.application.name}.log # 日志文件名,全路径
knife4j:
# 聚合 Swagger 文档,参考 https://doc.xiaominfo.com/docs/action/springcloud-gateway 文档
gateway:
enabled: true
routes:
- name: system-server
service-name: system-server
url: /admin-api/system/v3/api-docs
- name: infra-server
service-name: infra-server
url: /admin-api/infra/v3/api-docs
- name: member-server
service-name: member-server
url: /admin-api/member/v3/api-docs
- name: bpm-server
service-name: bpm-server
url: /admin-api/bpm/v3/api-docs
- name: pay-server
service-name: pay-server
url: /admin-api/pay/v3/api-docs
- name: mp-server
service-name: mp-server
url: /admin-api/mp/v3/api-docs
- name: product-server
service-name: product-server
url: /admin-api/product/v3/api-docs
- name: promotion-server
service-name: promotion-server
url: /admin-api/promotion/v3/api-docs
- name: trade-server
service-name: trade-server
url: /admin-api/trade/v3/api-docs
- name: statistics-server
service-name: statistics-server
url: /admin-api/statistics/v3/api-docs
- name: erp-server
service-name: erp-server
url: /admin-api/erp/v3/api-docs
- name: crm-server
service-name: crm-server
url: /admin-api/crm/v3/api-docs
- name: ai-server
service-name: ai-server
url: /admin-api/ai/v3/api-docs
--- #################### 芋道相关配置 ####################
yudao:
info:
version: 1.0.0

View File

@ -1,4 +1,20 @@
--- #################### 注册中心 + 配置中心相关配置 ####################
spring:
cloud:
nacos:
server-addr: ${NACOS_HOST_ADDR:nacos.default}:${NACOS_HOST_PORT:8848}
username: ${NACOS_USERNAME}
password: ${NACOS_PASSWORD}
discovery: # 【配置中心】配置项
namespace: ${NACOS_NAMESPACE:ebe55be3-9630-4f18-9f8a-71b578896355} # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
metadata:
version: 1.0.0 # 服务实例的版本号,可用于灰度发布
config: # 【注册中心】配置项
namespace: ${NACOS_NAMESPACE:ebe55be3-9630-4f18-9f8a-71b578896355} # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
application:
name: infra-server
@ -64,7 +80,7 @@ mybatis-plus:
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
global-config:
db-config:
id-type: NONE # “智能”模式,基于 IdTypeEnvironmentPostProcessor + 数据源的类型,自动适配成 AUTO、INPUT 模式。
id-type: AUTO # “智能”模式,基于 IdTypeEnvironmentPostProcessor + 数据源的类型,自动适配成 AUTO、INPUT 模式。
# id-type: AUTO # 自增 ID适合 MySQL 等直接自增的数据库
# id-type: INPUT # 用户输入 ID适合 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库
# id-type: ASSIGN_ID # 分配 ID默认使用雪花算法。注意Oracle、PostgreSQL、Kingbase、DB2、H2 数据库时,需要去除实体类上的 @KeySequence 注解

View File

@ -1,4 +1,20 @@
--- #################### 注册中心 + 配置中心相关配置 ####################
spring:
cloud:
nacos:
server-addr: ${NACOS_HOST_ADDR:nacos.default}:${NACOS_HOST_PORT:8848}
username: ${NACOS_USERNAME}
password: ${NACOS_PASSWORD}
discovery: # 【配置中心】配置项
namespace: ${NACOS_NAMESPACE:ebe55be3-9630-4f18-9f8a-71b578896355} # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
metadata:
version: 1.0.0 # 服务实例的版本号,可用于灰度发布
config: # 【注册中心】配置项
namespace: ${NACOS_NAMESPACE:ebe55be3-9630-4f18-9f8a-71b578896355} # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
application:
name: system-server
@ -64,7 +80,7 @@ mybatis-plus:
map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。
global-config:
db-config:
id-type: NONE # “智能”模式,基于 IdTypeEnvironmentPostProcessor + 数据源的类型,自动适配成 AUTO、INPUT 模式。
id-type: AUTO # “智能”模式,基于 IdTypeEnvironmentPostProcessor + 数据源的类型,自动适配成 AUTO、INPUT 模式。
# id-type: AUTO # 自增 ID适合 MySQL 等直接自增的数据库
# id-type: INPUT # 用户输入 ID适合 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库
# id-type: ASSIGN_ID # 分配 ID默认使用雪花算法。注意Oracle、PostgreSQL、Kingbase、DB2、H2 数据库时,需要去除实体类上的 @KeySequence 注解

View File

@ -3,16 +3,16 @@
spring:
cloud:
nacos:
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
username: # Nacos 账号
password: # Nacos 密码
server-addr: myserver:13721 #127.0.0.1:8848 # Nacos 服务器地址
username: nacos # Nacos 账号
password: zyx123123 # Nacos 密码
discovery: # 【配置中心】配置项
namespace: dev # 命名空间。这里使用 dev 开发环境
namespace: d5c15366-e804-4c94-8288-5df56e8b7e8a # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
metadata:
version: 1.0.0 # 服务实例的版本号,可用于灰度发布
config: # 【注册中心】配置项
namespace: dev # 命名空间。这里使用 dev 开发环境
namespace: d5c15366-e804-4c94-8288-5df56e8b7e8a # 命名空间。这里使用 dev 开发环境
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
--- #################### 数据库相关配置 ####################
@ -56,14 +56,14 @@ spring:
primary: master
datasource:
master:
url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
url: jdbc:mysql://myserver:13722/dlifevpn?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例
# url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ruoyi-vue-pro # SQLServer 连接的示例
# url: jdbc:dm://10.211.55.4:5236?schema=RUOYI_VUE_PRO # DM 连接的示例
username: root
password: 123456
password: Zyx234kk..#
# username: sa # SQL Server 连接的示例
# password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W # SQL Server 连接的示例
# username: SYSDBA # DM 连接的示例
@ -72,15 +72,15 @@ spring:
lazy: true # 开启懒加载,保证启动速度
url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true
username: root
password: 123456
password: Zyx234kk..#
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
data:
redis:
host: 127.0.0.1 # 地址
port: 6379 # 端口
host: myserver # 地址
port: 13723 # 端口
database: 0 # 数据库索引
# password: 123456 # 密码,建议生产环境开启
password: 123123123 # 密码,建议生产环境开启
--- #################### MQ 消息队列相关配置 ####################