commit
b07b3a0012
|
@ -0,0 +1,56 @@
|
|||
log4j.rootLogger=INFO,stdout,info,warn,error
|
||||
|
||||
log4j.logger.info=info
|
||||
log4j.logger.warn=warn
|
||||
log4j.logger.error=error
|
||||
|
||||
log4j.logger.org.springframework=warn
|
||||
log4j.logger.org.apache=info,error
|
||||
log4j.logger.org.aspectj.weaver=warn
|
||||
log4j.logger.org.hibernate=off
|
||||
log4j.logger.com.mchange=off
|
||||
log4j.logger.java.sql.Connection=info
|
||||
log4j.logger.java.sql.Statement=info
|
||||
log4j.logger.java.sql.ResultSet=info
|
||||
log4j.logger.java.sql.PreparedStatement=info
|
||||
|
||||
#log4j.logger.httpclient.wire.header=off
|
||||
#log4j.logger.httpclient.wire.content=off
|
||||
#log4j.logger.org.apache.commons.httpclient=off
|
||||
#log4j.logger.org.apache.commons.httpclient.Wire=off
|
||||
|
||||
|
||||
################打印到控制台
|
||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.stdout.layout.ConversionPattern = %d{yyyy-MM-dd HH\:mm\:ss\:SSS}\:%l - \n%p\: %m%n
|
||||
|
||||
################记录系统日志,监控客户端运行情况
|
||||
log4j.appender.info=org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.info.File=bootlog/INFO.log
|
||||
log4j.appender.info.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.info.Threshold = INFO
|
||||
log4j.appender.info.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
|
||||
log4j.appender.info.DatePattern = '.'yyyy-MM-dd
|
||||
log4j.appender.info.encoding=UTF-8
|
||||
################
|
||||
|
||||
################记录系统告警日志
|
||||
log4j.appender.warn=org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.warn.File=bootlog/WARN.log
|
||||
log4j.appender.warn.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.warn.Threshold = WARN
|
||||
log4j.appender.warn.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
|
||||
log4j.appender.warn.DatePattern = '.'yyyy-MM-dd
|
||||
log4j.appender.warn.encoding=UTF-8
|
||||
################
|
||||
|
||||
################记录系统错误,监控程序是否出错
|
||||
log4j.appender.error=org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.error.File=bootlog/ERROR.log
|
||||
log4j.appender.error.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.error.Threshold = ERROR
|
||||
log4j.appender.error.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}:%p %l - %m%n
|
||||
log4j.appender.error.DatePattern = '.'yyyy-MM-dd
|
||||
log4j.appender.error.encoding=UTF-8
|
||||
|
4
pom.xml
4
pom.xml
|
@ -323,6 +323,10 @@
|
|||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<!--排除版本管理警告-->
|
||||
<dependencyManagement>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
spring.application.name = LuckyFrameClient
|
||||
server.port = 6633
|
||||
spring.servlet.multipart.max-file-size=30MB
|
||||
spring.application.name = LuckyFrameClient
|
||||
server.port = 6633
|
||||
spring.servlet.multipart.max-file-size=30MB
|
||||
spring.servlet.multipart.max-request-size=30MB
|
|
@ -35,4 +35,7 @@ jenkins.username=test
|
|||
jenkins.password=test1
|
||||
#==================Web Driver配置========================
|
||||
#是否高亮显示 true打开 false关闭
|
||||
webdriver.highlight=false
|
||||
webdriver.highlight=false
|
||||
#==================ソヘサァカヒナ葷テテワヤソ========================
|
||||
client.config.privateKey=MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKZzwv5UN94a4OdMlmRS20n7x5e267LAV9Ue8wFOxUL2BJH33+mrJBqfj8rpcSgp7K+etX2kFq35VeeK3cr+ndBq9z+fO1FHw1kfsE8SQnSw17jfM1pdekC40gle+1bRKlm28zoLYcUMkQ8UFyVEyn72JH5ByJf9zNxWPVAIuzh3AgMBAAECgYBUrXd5Yua4+vuHL5MinnQogwnayJfHa8pDBWeiNqxrkDRq/arPeNz5HktMcs26HPnnrdmufRd8ked9z0tdxYIKfxeZrWuY3+YQkthGkROcWPLc4H1BdlXMTSoDS1hoTokehJ22i+SH2Qr9IYs++xHdEg7s5lPkoi9eVboTpOC0wQJBAM+qft5kp7gH3XV/XtpBeUxwB5rmpPVRIBPHxjHURhFI19+VDwidIq8MbN4tP1ukqegGNj5tWotNpoP9S+dS49kCQQDNMZiSW9HsX51CP7tJ1PVGnmE7QN5pu5TnlEl2WJQup6JamzvMiNYbJ4XzI4tBoL9+n4iAqbDyNIKY9y7ci1zPAkAT/PEhLscF65vhR1U15L9sIAxbWH/gLOLNhJkLCseDumMs3ggIaDeCacvAxtImW/8Omip2b8gbSGoSojrAFTZhAkAsWmoWSM6pf0loxonfPa7+4sE1o6HvzOI05HK0qBTvuMB5QVC9t15AZFyp36b8Opjp7+X7mbJryDnqgpOYjG81AkEAlgZbPEKrFmvBAdhnsOdLywYO+iaKVHsUV/xB65gOJk9TtJNG5GQd9zJkTJ589itK4Avg0x247PELbQjd3Tge2w==
|
||||
client.config.publicKey=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmc8L+VDfeGuDnTJZkUttJ+8eXtuuywFfVHvMBTsVC9gSR99/pqyQan4/K6XEoKeyvnrV9pBat+VXnit3K/p3Qavc/nztRR8NZH7BPEkJ0sNe43zNaXXpAuNIJXvtW0SpZtvM6C2HFDJEPFBclRMp+9iR+QciX/czcVj1QCLs4dwIDAQAB
|
||||
|
|
|
@ -52,6 +52,7 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
|||
|
||||
private static final String SERVER_PORT = SysConfig.getConfiguration().getProperty("server.web.port");
|
||||
|
||||
public static Integer clientId=-1;
|
||||
|
||||
private volatile int lastLength = 0;
|
||||
|
||||
|
@ -200,7 +201,11 @@ public class ClientHandler extends ChannelHandlerAdapter {
|
|||
re.put("data", result);
|
||||
sendMessage(re.toString());
|
||||
}
|
||||
|
||||
}
|
||||
else if("loginReturn".equals(json.get("method")))
|
||||
{
|
||||
//ÉèÖÃclient±ê¼Ç
|
||||
clientId=Integer.valueOf(json.get("clientId").toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,257 @@
|
|||
package luckyclient.utils;
|
||||
|
||||
import luckyclient.utils.config.SysConfig;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.security.*;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
|
||||
@Component
|
||||
public class EncryptionUtils {
|
||||
|
||||
/**
|
||||
* RSA最大加密明文大小
|
||||
*/
|
||||
private static final int MAX_ENCRYPT_BLOCK = 117;
|
||||
|
||||
/**
|
||||
* RSA最大解密密文大小
|
||||
*/
|
||||
private static final int MAX_DECRYPT_BLOCK = 128;
|
||||
|
||||
/**
|
||||
* 默认公钥
|
||||
*/
|
||||
private static final String DEFAULT_PUBLIC_KEY="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCadmkcep05BmZ3aWH72ab8iw8xD4XYrXmeySwBgKQY4mhHo2MrT8fKiNaG0PC/Jy09inPczBPqf/IPILlE79ujgpc84bHnR27u9IH7kJlyoLiPRGoN+oQbWJakmYTwGkdG4z1Re9xoKi4Ww1WShkvJspMwOWtkwfwub5zkvQtSWQIDAQAB";
|
||||
|
||||
/**
|
||||
* 默认私钥
|
||||
*/
|
||||
private static final String DEFAULT_PRIVATE_KEY="MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAJp2aRx6nTkGZndpYfvZpvyLDzEPhditeZ7JLAGApBjiaEejYytPx8qI1obQ8L8nLT2Kc9zME+p/8g8guUTv26OClzzhsedHbu70gfuQmXKguI9Eag36hBtYlqSZhPAaR0bjPVF73GgqLhbDVZKGS8mykzA5a2TB/C5vnOS9C1JZAgMBAAECgYBNTjYNKtDFWY6u9O81PRl2C6LuyvYSG8Bi2AxONDPswGOwdvWLF8LGevXjQ286PEFIK6MRPpI5Kw/awmX3OpSR10nAzLHo7KU03+1+71EpGcGt0OAudDG+Qzzz10rjyoBwV21d8utoJmy4m5MLbp7yxxZ0caGNfkJMj7QJyxsQAQJBAOtTwyqdGbhLle0rD/9WhK5huFBAaXCw21mJK/wkByVFk9ynHN1P0e3fgS4S2KOyWGEwMgfaxRxvn+Tmj8sQLkkCQQCoCBhihIZj0epYvdQdf63sgrzVlUr3d3IIlKio4JLfvo4gFGpQjV/mOlyS7AGNWf5iDFzJvpXoXET5GYkmpEORAkA784LtAEjlIpx3Z1kT+76hjlOeXkp+Yw/+p2uFOMh5PliFBi3cU9FvgFkwm6yFR5IscFLOnXVJ4UYi0nofiWfBAkBMZvnneci9hIog9ZeIHjEP9FY2a16d7RLNsgKKXyqJT9TB42Z/3/h1751+NI90HTJclLBwDxeMgr/d3+2Lw27xAkBdQqmrWTAmHPGS48CZ/VYu9repRhDmV+8nsWtX1fdU410kcfYgib7WX9Y22v4vGQrVt72waBvvEvbjWjXH+Ael";
|
||||
|
||||
/**
|
||||
* 用户配置的私钥
|
||||
*/
|
||||
private static String USER_PRIVATE_KEY= SysConfig.getConfiguration().getProperty("client.config.privateKey");
|
||||
|
||||
/**
|
||||
* 用户配置的公钥
|
||||
*/
|
||||
private static String USER_PUBLIC_KEY= SysConfig.getConfiguration().getProperty("client.config.publicKey");
|
||||
|
||||
@Value("${client.config.privateKey}")
|
||||
public void setUserPrivateKey(String userPrivateKey) {
|
||||
USER_PRIVATE_KEY = userPrivateKey;
|
||||
}
|
||||
|
||||
@Value("${client.config.publicKey}")
|
||||
public void setUserPublicKey(String userPublicKey) {
|
||||
USER_PUBLIC_KEY = userPublicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取密钥对
|
||||
*
|
||||
* @return 密钥对
|
||||
*/
|
||||
public static KeyPair getKeyPair() throws Exception {
|
||||
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
|
||||
generator.initialize(1024);
|
||||
return generator.generateKeyPair();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取私钥
|
||||
*
|
||||
* @param privateKey 私钥字符串
|
||||
* @return
|
||||
*/
|
||||
public static PrivateKey getPrivateKey(String privateKey) throws Exception {
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
byte[] decodedKey = Base64.decodeBase64(privateKey.getBytes());
|
||||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decodedKey);
|
||||
return keyFactory.generatePrivate(keySpec);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公钥
|
||||
*
|
||||
* @param publicKey 公钥字符串
|
||||
* @return
|
||||
*/
|
||||
public static PublicKey getPublicKey(String publicKey) throws Exception {
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
byte[] decodedKey = Base64.decodeBase64(publicKey.getBytes());
|
||||
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(decodedKey);
|
||||
return keyFactory.generatePublic(keySpec);
|
||||
}
|
||||
|
||||
/**
|
||||
* RSA加密
|
||||
*
|
||||
* @param data 待加密数据
|
||||
* @param publicKey 公钥
|
||||
* @return
|
||||
*/
|
||||
public static String encrypt(String data, PublicKey publicKey) throws Exception {
|
||||
Cipher cipher = Cipher.getInstance("RSA");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
int inputLen = data.getBytes().length;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offset = 0;
|
||||
byte[] cache;
|
||||
int i = 0;
|
||||
// 对数据分段加密
|
||||
while (inputLen - offset > 0) {
|
||||
if (inputLen - offset > MAX_ENCRYPT_BLOCK) {
|
||||
cache = cipher.doFinal(data.getBytes(), offset, MAX_ENCRYPT_BLOCK);
|
||||
} else {
|
||||
cache = cipher.doFinal(data.getBytes(), offset, inputLen - offset);
|
||||
}
|
||||
out.write(cache, 0, cache.length);
|
||||
i++;
|
||||
offset = i * MAX_ENCRYPT_BLOCK;
|
||||
}
|
||||
byte[] encryptedData = out.toByteArray();
|
||||
out.close();
|
||||
// 获取加密内容使用base64进行编码,并以UTF-8为标准转化成字符串
|
||||
// 加密后的字符串
|
||||
return new String(Base64.encodeBase64String(encryptedData));
|
||||
}
|
||||
|
||||
/**
|
||||
* RSA解密
|
||||
*
|
||||
* @param data 待解密数据
|
||||
* @param privateKey 私钥
|
||||
* @return
|
||||
*/
|
||||
public static String decrypt(String data, PrivateKey privateKey) throws Exception {
|
||||
Cipher cipher = Cipher.getInstance("RSA");
|
||||
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
byte[] dataBytes = Base64.decodeBase64(data);
|
||||
int inputLen = dataBytes.length;
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
int offset = 0;
|
||||
byte[] cache;
|
||||
int i = 0;
|
||||
// 对数据分段解密
|
||||
while (inputLen - offset > 0) {
|
||||
if (inputLen - offset > MAX_DECRYPT_BLOCK) {
|
||||
cache = cipher.doFinal(dataBytes, offset, MAX_DECRYPT_BLOCK);
|
||||
} else {
|
||||
cache = cipher.doFinal(dataBytes, offset, inputLen - offset);
|
||||
}
|
||||
out.write(cache, 0, cache.length);
|
||||
i++;
|
||||
offset = i * MAX_DECRYPT_BLOCK;
|
||||
}
|
||||
byte[] decryptedData = out.toByteArray();
|
||||
out.close();
|
||||
// 解密后的内容
|
||||
return new String(decryptedData, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
* 签名
|
||||
*
|
||||
* @param data 待签名数据
|
||||
* @param privateKey 私钥
|
||||
* @return 签名
|
||||
*/
|
||||
public static String sign(String data, PrivateKey privateKey) throws Exception {
|
||||
byte[] keyBytes = privateKey.getEncoded();
|
||||
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
PrivateKey key = keyFactory.generatePrivate(keySpec);
|
||||
Signature signature = Signature.getInstance("MD5withRSA");
|
||||
signature.initSign(key);
|
||||
signature.update(data.getBytes());
|
||||
return new String(Base64.encodeBase64(signature.sign()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 验签
|
||||
*
|
||||
* @param srcData 原始字符串
|
||||
* @param publicKey 公钥
|
||||
* @param sign 签名
|
||||
* @return 是否验签通过
|
||||
*/
|
||||
public static boolean verify(String srcData, PublicKey publicKey, String sign) throws Exception {
|
||||
byte[] keyBytes = publicKey.getEncoded();
|
||||
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||
PublicKey key = keyFactory.generatePublic(keySpec);
|
||||
Signature signature = Signature.getInstance("MD5withRSA");
|
||||
signature.initVerify(key);
|
||||
signature.update(srcData.getBytes());
|
||||
return signature.verify(Base64.decodeBase64(sign.getBytes()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 加密
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
public static String encrypt(String data)
|
||||
{
|
||||
try
|
||||
{
|
||||
String publicKey= StringUtils.isNotEmpty(USER_PUBLIC_KEY)?USER_PUBLIC_KEY:DEFAULT_PUBLIC_KEY;
|
||||
String encryptData = encrypt(data, getPublicKey(publicKey));
|
||||
return encryptData;
|
||||
}catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密
|
||||
* @param encryptData
|
||||
* @return
|
||||
*/
|
||||
public static String decrypt(String encryptData)
|
||||
{
|
||||
try
|
||||
{
|
||||
String privateKey= StringUtils.isNotEmpty(USER_PRIVATE_KEY)?USER_PRIVATE_KEY:DEFAULT_PRIVATE_KEY;
|
||||
String data = decrypt(encryptData, getPrivateKey(privateKey));
|
||||
return data;
|
||||
}catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return encryptData;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// 生成密钥对
|
||||
KeyPair keyPair = getKeyPair();
|
||||
String privateKey = new String(Base64.encodeBase64(keyPair.getPrivate().getEncoded()));
|
||||
String publicKey = new String(Base64.encodeBase64(keyPair.getPublic().getEncoded()));
|
||||
System.out.println("私钥:" + privateKey);
|
||||
System.out.println("公钥:" + publicKey);
|
||||
// RSA加密
|
||||
String data = "待加密的文字内容";
|
||||
String encryptData = encrypt(data, getPublicKey(publicKey));
|
||||
System.out.println("加密后内容:" + encryptData);
|
||||
// RSA解密
|
||||
String decryptData = decrypt(encryptData, getPrivateKey(privateKey));
|
||||
System.out.println("解密后内容:" + decryptData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.print("加解密异常");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.util.Properties;
|
||||
|
||||
import luckyclient.utils.LogUtil;
|
||||
import luckyclient.utils.proxy.PropertiesProxy;
|
||||
|
||||
/**
|
||||
* 初始化Appium配置参数
|
||||
|
@ -17,16 +18,18 @@ import luckyclient.utils.LogUtil;
|
|||
public class AppiumConfig {
|
||||
private static final Properties SYS_CONFIG = new Properties();
|
||||
private static final String SYS_CONFIG_FILE = "/appium_config.properties";
|
||||
private static PropertiesProxy proxy=new PropertiesProxy();
|
||||
static{
|
||||
try {
|
||||
InputStream in = new BufferedInputStream(AppiumConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
||||
SYS_CONFIG.load(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
proxy.setWapper(SYS_CONFIG);
|
||||
} catch (IOException e) {
|
||||
LogUtil.APP.error("读取移动端appium_config.properties配置文件出现异常,请检查!", e);
|
||||
}
|
||||
}
|
||||
private AppiumConfig(){}
|
||||
public static Properties getConfiguration(){
|
||||
return SYS_CONFIG;
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.util.Properties;
|
||||
|
||||
import luckyclient.utils.LogUtil;
|
||||
import luckyclient.utils.proxy.PropertiesProxy;
|
||||
|
||||
/**
|
||||
* 初始化数据库驱动配置
|
||||
|
@ -21,16 +22,18 @@ import luckyclient.utils.LogUtil;
|
|||
public class DrivenConfig {
|
||||
private static final Properties SYS_CONFIG = new Properties();
|
||||
private static final String SYS_CONFIG_FILE = "/TestDriven/driven_config.properties";
|
||||
private static PropertiesProxy proxy=new PropertiesProxy();
|
||||
static{
|
||||
try {
|
||||
InputStream in = new BufferedInputStream(DrivenConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
||||
SYS_CONFIG.load(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
proxy.setWapper(SYS_CONFIG);
|
||||
} catch (IOException e) {
|
||||
LogUtil.APP.error("读取测试驱动driven_config.properties配置文件出现异常,请检查!", e);
|
||||
}
|
||||
}
|
||||
private DrivenConfig(){}
|
||||
public static Properties getConfiguration(){
|
||||
return SYS_CONFIG;
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package luckyclient.utils.config;
|
||||
|
||||
import luckyclient.utils.proxy.PropertiesProxy;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -14,16 +16,18 @@ import java.util.Properties;
|
|||
public class SysConfig {
|
||||
private static final Properties SYS_CONFIG = new Properties();
|
||||
private static final String SYS_CONFIG_FILE = "/sys_config.properties";
|
||||
private static PropertiesProxy proxy=new PropertiesProxy();
|
||||
static{
|
||||
try {
|
||||
InputStream in = new BufferedInputStream(SysConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
|
||||
SYS_CONFIG.load(new InputStreamReader(in, "GBK"));
|
||||
proxy.setWapper(SYS_CONFIG);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private SysConfig(){}
|
||||
public static Properties getConfiguration(){
|
||||
return SYS_CONFIG;
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package luckyclient.utils.proxy;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import luckyclient.netty.ClientHandler;
|
||||
import luckyclient.utils.EncryptionUtils;
|
||||
import luckyclient.utils.httputils.HttpRequest;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author fengjian
|
||||
* @date 2020/6/22 21:26
|
||||
*/
|
||||
public class PropertiesProxy extends Properties {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(PropertiesProxy.class);
|
||||
|
||||
private Properties wapper = new Properties();
|
||||
|
||||
public Properties getWapper() {
|
||||
return wapper;
|
||||
}
|
||||
|
||||
public void setWapper(Properties wapper) {
|
||||
this.wapper = wapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty(String key) {
|
||||
log.info("get config from service");
|
||||
//获取参数
|
||||
//通过接口获取服务端配置
|
||||
try{
|
||||
String result = HttpRequest.loadJSON("/system/clientConfig/config/"+ ClientHandler.clientId+"/"+key);
|
||||
if(StringUtils.isNotEmpty(result))
|
||||
{
|
||||
JSONObject res=JSONObject.parseObject(result);
|
||||
if(res.get("code")!=null&&res.getInteger("code")==200)
|
||||
{
|
||||
String value= EncryptionUtils.decrypt(res.get("value").toString());
|
||||
log.info("get config from server:"+res.toJSONString()+";value="+value);
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
}catch (Exception e)
|
||||
{
|
||||
log.info("服务器没有配置:"+key);
|
||||
}
|
||||
return wapper.getProperty(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty(String key, String defaultValue) {
|
||||
log.debug("get config from service");
|
||||
//获取参数
|
||||
//通过接口获取服务端配置
|
||||
try{
|
||||
String result = HttpRequest.loadJSON("/system/clientConfig/config/"+ ClientHandler.clientId+"/"+key);
|
||||
if(StringUtils.isNotEmpty(result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}catch (Exception e)
|
||||
{
|
||||
log.debug("服务器没有配置:"+key);
|
||||
}
|
||||
return wapper.getProperty(key, defaultValue);
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
import cn.hutool.core.util.BooleanUtil;
|
||||
import luckyclient.netty.NettyClient;
|
||||
import luckyclient.utils.config.SysConfig;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
|
||||
/**
|
||||
* =================================================================
|
||||
|
@ -32,7 +33,7 @@ public class RunService {
|
|||
private static final Logger log = LoggerFactory.getLogger(RunService.class);
|
||||
private static final Boolean NETTY_MODEL= BooleanUtil.toBoolean(SysConfig.getConfiguration().getProperty("netty.model"));
|
||||
public static String CLIENT_IP = "";
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
// TODO Auto-generated method stub
|
||||
PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator +"bootlog4j.conf");
|
||||
SpringApplication.run(RunService.class, args);
|
||||
|
@ -53,6 +54,8 @@ public class RunService {
|
|||
}else{
|
||||
HttpImpl.checkHostNet();
|
||||
}
|
||||
Thread.sleep(5000);
|
||||
SysConfig.getConfiguration().getProperty("appid");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue