@@ -8,6 +8,8 @@ | |||
<name>szyx-tcm-supervision</name> | |||
<description>szyx-tcm-supervision</description> | |||
<packaging>jar</packaging> | |||
<properties> | |||
<java.version>1.8</java.version> | |||
@@ -207,7 +209,7 @@ | |||
<dependency> | |||
<groupId>com.tencent.mip</groupId> | |||
<artifactId>med-request-data-sdk</artifactId> | |||
<version>2.1.2</version> | |||
<version>2.1.2-SNAPSHOT</version> | |||
</dependency> | |||
<dependency> | |||
@@ -251,6 +253,13 @@ | |||
<scope>compile</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.httpcomponents</groupId> | |||
<artifactId>httpclient</artifactId> | |||
<version>4.5.1</version> | |||
</dependency> | |||
</dependencies> | |||
@@ -330,7 +339,6 @@ | |||
<version>${spring-boot.version}</version> | |||
<configuration> | |||
<mainClass>com.szyx.tcm.supervision.SupervisionApplication</mainClass> | |||
<skip>true</skip> | |||
</configuration> | |||
<executions> | |||
<execution> | |||
@@ -4,6 +4,9 @@ import org.asynchttpclient.DefaultAsyncHttpClient; | |||
import org.asynchttpclient.DefaultAsyncHttpClientConfig; | |||
import org.springframework.context.annotation.Bean; | |||
import org.springframework.context.annotation.Configuration; | |||
import org.springframework.http.client.ClientHttpRequestFactory; | |||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | |||
import org.springframework.http.client.SimpleClientHttpRequestFactory; | |||
import org.springframework.web.client.RestTemplate; | |||
/******************************************************************* | |||
@@ -28,8 +31,18 @@ public class HttpConfig { | |||
} | |||
@Bean | |||
public RestTemplate restTemplate() { | |||
return new RestTemplate(); | |||
public RestTemplate restTemplate(ClientHttpRequestFactory factory) { | |||
RestTemplate restTemplate = new RestTemplate(); | |||
restTemplate.setRequestFactory(factory); | |||
return restTemplate; | |||
} | |||
@Bean | |||
public ClientHttpRequestFactory clientHttpRequestFactory() { | |||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); | |||
factory.setReadTimeout(10000); | |||
factory.setConnectTimeout(15000); | |||
return factory; | |||
} | |||
@@ -1,10 +1,12 @@ | |||
package com.szyx.tcm.supervision.controller.insurance; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.http.*; | |||
import org.springframework.web.bind.annotation.RequestBody; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import org.springframework.web.client.HttpClientErrorException; | |||
import org.springframework.web.client.RestTemplate; | |||
import javax.servlet.http.HttpServletRequest; | |||
@@ -24,6 +26,7 @@ import java.util.Objects; | |||
*/ | |||
@RestController | |||
@RequestMapping("/proxy") | |||
@Slf4j | |||
public class ProxyController { | |||
@Value("${insurance.host}") | |||
@@ -56,7 +59,16 @@ public class ProxyController { | |||
responseHeaders.setContentType(MediaType.APPLICATION_JSON); | |||
HttpEntity<String> entity = new HttpEntity<>(body, headers); | |||
ResponseEntity<String> response = restTemplate.exchange(url, Objects.requireNonNull(HttpMethod.resolve(request.getMethod())), entity, String.class); | |||
ResponseEntity<String> response = null; | |||
try { | |||
log.info("Proxy request: {} {}", request.getMethod(), url); | |||
log.info("Proxy request body: {}", body); | |||
response = restTemplate.exchange(url, Objects.requireNonNull(HttpMethod.resolve(request.getMethod())), entity, String.class); | |||
} catch (HttpClientErrorException e) { | |||
String resBody = e.getResponseBodyAsString(); | |||
log.error("Proxy request failed: {} {}", e.getStatusCode(), resBody); | |||
return new ResponseEntity<>(resBody, responseHeaders, e.getStatusCode()); | |||
} | |||
return new ResponseEntity<>(response.getBody(), responseHeaders,response.getStatusCode()); | |||
} | |||
@@ -1,5 +1,5 @@ | |||
# \u5E94\u7528\u670D\u52A1 WEB \u8BBF\u95EE\u7AEF\u53E3 | |||
server.port=9735 | |||
server.port=9011 | |||
spring.profiles.active=${profile.active} | |||
swagger.enable=true | |||
server.http.encoding.force=true | |||
@@ -15,7 +15,7 @@ spring.mvc.pathmatch.matching-strategy=ant_path_matcher | |||
arthas.slient-init=true | |||
# \u533B\u4FDD\u4E13\u7F51\u914D\u7F6E | |||
insurance.host =http://localhost:9345/ | |||
insurance.host =http://10.85.254.46:8000/ | |||
## \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 mysql \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 | |||
@@ -9,6 +9,7 @@ import com.szyx.tcm.supervision.model.dto.insurance.InsuranceCoreOutputMessage11 | |||
import com.szyx.tcm.supervision.model.dto.insurance.InsuranceUploadRecipeDetailInputMessage; | |||
import com.szyx.tcm.supervision.util.DateUtils; | |||
import com.szyx.tcm.supervision.util.InsuranceWechatUtil; | |||
import com.szyx.tcm.supervision.util.SZYXAccessUtil; | |||
import com.tencent.mip.DataHandler; | |||
import com.tencent.mip.MIPayInvoker; | |||
import com.tencent.mip.model.DetailUploadReq; | |||
@@ -88,6 +89,16 @@ public class InsuranceCoreDemo { | |||
} | |||
@Test | |||
public void test2() throws Exception { | |||
System.out.println("test2"); | |||
long timestamp = System.currentTimeMillis(); | |||
System.out.println(SZYXAccessUtil.encryptTimeStamp(timestamp)); | |||
System.out.println(SZYXAccessUtil.encryptByAES(Long.toString(timestamp))); | |||
System.out.println( InsuranceWechatUtil.getMsgId("H41148100267")); | |||
} | |||
private void buildText(InsuranceUploadRecipeDetailInputMessage uploadData){ | |||
// 医保核心系统患者基本信息 | |||
@@ -0,0 +1,161 @@ | |||
package com.szyx.tcm.supervision; | |||
import com.szyx.tcm.supervision.util.SZYXAccessUtil; | |||
import org.apache.http.HttpEntity; | |||
import org.apache.http.HttpStatus; | |||
import org.apache.http.client.ClientProtocolException; | |||
import org.apache.http.client.config.RequestConfig; | |||
import org.apache.http.client.methods.CloseableHttpResponse; | |||
import org.apache.http.client.methods.HttpPost; | |||
import org.apache.http.entity.ByteArrayEntity; | |||
import org.apache.http.impl.client.CloseableHttpClient; | |||
import org.apache.http.impl.client.HttpClients; | |||
import org.apache.http.util.EntityUtils; | |||
import org.junit.jupiter.api.Test; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.nio.charset.StandardCharsets; | |||
/******************************************************************* | |||
* <pre></pre> | |||
* @文件名称: testDemo.java | |||
* @包 路 径: com.szyx.tcm.supervision | |||
* @Copyright:wy (C) 2024 * | |||
* @Description: | |||
* @Version: V1.0 | |||
* @Author: wy | |||
* @Date: 2024/7/28 15:34 | |||
* @Modify: | |||
*/ | |||
public class testDemo { | |||
private static final String url = "http://123.54.6.202:49336/szyx/api/insurancePayment/proxy/hss-call-service-interface"; | |||
/** 按照报文要求传入JSON格式字符串 */ | |||
private static final String downInput = "{…}"; | |||
/** | |||
* 调用普通交易及文件下载交易 | |||
*/ | |||
@Test | |||
public void test1() { | |||
CloseableHttpClient httpclient = HttpClients.createDefault(); | |||
HttpPost httppost = new HttpPost(url); | |||
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).build(); | |||
httppost.setConfig(requestConfig); | |||
long timestamp = System.currentTimeMillis(); | |||
httppost.setHeader("timestamp", SZYXAccessUtil.encryptTimeStamp(timestamp)); | |||
httppost.setHeader("accessToken", SZYXAccessUtil.encryptByAES(Long.toString(timestamp))); | |||
ByteArrayEntity entity = new ByteArrayEntity(downInput.getBytes(StandardCharsets.UTF_8)); | |||
entity.setContentType("text/plain"); | |||
httppost.setEntity(entity); | |||
CloseableHttpResponse response = null; | |||
try { | |||
response = httpclient.execute(httppost); | |||
int statusCode = response.getStatusLine().getStatusCode(); | |||
if (statusCode != HttpStatus.SC_OK) { | |||
httppost.abort(); | |||
throw new RuntimeException("HttpClient,error status code :" + statusCode); | |||
} | |||
HttpEntity responseEntity = response.getEntity(); | |||
String result; | |||
if (responseEntity != null) { | |||
if (responseEntity.getContentType().getValue().contains("application/octet-stream")) { | |||
InputStream content = responseEntity.getContent(); | |||
//返回文件流 | |||
File file = new File("testDownload.txt"); | |||
FileOutputStream fileOutputStream = new FileOutputStream(file); | |||
int temp; | |||
while ((temp = content.read()) != -1) { | |||
fileOutputStream.write(temp); | |||
} | |||
fileOutputStream.close(); | |||
} else { | |||
//返回字符串 | |||
result = EntityUtils.toString(responseEntity, "UTF-8"); | |||
System.out.println(result); | |||
} | |||
} | |||
EntityUtils.consume(entity); | |||
} catch (ClientProtocolException e) { | |||
throw new RuntimeException("提交给服务器的请求,不符合HTTP协议", e); | |||
} catch (IOException e) { | |||
throw new RuntimeException("向服务器承保接口发起http请求,执行post请求异常", e); | |||
} finally { | |||
if (response != null) { | |||
try { | |||
response.close(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
if (httpclient != null) { | |||
try { | |||
httpclient.close(); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* 调用文件上传交易 | |||
*/ | |||
// @Test | |||
// public void test2() { | |||
// File file = new File("testUpload.txt"); | |||
// CloseableHttpClient httpclient = HttpClients.createDefault(); | |||
// HttpPost httppost = new HttpPost(url); | |||
// RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10000).setSocketTimeout(10000).build(); | |||
// httppost.setConfig(requestConfig); | |||
// MultipartEntityBuilder builder = MultipartEntityBuilder.create(); | |||
// builder.setCharset(StandardCharsets.UTF_8); | |||
// builder.addTextBody("jsonStr", upInput); | |||
// builder.addBinaryBody("file", file, ContentType.DEFAULT_BINARY, "testUpload.txt"); | |||
// HttpEntity entity = builder.build(); | |||
// httppost.setEntity(entity); | |||
// CloseableHttpResponse response = null; | |||
// try { | |||
// response = httpclient.execute(httppost); | |||
// int statusCode = response.getStatusLine().getStatusCode(); | |||
// if (statusCode != HttpStatus.SC_OK) { | |||
// httppost.abort(); | |||
// throw new RuntimeException("HttpClient,error status code :" + statusCode); | |||
// } | |||
// HttpEntity responseEntity = response.getEntity(); | |||
// String result; | |||
// if (responseEntity != null) { | |||
// //返回字符串 | |||
// result = EntityUtils.toString(responseEntity, "UTF-8"); | |||
// System.out.println(result); | |||
// } | |||
// EntityUtils.consume(entity); | |||
// } catch (ClientProtocolException e) { | |||
// throw new RuntimeException("提交给服务器的请求,不符合HTTP协议", e); | |||
// } catch (IOException e) { | |||
// throw new RuntimeException("向服务器承保接口发起http请求,执行post请求异常", e); | |||
// } finally { | |||
// if (response != null) { | |||
// try { | |||
// response.close(); | |||
// } catch (IOException e) { | |||
// e.printStackTrace(); | |||
// } | |||
// } | |||
// if (httpclient != null) { | |||
// try { | |||
// httpclient.close(); | |||
// } catch (IOException e) { | |||
// e.printStackTrace(); | |||
// } | |||
// } | |||
// } | |||
// } | |||
} |