From 9e09d5edd18a8ef92f88f624deaf25bbb0b59c97 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Fri, 21 Jul 2023 10:01:30 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=A1=E7=94=A8=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ningdatech/pmapi/common/util/HttpUtil.java | 29 +++++++++++++ .../ding/controller/DingInfoPullController.java | 33 ++++++-------- .../pmapi/irs/controller/IrsController.java | 14 ++++++ .../pmapi/irs/utils/RefreshTokenUtil.java | 50 ++++++++++++++++++++++ .../pmapi/projectdeclared/manage/IrsManage.java | 20 +++++++++ .../java/com/ningdatech/pmapi/irs/IrsTest2.java | 34 ++++++++++++++- 6 files changed, 160 insertions(+), 20 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/irs/utils/RefreshTokenUtil.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/HttpUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/HttpUtil.java index fcc5333..2470fd3 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/util/HttpUtil.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/util/HttpUtil.java @@ -8,16 +8,23 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustStrategy; import org.apache.http.conn.util.PublicSuffixMatcher; import org.apache.http.conn.util.PublicSuffixMatcherLoader; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; +import org.apache.http.ssl.SSLContexts; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import javax.net.ssl.SSLContext; import java.io.IOException; import java.net.URL; import java.util.ArrayList; @@ -214,4 +221,26 @@ public class HttpUtil { } return responseContent; } + + /** + * 通过该工厂类创建的RestTemplate发送请求时,可忽略https证书认证 + * @return 工厂 + */ + public static HttpComponentsClientHttpRequestFactory generateHttpRequestFactory(){ + try{ + TrustStrategy acceptingTrustStrategy = ((x509Certificates, authType) -> true); + SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(); + SSLConnectionSocketFactory connectionSocketFactory = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier()); + + HttpClientBuilder httpClientBuilder = HttpClients.custom(); + httpClientBuilder.setSSLSocketFactory(connectionSocketFactory); + CloseableHttpClient httpClient = httpClientBuilder.build(); + HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); + factory.setHttpClient(httpClient); + return factory; + }catch (Exception e){ + e.printStackTrace(); + } + return null; + } } \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java b/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java index f708e4f..f07e985 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/ding/controller/DingInfoPullController.java @@ -1,19 +1,33 @@ package com.ningdatech.pmapi.ding.controller; +import cn.hutool.crypto.digest.MD5; import com.alibaba.fastjson.JSON; import com.ningdatech.pmapi.common.util.CryptUtils; +import com.ningdatech.pmapi.common.util.HttpUtil; +import com.ningdatech.pmapi.common.util.Md5Utils; import com.ningdatech.pmapi.common.util.RefreshKeyUtil; import com.ningdatech.pmapi.ding.task.EmployeeBatchGetTask; import com.ningdatech.pmapi.ding.task.GovBusinessStripsTask; import com.ningdatech.pmapi.ding.task.OrganizationBatchGetTask; +import com.ningdatech.pmapi.irs.utils.RefreshTokenUtil; import com.ningdatech.pmapi.organization.manage.ProcDefManage; import io.swagger.annotations.ApiOperation; +import liquibase.util.MD5Util; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustStrategy; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.RestTemplate; +import javax.net.ssl.SSLContext; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.security.NoSuchAlgorithmException; @@ -89,23 +103,4 @@ public class DingInfoPullController { public String init() { return procDefManage.init(); } - - @ApiOperation(value = "系统流程配置初始化", notes = "系统流程配置初始化") - @GetMapping("/test") - public String test() throws NoSuchAlgorithmException, UnsupportedEncodingException { - String appSecret = "e066f496194540afa829c66983d4710e"; - String appkey = "8fb070a1f1194b2ebffdc6f596bb8a96"; - String dataName = URLEncoder.encode("丽水市数管公司","UTF-8"); - long timestamp = System.currentTimeMillis(); - String sign = CryptUtils.MD5Encode(appkey + appSecret + timestamp); - String url = "https://interface.ls.local/a/api/shared/1689239219101?data_name=" + dataName + "&appKey=" + appkey + - "&sign=" + sign + "&requestTime=" + timestamp; - RestTemplate restTemplate = new RestTemplate(); - log.info("url:" + url); - ResponseEntity forEntity = restTemplate.getForEntity(url, String.class); - - System.out.println(JSON.toJSONString(forEntity)); - - return JSON.toJSONString(forEntity); - } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java index 5ea1c8c..02856c4 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/controller/IrsController.java @@ -1,6 +1,9 @@ package com.ningdatech.pmapi.irs.controller; import com.ningdatech.log.annotation.WebLog; +import com.ningdatech.pmapi.common.util.CryptUtils; +import com.ningdatech.pmapi.common.util.HttpUtil; +import com.ningdatech.pmapi.irs.utils.RefreshTokenUtil; import com.ningdatech.pmapi.projectdeclared.manage.IrsManage; import com.ningdatech.pmapi.projectdeclared.model.vo.IrsApplicationVO; import com.ningdatech.pmapi.projectdeclared.model.vo.PiotTasksVO; @@ -8,8 +11,13 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.RestTemplate; + +import java.io.UnsupportedEncodingException; +import java.security.NoSuchAlgorithmException; import java.util.List; /** @@ -41,4 +49,10 @@ public class IrsController { public List piotTasks() { return irsManage.listPiotTasks(); } + + @ApiOperation(value = "获取企业社会信用编码", notes = "获取企业社会信用编码") + @GetMapping("/get-credit-code") + public String getCreditCode() throws NoSuchAlgorithmException, UnsupportedEncodingException { + return irsManage.getCreditCode(); + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/utils/RefreshTokenUtil.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/utils/RefreshTokenUtil.java new file mode 100644 index 0000000..e9da6cd --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/utils/RefreshTokenUtil.java @@ -0,0 +1,50 @@ +package com.ningdatech.pmapi.irs.utils; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.ningdatech.pmapi.common.util.CryptUtils; +import com.ningdatech.pmapi.common.util.HttpUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +import java.security.NoSuchAlgorithmException; +import java.util.Objects; + +/** + * @Classname RefreshTokenManage + * @Description + * @Date 2023/7/20 15:53 + * @Author PoffyZhang + */ +@Slf4j +public class RefreshTokenUtil { + + public static String refrshByAppScret() throws NoSuchAlgorithmException { + long timestamp = System.currentTimeMillis(); + String appSecret = "e066f496194540afa829c66983d4710e"; + String appKey = "8fb070a1f1194b2ebffdc6f596bb8a96"; + String sign = CryptUtils.MD5Encode(appKey + appSecret + timestamp); + HttpComponentsClientHttpRequestFactory factory = HttpUtil.generateHttpRequestFactory(); + RestTemplate restTemplate; + if(Objects.nonNull(factory)){ + restTemplate = new RestTemplate(factory); + }else{ + restTemplate = new RestTemplate(); + } + String url = "https://interface.ls.local/a/api/refreshTokenKey?appKey=" + appKey + + "&requestTime=" + timestamp + "&sign=" + sign; + ResponseEntity forEntity = restTemplate.getForEntity(url, String.class); + + String body = forEntity.getBody(); + log.info(body); + + JSONObject bodyJson = JSON.parseObject(body); + JSONObject datas = bodyJson.getJSONObject("datas"); + String requestSecret = datas.getString("requestSecret"); + log.info("requestSecret :{}",requestSecret); + return requestSecret; + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/IrsManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/IrsManage.java index c8dfcd8..6e29118 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/IrsManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/IrsManage.java @@ -6,8 +6,11 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ningdatech.basic.util.CollUtils; +import com.ningdatech.pmapi.common.util.CryptUtils; +import com.ningdatech.pmapi.common.util.HttpUtil; import com.ningdatech.pmapi.irs.manage.AppIrsManage; import com.ningdatech.pmapi.irs.model.dto.ApiApplyDTO; +import com.ningdatech.pmapi.irs.utils.RefreshTokenUtil; import com.ningdatech.pmapi.projectdeclared.model.entity.IrsApplication; import com.ningdatech.pmapi.projectdeclared.model.entity.NdPiotTasks; import com.ningdatech.pmapi.projectdeclared.model.vo.IrsApplicationVO; @@ -17,7 +20,9 @@ import com.ningdatech.pmapi.projectdeclared.service.IrsApplicationService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; import java.security.NoSuchAlgorithmException; import java.util.Collections; @@ -82,4 +87,19 @@ public class IrsManage { } return CollUtils.convert(list,task -> BeanUtil.copyProperties(task,PiotTasksVO.class)); } + + public String getCreditCode() throws NoSuchAlgorithmException { + String appSecret = RefreshTokenUtil.refrshByAppScret(); + String appkey = "8fb070a1f1194b2ebffdc6f596bb8a96"; + String dataName = "丽水市大数据"; + long timestamp = System.currentTimeMillis(); + String sign = CryptUtils.MD5Encode(appkey + appSecret + timestamp); + String url = "https://interface.ls.local/a/api/shared/1689239219101?data_name=" + dataName + "&appKey=" + appkey + + "&sign=" + sign + "&requestTime=" + timestamp; + RestTemplate restTemplate = new RestTemplate(HttpUtil.generateHttpRequestFactory()); + log.info("url:" + url); + ResponseEntity forEntity = restTemplate.getForEntity(url, String.class); + log.info(forEntity.getBody()); + return forEntity.getBody(); + } } diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest2.java b/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest2.java index 6a0f480..f2a8839 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest2.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/irs/IrsTest2.java @@ -2,14 +2,17 @@ package com.ningdatech.pmapi.irs; import com.alibaba.fastjson.JSON; import com.ningdatech.pmapi.common.util.CryptUtils; -import com.ningdatech.pmapi.common.util.RefreshKeyUtil; +import com.ningdatech.pmapi.common.util.HttpUtil; +import liquibase.util.MD5Util; import org.junit.Test; import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.security.NoSuchAlgorithmException; +import java.util.Objects; /** * @Classname IrsTest2 @@ -35,4 +38,33 @@ public class IrsTest2 { System.out.println(JSON.toJSONString(forEntity)); } + @Test + public void refreshToken() throws NoSuchAlgorithmException { + long timestamp = System.currentTimeMillis(); + String appSecret = "e066f496194540afa829c66983d4710e"; + String appKey = "8fb070a1f1194b2ebffdc6f596bb8a96"; + String sign = CryptUtils.MD5Encode(appKey + appSecret + timestamp); + HttpComponentsClientHttpRequestFactory factory = HttpUtil.generateHttpRequestFactory(); + RestTemplate restTemplate; + if(Objects.nonNull(factory)){ + restTemplate = new RestTemplate(factory); + }else{ + restTemplate = new RestTemplate(); + } + String url = "https://interface.ls.local/a/api/refreshTokenKey?appKey=" + appKey + + "&requestTime=" + timestamp + "&sign=" + sign; + ResponseEntity forEntity = restTemplate.getForEntity(url, String.class); + System.out.println(forEntity.getBody()); + } + + @Test + public void test3() throws NoSuchAlgorithmException { + String timestamp = "1689841393364"; + String appSecret = "f12a6f2e9fc143fcbe4622295db097fd"; + String appkey = "8fb070a1f1194b2ebffdc6f596bb8a96"; + String sign1 = MD5Util.computeMD5(appkey + appSecret + timestamp); + String sign2 = CryptUtils.MD5Encode(appkey + appSecret + timestamp); + System.out.println(sign1); + System.out.println(sign2); + } } From 84ec6b221bdebb608f2053681d433c163fea5bcc Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Fri, 21 Jul 2023 10:16:15 +0800 Subject: [PATCH 2/3] redis --- pmapi/src/main/resources/application-prod.yml | 6 +++--- pmapi/src/test/resources/application-prod.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pmapi/src/main/resources/application-prod.yml b/pmapi/src/main/resources/application-prod.yml index 9c29682..ff426bb 100644 --- a/pmapi/src/main/resources/application-prod.yml +++ b/pmapi/src/main/resources/application-prod.yml @@ -13,9 +13,9 @@ spring: namespace: "spring:session" redis: timeout: 5000 - host: 47.98.125.47 - port: 26379 - database: 4 + host: localhost + port: 6379 + database: 0 password: Ndkj1234 jedis: pool: diff --git a/pmapi/src/test/resources/application-prod.yml b/pmapi/src/test/resources/application-prod.yml index e2c6623..f855139 100644 --- a/pmapi/src/test/resources/application-prod.yml +++ b/pmapi/src/test/resources/application-prod.yml @@ -13,9 +13,9 @@ spring: namespace: "spring:session" redis: timeout: 5000 - host: 47.98.125.47 - port: 26379 - database: 4 + host: localhost + port: 6379 + database: 0 password: Ndkj1234 jedis: pool: From d93ba31948c603bcb9dd42fd9814e94daaf7ee83 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Fri, 21 Jul 2023 10:51:49 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=A2=84=E5=8F=91=E7=8E=AF=E5=A2=83=20redi?= =?UTF-8?q?s=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pmapi/src/main/resources/application-pre.yml | 6 +++--- pmapi/src/test/resources/application-pre.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pmapi/src/main/resources/application-pre.yml b/pmapi/src/main/resources/application-pre.yml index ef10f06..e0330c2 100644 --- a/pmapi/src/main/resources/application-pre.yml +++ b/pmapi/src/main/resources/application-pre.yml @@ -13,9 +13,9 @@ spring: namespace: "spring:session" redis: timeout: 5000 - host: 47.98.125.47 - port: 26379 - database: 5 + host: localhost + port: 6379 + database: 0 password: Ndkj1234 jedis: pool: diff --git a/pmapi/src/test/resources/application-pre.yml b/pmapi/src/test/resources/application-pre.yml index ef10f06..e0330c2 100644 --- a/pmapi/src/test/resources/application-pre.yml +++ b/pmapi/src/test/resources/application-pre.yml @@ -13,9 +13,9 @@ spring: namespace: "spring:session" redis: timeout: 5000 - host: 47.98.125.47 - port: 26379 - database: 5 + host: localhost + port: 6379 + database: 0 password: Ndkj1234 jedis: pool: