diff --git a/pom.xml b/pom.xml
index 23da1b2..99509f6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,6 +59,21 @@
org.projectlombok
lombok
+
+ org.apache.httpcomponents
+ httpclient
+ 4.4.1
+
+
+ org.apache.httpcomponents
+ httpcore
+ 4.4.1
+
+
+ org.apache.httpcomponents
+ httpmime
+ 4.4.1
+
diff --git a/src/main/java/com/sentinel/license/LicenseApplication.java b/src/main/java/com/license/LicenseApplication.java
similarity index 90%
rename from src/main/java/com/sentinel/license/LicenseApplication.java
rename to src/main/java/com/license/LicenseApplication.java
index adf5b56..25c1c46 100644
--- a/src/main/java/com/sentinel/license/LicenseApplication.java
+++ b/src/main/java/com/license/LicenseApplication.java
@@ -1,4 +1,4 @@
-package com.sentinel.license;
+package com.license;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/src/main/java/com/sentinel/license/bean/Code.java b/src/main/java/com/license/bean/Code.java
similarity index 95%
rename from src/main/java/com/sentinel/license/bean/Code.java
rename to src/main/java/com/license/bean/Code.java
index 5eb3c76..b127d7b 100644
--- a/src/main/java/com/sentinel/license/bean/Code.java
+++ b/src/main/java/com/license/bean/Code.java
@@ -1,4 +1,4 @@
-package com.sentinel.license.bean;
+package com.license.bean;
/**
diff --git a/src/main/java/com/sentinel/license/bean/LicenseInfo.java b/src/main/java/com/license/bean/LicenseInfo.java
similarity index 80%
rename from src/main/java/com/sentinel/license/bean/LicenseInfo.java
rename to src/main/java/com/license/bean/LicenseInfo.java
index 929d4a4..988a03c 100644
--- a/src/main/java/com/sentinel/license/bean/LicenseInfo.java
+++ b/src/main/java/com/license/bean/LicenseInfo.java
@@ -1,4 +1,4 @@
-package com.sentinel.license.bean;
+package com.license.bean;
import lombok.Data;
@@ -19,5 +19,7 @@ public class LicenseInfo {
// 1 获取指纹 2 更新license 3 获取license信息 4 验证license信息
private Integer type;
+ //提供服务标识
+ private String serverId;
}
diff --git a/src/main/java/com/sentinel/license/bean/Ret.java b/src/main/java/com/license/bean/Ret.java
similarity index 97%
rename from src/main/java/com/sentinel/license/bean/Ret.java
rename to src/main/java/com/license/bean/Ret.java
index 8018f0d..e464646 100644
--- a/src/main/java/com/sentinel/license/bean/Ret.java
+++ b/src/main/java/com/license/bean/Ret.java
@@ -1,4 +1,4 @@
-package com.sentinel.license.bean;
+package com.license.bean;
import java.util.Arrays;
diff --git a/src/main/java/com/sentinel/license/bean/Rets.java b/src/main/java/com/license/bean/Rets.java
similarity index 94%
rename from src/main/java/com/sentinel/license/bean/Rets.java
rename to src/main/java/com/license/bean/Rets.java
index db00370..9844880 100644
--- a/src/main/java/com/sentinel/license/bean/Rets.java
+++ b/src/main/java/com/license/bean/Rets.java
@@ -1,4 +1,5 @@
-package com.sentinel.license.bean;
+package com.license.bean;
+
public class Rets {
diff --git a/src/main/java/com/license/cache/CacheManager.java b/src/main/java/com/license/cache/CacheManager.java
new file mode 100644
index 0000000..8f4b56f
--- /dev/null
+++ b/src/main/java/com/license/cache/CacheManager.java
@@ -0,0 +1,53 @@
+package com.license.cache;
+
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+
+/**
+ * @author fengjunfeng
+ * @date 2022/1/20
+ * @time 10:24
+ * @description
+ **/
+@Component
+public class CacheManager {
+ /**
+ */
+ private static HashMap map = new HashMap<>();
+
+// /**
+// * 保存时间
+// */
+// private static int liveTime = 60;
+
+ /**
+ * 信息缓存
+ * @param key
+ * @param v
+ * @return
+ */
+ public static boolean addCache(String key,String v){
+ map.put(key,v);
+ return true;
+ }
+
+ /**
+ * 缓存信息
+ * @param key
+ * @return
+ */
+ public static boolean delCache(String key){
+ map.remove(key);
+ return true;
+ }
+
+ /**
+ * @param key
+ * @return
+ */
+ public static String getCache(String key){
+ return map.get(key);
+ }
+
+}
diff --git a/src/main/java/com/license/config/RestTemplateConfig.java b/src/main/java/com/license/config/RestTemplateConfig.java
new file mode 100644
index 0000000..9a16fef
--- /dev/null
+++ b/src/main/java/com/license/config/RestTemplateConfig.java
@@ -0,0 +1,121 @@
+package com.license.config;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.client.ClientHttpRequestFactory;
+import org.springframework.http.client.ClientHttpResponse;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.StringHttpMessageConverter;
+import org.springframework.web.client.ResponseErrorHandler;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+/**
+*
+* @author fengjunfeng
+* @date 2022/1/20
+* @time 11:12
+* @description
+*
+**/
+@Configuration
+public class RestTemplateConfig {
+ @Value("${http.maxTotal}")
+ private String maxTotal;
+ @Value("${http.defaultMaxPerRoute}")
+ private String defaultMaxPerRoute;
+ @Value("${http.connectTimeout}")
+ private String connectTimeout;
+ @Value("${http.connectionRequestTimeout}")
+ private String connectionRequestTimeout;
+ @Value("${http.socketTimeout}")
+ private String socketTimeout;
+
+
+
+ @Bean
+ public RestTemplate restTemplate() {
+ RestTemplate restTemplate = new RestTemplate(httpRequestFactory());
+ List> converterList = restTemplate.getMessageConverters();
+
+ //重新设置StringHttpMessageConverter字符集为UTF-8,解决中文乱码问题
+ HttpMessageConverter> converterTarget = null;
+ for (HttpMessageConverter> item : converterList) {
+ if (StringHttpMessageConverter.class == item.getClass()) {
+ converterTarget = item;
+ break;
+ }
+ }
+ if (null != converterTarget) {
+ converterList.remove(converterTarget);
+ }
+
+
+ converterList.add(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
+
+ /**
+ * restTemplate 异常处理类 , 解决返回不了除了200之外的状态码
+ */
+ ResponseErrorHandler responseErrorHandler = new ResponseErrorHandler() {
+ @Override
+ public boolean hasError(ClientHttpResponse clientHttpResponse) throws IOException {
+ return true;
+ }
+
+ @Override
+ public void handleError(ClientHttpResponse clientHttpResponse) throws IOException {
+
+ }
+ };
+ restTemplate.setErrorHandler(responseErrorHandler);
+
+ return restTemplate;
+ }
+
+ @Bean
+ public ClientHttpRequestFactory httpRequestFactory() {
+ return new HttpComponentsClientHttpRequestFactory(httpClient());
+ }
+
+ @Bean
+ public HttpClient httpClient() {
+ Registry registry = RegistryBuilder.create()
+ .register("http", PlainConnectionSocketFactory.getSocketFactory())
+ .register("https", SSLConnectionSocketFactory.getSocketFactory())
+ .build();
+ PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(registry);
+ connectionManager.setMaxTotal(Integer.valueOf(this.maxTotal));
+ connectionManager.setDefaultMaxPerRoute(Integer.valueOf(this.defaultMaxPerRoute));
+ RequestConfig requestConfig = RequestConfig.custom()
+ //服务器返回数据(response)的时间,超过抛出read timeout
+ .setSocketTimeout(Integer.valueOf(this.socketTimeout))
+ //连接上服务器(握手成功)的时间,超出抛出connect timeout
+ .setConnectTimeout(Integer.valueOf(this.connectTimeout))
+ //从连接池中获取连接的超时时间,超时间未拿到可用连接,会抛出org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
+ .setConnectionRequestTimeout(Integer.valueOf(this.connectionRequestTimeout))
+ .build();
+ return HttpClientBuilder.create()
+ .setDefaultRequestConfig(requestConfig)
+ .setConnectionManager(connectionManager)
+ .setConnectionManagerShared(true)
+ .build();
+ }
+
+
+
+
+}
diff --git a/src/main/java/com/license/controller/LicenseController.java b/src/main/java/com/license/controller/LicenseController.java
new file mode 100644
index 0000000..01b3f71
--- /dev/null
+++ b/src/main/java/com/license/controller/LicenseController.java
@@ -0,0 +1,105 @@
+package com.license.controller;
+
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import cn.hutool.log.Log;
+
+import com.license.bean.LicenseInfo;
+import com.license.cache.CacheManager;
+import com.license.utils.Constant;
+import com.license.utils.GetIpProtUtil;
+import com.license.utils.HaspUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.*;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
+
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * @author fengjunfeng
+ * @date 2021/12/28
+ * @time 16:00
+ * @description
+ **/
+@RestController
+public class LicenseController {
+ private static final Log log = Log.get();
+ @Autowired
+ public RestTemplate restTemplate;
+ @Value("${bifang-api.server.port}")
+ private String port;
+ /**
+ * license锁信息交互
+ *
+ * @return
+ */
+ @PostMapping("/licenseOperation")
+ public Object licenseOperation(@RequestBody LicenseInfo licenseInfo) {
+// if (!verify(licenseInfo.getServerId())){
+// return null;
+// }
+ if (licenseInfo.getType().equals(Constant.LICENSE_C2V)){
+ //获取C2V信息
+ return HaspUtil.readC2V(licenseInfo.getVendorCode(),licenseInfo.getFeatureId());
+ }else if (licenseInfo.getType().equals(Constant.LICENSE_UPDATE)){
+ //上传license信息
+ return HaspUtil.updateKeyWithLicense(licenseInfo.getV2C());
+ }else if (licenseInfo.getType().equals(Constant.LICENSE_QUERY)){
+ //获取license信息
+ return HaspUtil.getLicenseInfo(licenseInfo.getVendorCode(),licenseInfo.getFeatureId());
+ }else if (licenseInfo.getType().equals(Constant.LICENSE_VERIFY)){
+ //验证license信息
+ return HaspUtil.verify(licenseInfo.getVendorCode(),licenseInfo.getFeatureId());
+ }else {
+ log.info("type error");
+ return null;
+ }
+ }
+
+ /**
+ *
+ * @author fengjunfeng
+ * @date 2022/1/20
+ * @time 11:14
+ * @description
+ *
+ **/
+ public boolean verify(String serverId){
+ try {
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
+ HttpEntity httpEntity = new HttpEntity<>(null, headers);
+ String url = "http://" + GetIpProtUtil.getLocalIP() +":" + port + "/getServerId";
+ ResponseEntity