@@ -8,16 +8,23 @@ import org.apache.http.client.methods.CloseableHttpResponse; | |||||
import org.apache.http.client.methods.HttpGet; | import org.apache.http.client.methods.HttpGet; | ||||
import org.apache.http.client.methods.HttpPost; | import org.apache.http.client.methods.HttpPost; | ||||
import org.apache.http.conn.ssl.DefaultHostnameVerifier; | 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.PublicSuffixMatcher; | ||||
import org.apache.http.conn.util.PublicSuffixMatcherLoader; | import org.apache.http.conn.util.PublicSuffixMatcherLoader; | ||||
import org.apache.http.entity.StringEntity; | import org.apache.http.entity.StringEntity; | ||||
import org.apache.http.impl.client.CloseableHttpClient; | 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.impl.client.HttpClients; | ||||
import org.apache.http.message.BasicNameValuePair; | import org.apache.http.message.BasicNameValuePair; | ||||
import org.apache.http.ssl.SSLContexts; | |||||
import org.apache.http.util.EntityUtils; | import org.apache.http.util.EntityUtils; | ||||
import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | |||||
import javax.net.ssl.SSLContext; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.net.URL; | import java.net.URL; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
@@ -214,4 +221,26 @@ public class HttpUtil { | |||||
} | } | ||||
return responseContent; | 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; | |||||
} | |||||
} | } |
@@ -1,19 +1,33 @@ | |||||
package com.ningdatech.pmapi.ding.controller; | package com.ningdatech.pmapi.ding.controller; | ||||
import cn.hutool.crypto.digest.MD5; | |||||
import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
import com.ningdatech.pmapi.common.util.CryptUtils; | 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.common.util.RefreshKeyUtil; | ||||
import com.ningdatech.pmapi.ding.task.EmployeeBatchGetTask; | import com.ningdatech.pmapi.ding.task.EmployeeBatchGetTask; | ||||
import com.ningdatech.pmapi.ding.task.GovBusinessStripsTask; | import com.ningdatech.pmapi.ding.task.GovBusinessStripsTask; | ||||
import com.ningdatech.pmapi.ding.task.OrganizationBatchGetTask; | import com.ningdatech.pmapi.ding.task.OrganizationBatchGetTask; | ||||
import com.ningdatech.pmapi.irs.utils.RefreshTokenUtil; | |||||
import com.ningdatech.pmapi.organization.manage.ProcDefManage; | import com.ningdatech.pmapi.organization.manage.ProcDefManage; | ||||
import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
import liquibase.util.MD5Util; | |||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
import lombok.extern.slf4j.Slf4j; | 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.ResponseEntity; | ||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | |||||
import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
import org.springframework.web.client.RestTemplate; | import org.springframework.web.client.RestTemplate; | ||||
import javax.net.ssl.SSLContext; | |||||
import java.io.UnsupportedEncodingException; | import java.io.UnsupportedEncodingException; | ||||
import java.net.URLEncoder; | import java.net.URLEncoder; | ||||
import java.security.NoSuchAlgorithmException; | import java.security.NoSuchAlgorithmException; | ||||
@@ -89,23 +103,4 @@ public class DingInfoPullController { | |||||
public String init() { | public String init() { | ||||
return procDefManage.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<String> forEntity = restTemplate.getForEntity(url, String.class); | |||||
System.out.println(JSON.toJSONString(forEntity)); | |||||
return JSON.toJSONString(forEntity); | |||||
} | |||||
} | } |
@@ -1,6 +1,9 @@ | |||||
package com.ningdatech.pmapi.irs.controller; | package com.ningdatech.pmapi.irs.controller; | ||||
import com.ningdatech.log.annotation.WebLog; | 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.manage.IrsManage; | ||||
import com.ningdatech.pmapi.projectdeclared.model.vo.IrsApplicationVO; | import com.ningdatech.pmapi.projectdeclared.model.vo.IrsApplicationVO; | ||||
import com.ningdatech.pmapi.projectdeclared.model.vo.PiotTasksVO; | import com.ningdatech.pmapi.projectdeclared.model.vo.PiotTasksVO; | ||||
@@ -8,8 +11,13 @@ import io.swagger.annotations.Api; | |||||
import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.http.ResponseEntity; | |||||
import org.springframework.validation.annotation.Validated; | import org.springframework.validation.annotation.Validated; | ||||
import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
import org.springframework.web.client.RestTemplate; | |||||
import java.io.UnsupportedEncodingException; | |||||
import java.security.NoSuchAlgorithmException; | |||||
import java.util.List; | import java.util.List; | ||||
/** | /** | ||||
@@ -41,4 +49,10 @@ public class IrsController { | |||||
public List<PiotTasksVO> piotTasks() { | public List<PiotTasksVO> piotTasks() { | ||||
return irsManage.listPiotTasks(); | return irsManage.listPiotTasks(); | ||||
} | } | ||||
@ApiOperation(value = "获取企业社会信用编码", notes = "获取企业社会信用编码") | |||||
@GetMapping("/get-credit-code") | |||||
public String getCreditCode() throws NoSuchAlgorithmException, UnsupportedEncodingException { | |||||
return irsManage.getCreditCode(); | |||||
} | |||||
} | } |
@@ -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<String> 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; | |||||
} | |||||
} |
@@ -6,8 +6,11 @@ import com.alibaba.fastjson.JSON; | |||||
import com.alibaba.fastjson.JSONArray; | import com.alibaba.fastjson.JSONArray; | ||||
import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
import com.ningdatech.basic.util.CollUtils; | 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.manage.AppIrsManage; | ||||
import com.ningdatech.pmapi.irs.model.dto.ApiApplyDTO; | 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.IrsApplication; | ||||
import com.ningdatech.pmapi.projectdeclared.model.entity.NdPiotTasks; | import com.ningdatech.pmapi.projectdeclared.model.entity.NdPiotTasks; | ||||
import com.ningdatech.pmapi.projectdeclared.model.vo.IrsApplicationVO; | import com.ningdatech.pmapi.projectdeclared.model.vo.IrsApplicationVO; | ||||
@@ -17,7 +20,9 @@ import com.ningdatech.pmapi.projectdeclared.service.IrsApplicationService; | |||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
import org.springframework.http.ResponseEntity; | |||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
import org.springframework.web.client.RestTemplate; | |||||
import java.security.NoSuchAlgorithmException; | import java.security.NoSuchAlgorithmException; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
@@ -82,4 +87,19 @@ public class IrsManage { | |||||
} | } | ||||
return CollUtils.convert(list,task -> BeanUtil.copyProperties(task,PiotTasksVO.class)); | 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<String> forEntity = restTemplate.getForEntity(url, String.class); | |||||
log.info(forEntity.getBody()); | |||||
return forEntity.getBody(); | |||||
} | |||||
} | } |
@@ -13,9 +13,9 @@ spring: | |||||
namespace: "spring:session" | namespace: "spring:session" | ||||
redis: | redis: | ||||
timeout: 5000 | timeout: 5000 | ||||
host: 47.98.125.47 | |||||
port: 26379 | |||||
database: 5 | |||||
host: localhost | |||||
port: 6379 | |||||
database: 0 | |||||
password: Ndkj1234 | password: Ndkj1234 | ||||
jedis: | jedis: | ||||
pool: | pool: | ||||
@@ -13,9 +13,9 @@ spring: | |||||
namespace: "spring:session" | namespace: "spring:session" | ||||
redis: | redis: | ||||
timeout: 5000 | timeout: 5000 | ||||
host: 47.98.125.47 | |||||
port: 26379 | |||||
database: 4 | |||||
host: localhost | |||||
port: 6379 | |||||
database: 0 | |||||
password: Ndkj1234 | password: Ndkj1234 | ||||
jedis: | jedis: | ||||
pool: | pool: | ||||
@@ -2,14 +2,17 @@ package com.ningdatech.pmapi.irs; | |||||
import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
import com.ningdatech.pmapi.common.util.CryptUtils; | 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.junit.Test; | ||||
import org.springframework.http.ResponseEntity; | import org.springframework.http.ResponseEntity; | ||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | |||||
import org.springframework.web.client.RestTemplate; | import org.springframework.web.client.RestTemplate; | ||||
import java.io.UnsupportedEncodingException; | import java.io.UnsupportedEncodingException; | ||||
import java.net.URLEncoder; | import java.net.URLEncoder; | ||||
import java.security.NoSuchAlgorithmException; | import java.security.NoSuchAlgorithmException; | ||||
import java.util.Objects; | |||||
/** | /** | ||||
* @Classname IrsTest2 | * @Classname IrsTest2 | ||||
@@ -35,4 +38,33 @@ public class IrsTest2 { | |||||
System.out.println(JSON.toJSONString(forEntity)); | 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<String> 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); | |||||
} | |||||
} | } |
@@ -13,9 +13,9 @@ spring: | |||||
namespace: "spring:session" | namespace: "spring:session" | ||||
redis: | redis: | ||||
timeout: 5000 | timeout: 5000 | ||||
host: 47.98.125.47 | |||||
port: 26379 | |||||
database: 5 | |||||
host: localhost | |||||
port: 6379 | |||||
database: 0 | |||||
password: Ndkj1234 | password: Ndkj1234 | ||||
jedis: | jedis: | ||||
pool: | pool: | ||||
@@ -13,9 +13,9 @@ spring: | |||||
namespace: "spring:session" | namespace: "spring:session" | ||||
redis: | redis: | ||||
timeout: 5000 | timeout: 5000 | ||||
host: 47.98.125.47 | |||||
port: 26379 | |||||
database: 4 | |||||
host: localhost | |||||
port: 6379 | |||||
database: 0 | |||||
password: Ndkj1234 | password: Ndkj1234 | ||||
jedis: | jedis: | ||||
pool: | pool: | ||||