增加金域外送

1.1_jinyuwaisong
zengwh 2 years ago
parent 532cfec2dd
commit 47e87687f4

@ -106,6 +106,26 @@
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
</dependencies>
<build>

@ -8,6 +8,7 @@ import com.ann.demo.entity.filing.MessageSubordinate;
import com.ann.demo.entity.filing.dto.MessageDto;
import com.ann.demo.entity.filing.dto.PatientMainDto;
import com.ann.demo.service.AnalysisService;
import com.ann.demo.service.CollectCheckService;
import com.ann.demo.utils.XMLUtils;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
@ -16,6 +17,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Objects;
@ -30,6 +32,9 @@ public class TestController {
@Autowired
AnalysisService analysisService;
@Resource
private CollectCheckService collectCheckService;
@RequestMapping("/demo")
public String aa() {
return "demo";
@ -61,4 +66,11 @@ public class TestController {
}
return "redirect:/demo";
}
@RequestMapping("/demo1")
@ResponseBody
public String demo1() {
collectCheckService.downFileWithCheck("123","100041535327","GZ002WWRQAZEUXP","http://kmcs.kingmed.com.cn:8890/km-platform-web/restful/fileDownload/0df10c5e-af85-4acd-b2df-c1628f77b59c@88f14792ee4a31129fa721f85e2068bb");
return "demo1";
}
}

@ -0,0 +1,19 @@
package com.ann.demo.entity.interfaceEntity;
public class Patient
{
private String patientid;
public void setPatientid(String patientid){
this.patientid = patientid;
}
public String getPatientid(){
return this.patientid;
}
public Patient(String patientid) {
this.patientid = patientid;
}
}

@ -0,0 +1,76 @@
package com.ann.demo.entity.interfaceEntity;
import java.util.ArrayList;
import java.util.List;
public class Root
{
private String collectorid;
private String ip;
private String assortid;
private Patient patient;
private List<Scanfiles> scanfiles;
private String scanusercode;
private String scanusername;
public Root(Scanfiles scanfiles,String masterId) {
List<Scanfiles> list = new ArrayList<>();
list.add(scanfiles);
this.collectorid = "10";
this.ip = "127.0.0.1";
this.assortid = "10";
this.patient = new Patient(masterId);
this.scanfiles = list;
this.scanusercode = "zwh";
this.scanusername = "zwh";
}
public void setCollectorid(String collectorid){
this.collectorid = collectorid;
}
public String getCollectorid(){
return this.collectorid;
}
public void setIp(String ip){
this.ip = ip;
}
public String getIp(){
return this.ip;
}
public void setAssortid(String assortid){
this.assortid = assortid;
}
public String getAssortid(){
return this.assortid;
}
public void setPatient(Patient patient){
this.patient = patient;
}
public Patient getPatient(){
return this.patient;
}
public void setScanfiles(List<Scanfiles> scanfiles){
this.scanfiles = scanfiles;
}
public List<Scanfiles> getScanfiles(){
return this.scanfiles;
}
public void setScanusercode(String scanusercode){
this.scanusercode = scanusercode;
}
public String getScanusercode(){
return this.scanusercode;
}
public void setScanusername(String scanusername){
this.scanusername = scanusername;
}
public String getScanusername(){
return this.scanusername;
}
}

@ -0,0 +1,71 @@
package com.ann.demo.entity.interfaceEntity;
public class Scanfiles
{
private int taskid;
private String filetitle;
private int filesource;
private int filestoragetype;
private int filetype;
private String downurl;
private String serialnum;
public Scanfiles(String filetitle,String downurl, String serialnum) {
this.taskid = -1;
this.filetitle = filetitle;
this.filesource = 1;
this.filestoragetype = 1;
this.filetype = 2;
this.downurl = downurl;
this.serialnum = serialnum;
}
public void setTaskid(int taskid){
this.taskid = taskid;
}
public int getTaskid(){
return this.taskid;
}
public void setFiletitle(String filetitle){
this.filetitle = filetitle;
}
public String getFiletitle(){
return this.filetitle;
}
public void setFilesource(int filesource){
this.filesource = filesource;
}
public int getFilesource(){
return this.filesource;
}
public void setFilestoragetype(int filestoragetype){
this.filestoragetype = filestoragetype;
}
public int getFilestoragetype(){
return this.filestoragetype;
}
public void setFiletype(int filetype){
this.filetype = filetype;
}
public int getFiletype(){
return this.filetype;
}
public void setDownurl(String downurl){
this.downurl = downurl;
}
public String getDownurl(){
return this.downurl;
}
public void setSerialnum(String serialnum){
this.serialnum = serialnum;
}
public String getSerialnum(){
return this.serialnum;
}
}

@ -10,6 +10,7 @@ import com.ann.demo.entity.filing.dto.PatientMainDto;
import com.ann.demo.entity.filing.ArchiveDetail;
import com.ann.demo.entity.interfaceEntity.ExamApply;
import com.ann.demo.entity.interfaceEntity.MessageLog;
import com.ann.demo.utils.Base64Utils;
import com.ann.demo.utils.FileUtils;
import com.ann.demo.utils.PdfUtils;
import com.ann.demo.utils.XMLUtils;
@ -19,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.io.File;
import java.util.Date;
import java.util.Objects;
@ -47,6 +49,8 @@ public class AnalysisService {
@Autowired
ArchiveDetailService archiveDetailService;
@Resource
private CollectCheckService collectCheckService;
/**
* 2019-7-8
* @Param xmlStr
@ -80,20 +84,28 @@ public class AnalysisService {
//System.out.println(messageDto.getReportAddress());
UUID uuid = UUID.randomUUID();
File pdfFile = FileUtils.createFile("pdfs", messageDto.getInpNo(), messageDto.getVisitId(), uuid.toString(), null);
if(PdfUtils.base64StringToPDF(messageDto.getReportAddress(),pdfFile)){
// 查询库中是否存在 如果存在就更新
archiveDetail = archiveDetailService.isExit(archiveMasterId, messageDto.getType(), messageDto.getSource(), messageDto.getApplyId(),messageDto.getCheckReportId());
if (archiveDetail == null) {
archiveDetail = new ArchiveDetail(uuid.toString(),archiveMasterId, new Date(), messageDto.getType(), messageDto.getSource(), messageDto.getApplyId(),
messageDto.getDetailType(),messageDto.getCheckReportId());
archiveDetail.setPdfPath(pdfFile.getAbsolutePath());
archiveDetailService.save(archiveDetail);
}else{
archiveDetail.setPdfPath(pdfFile.getAbsolutePath());
archiveDetailService.save(archiveDetail);
if(Base64Utils.isBase64(messageDto.getReportAddress())) {
//是base64
if (!PdfUtils.base64StringToPDF(messageDto.getReportAddress(), pdfFile)) {
textContentTemp = "加密字节流转换pdf失败";
}
}else{
textContentTemp = "加密字节流转换pdf失败";
//不是base64 2023-09-05新增根据接口下载pdf
boolean downFileFlag = collectCheckService.downFileWithCheck(archiveMasterId,messageDto.getBarCode(),messageDto.getCheckReportId(), messageDto.getReportAddress());
if(!downFileFlag){
textContentTemp = "金域外送base64下载失败";
}
}
// 查询库中是否存在 如果存在就更新
archiveDetail = archiveDetailService.isExit(archiveMasterId, messageDto.getType(), messageDto.getSource(), messageDto.getApplyId(),messageDto.getCheckReportId());
if (archiveDetail == null) {
archiveDetail = new ArchiveDetail(uuid.toString(),archiveMasterId, new Date(), messageDto.getType(), messageDto.getSource(), messageDto.getApplyId(),
messageDto.getDetailType(),messageDto.getCheckReportId());
archiveDetail.setPdfPath(pdfFile.getAbsolutePath());
archiveDetailService.save(archiveDetail);
}else{
archiveDetail.setPdfPath(pdfFile.getAbsolutePath());
archiveDetailService.save(archiveDetail);
}
// 替换消息的pdf节点
String tempMessage = XMLUtils.replaceXpath(message, pdfFile.getAbsolutePath());
@ -149,7 +161,6 @@ public class AnalysisService {
return outContent;
}
private String changeApply(ExamApply examApply,String interfaceName) throws Exception{
String textContent = null;
ExamApply examApplyTemp = examApplyService.findExamApply(examApply.getApplyId());

@ -0,0 +1,268 @@
package com.ann.demo.service;
import com.alibaba.fastjson.JSON;
import com.ann.demo.utils.HttpClientUtils;
import com.ann.demo.utils.JsonUtils;
import com.ann.demo.utils.Md5Utils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.axis.client.Call;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;
import org.apache.axis.client.Service;
import org.apache.axis.utils.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author
* @description:
* @createTime 2023/9/5 16:48
*/
@Component
@Slf4j
public class CollectCheckService {
private Map<String,String> tokenCacheMap = new HashMap<>();
private String FILENAME = "fileName";
private String FILEBASE64 = "fileBase64";
@Value("${siteCode}")
private String siteCode;
@Value("${customerCode}")
private String customerCode;
@Value("${collectionLocation}")
private String collectionLocation;
@Value("${loginUrl}")
private String loginUrl;
@Value("${namespaceURI}")
private String namespaceURI;
@Value("${webServiceMethod}")
private String webServiceMethod;
@Value("${webServiceDownMethod}")
private String webServiceDownMethod;
@Value("${downfileUrl}")
private String downfileUrl;
public boolean downFileWithCheck(String masterId,String hospBarcode,String reportOdd,String fileUrl) {
//登录
String token = getTokenByCheckKey(siteCode, customerCode, collectionLocation);
//下载
return downFileWithCheck(masterId,hospBarcode,reportOdd,fileUrl,token);
}
/**
*
* @param masterId
* @param hospBarcode
* @param reportOdd
* @param fileUrl
* @param token
* @return
*/
private boolean downFileWithCheck(String masterId,String hospBarcode,String reportOdd,String fileUrl,String token){
//根据参数请求接口返回json数据
String result = reqInterfaceByParam(hospBarcode, reportOdd, fileUrl, token);
//解析返回json数据
Map<String,String> map = analysisData(result);
//唯一文件码
String serialnum = hospBarcode + "_" + reportOdd;
//根据解析的数据调用下载
String reqResult = downFile(masterId,map,serialnum);
if(!StringUtils.isEmpty(reqResult)) {
String code = JsonUtils.getValueByKey(reqResult, "code");
if(!StringUtils.isEmpty(code) && "0".equals(code)){
return true;
}
}
return false;
}
/**
*
* @param map
*/
private String downFile(String masterId,Map<String, String> map,String serialnum) {
if(!CollectionUtils.isEmpty(map)){
//设置下载参数
Map rootMap = setDownReqParams(masterId, map, serialnum);
//调用下载接口
String result = HttpClientUtils.doPost(downfileUrl,JSON.toJSONString(rootMap));
log.info("上传下载服务result:"+result);
return result;
}
return null;
}
/**
*
* @param masterId
* @param map
* @param serialnum
* @return
*/
private Map setDownReqParams(String masterId, Map<String, String> map, String serialnum) {
//设置文件信息参数
Map<String,Object> scanfilesMap = new HashMap<>();
scanfilesMap.put("taskid",-1);
scanfilesMap.put("filetitle", map.get(FILENAME));
scanfilesMap.put("filesource",1);
scanfilesMap.put("filestoragetype",1);
scanfilesMap.put("filetype",2);
scanfilesMap.put("downurl", map.get(FILEBASE64));
scanfilesMap.put("serialnum", serialnum +"1");
List<Map<String,Object>> scanfilesList = new ArrayList<>();
scanfilesList.add(scanfilesMap);
//设置患者信息参数
Map<String,Object> patientMap = new HashMap<>();
patientMap.put("patientid", masterId);
//设置全部参数
Map rootMap = new HashMap<>();
rootMap.put("collectorid","10");
rootMap.put("ip","127.0.0.1");
rootMap.put("assortid","10");
rootMap.put("patient",patientMap);
rootMap.put("scanfiles",scanfilesList);
rootMap.put("scanusercode","zwh");
rootMap.put("scanusername","zwh");
return rootMap;
}
/**
* json
* @param result
*/
private Map<String,String> analysisData(String result) {
Map<String,String> map = new HashMap<>();
if(!StringUtils.isEmpty(result)) {
ObjectMapper objectMapper = new ObjectMapper();
//解析
try {
// 将JSON字符串转换为Map对象
JsonNode jsonNode = objectMapper.readTree(result);
String fileName = jsonNode.get("result").get("fileName").asText();
if (!StringUtils.isEmpty(fileName)) {
fileName = fileName.substring(0, fileName.length() - 4);
}
map.put(FILENAME,fileName);
String fileBase64 = jsonNode.get("result").get("file").asText();
map.put(FILEBASE64,fileBase64);
} catch (IOException e) {
e.printStackTrace();
}
}
return map;
}
/**
*
* @param hospBarcode
* @param reportOdd
* @param fileUrl
* @param token
* @return
*/
private String reqInterfaceByParam(String hospBarcode, String reportOdd, String fileUrl, String token) {
Map<String,String> paramMap = new HashMap<>();
paramMap.put("siteCode",siteCode);
paramMap.put("customerCode",customerCode);
paramMap.put("collectionLocation",collectionLocation);
paramMap.put("hospBarcode", hospBarcode);
paramMap.put("reportOdd", reportOdd);
paramMap.put("fileUrl", fileUrl);
String paramStr = JSON.toJSONString(paramMap);
String jsonMd5 = Md5Utils.strToMd5(paramStr);
//调用webService
Object[] objects = {jsonMd5, token, paramStr};
String[] params ={"md5","token","postJson"};
String result = null;
try {
result = getWebService(loginUrl,namespaceURI,webServiceDownMethod,params,objects);
} catch (Exception e) {
e.printStackTrace();
log.info("调用接口失败:"+objects.toString());
}
return result;
}
/**
*
* @param siteCode
* @param customerCode
* @param collectionLocation
* @return
*/
private String getTokenByCheckKey(String siteCode,String customerCode,String collectionLocation){
//组织协定秘钥secretKey
SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
String toDay = fmt.format(new Date());
//判断token是否存在
String token = tokenCacheMap.get(toDay);
if(!StringUtils.isEmpty(token)){
//取缓存
return token;
}
String secretKey = collectionLocation + customerCode + siteCode + toDay;
//MD5转换
String secretKeyMd5 = Md5Utils.strToMd5(secretKey);
//调用第三方webService接口登录
//实例化org.apache.axis.client.Service对象
//创建service调用对象
Object[] objects = {siteCode, customerCode, collectionLocation, secretKeyMd5};
String[] params ={"siteCode","customerCode","collectionLocation","secretKey"};
String result = getWebService(loginUrl,namespaceURI,webServiceMethod,params,objects);
ObjectMapper objectMapper = new ObjectMapper();
//解析
try {
// 将JSON字符串转换为Map对象
JsonNode jsonNode = objectMapper.readTree(result);
token = jsonNode.get("result").get("token").asText();
} catch (IOException e) {
e.printStackTrace();
}
if(!StringUtils.isEmpty(token)) {
//存缓存
tokenCacheMap.clear();
tokenCacheMap.put(toDay, token);
}
return token;
}
/**
* webService
* @return
*/
private String getWebService(String webServiceUrl,String namespaceURI,String webServiceMethod,String[] params,Object[] objects ){
try {
Service service = new Service();
Call call;
call=(Call) service.createCall();
QName opAddEntry = new QName(namespaceURI, webServiceMethod); //设置命名空间和需要调用的方法名
call.setTargetEndpointAddress(webServiceUrl); //设置请求路径
call.setOperationName(webServiceMethod); //调用的方法名
call.setTimeout(Integer.valueOf(2000)); //设置请求超时
//按顺序设置请求参数、请求类型,多个需多添加参数
for(String param : params){
call.addParameter(param, XMLType.XSD_STRING, ParameterMode.IN);
}
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
return (String) call.invoke(opAddEntry,objects);
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,42 @@
package com.ann.demo.service;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.CXFBusFactory;
import org.apache.cxf.endpoint.EndpointImplFactory;
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
import org.apache.cxf.jaxws.support.JaxWsEndpointImplFactory;
import java.util.List;
public class JAXDynamicClientFactory extends DynamicClientFactory {
protected JAXDynamicClientFactory(Bus bus) {
super(bus);
}
protected EndpointImplFactory getEndpointImplFactory() {
return JaxWsEndpointImplFactory.getSingleton();
}
protected boolean allowWrapperOps() {
return true;
}
public static JAXDynamicClientFactory newInstance(Bus b) {
return new JAXDynamicClientFactory(b);
}
public static JAXDynamicClientFactory newInstance() {
Bus bus = CXFBusFactory.getThreadDefaultBus();
return new JAXDynamicClientFactory(bus);
}
public boolean compileJavaSrc(String classPath, List srcList, String dest) {
org.apache.cxf.common.util.Compiler javaCompiler
= new org.apache.cxf.common.util.Compiler();
javaCompiler.setEncoding("UTF-8");
javaCompiler.setClassPath(classPath);
javaCompiler.setOutputDir(dest);
javaCompiler.setTarget("1.8");
return javaCompiler.compileFiles(srcList);
}
}

@ -13,4 +13,13 @@ public class Base64Utils {
}
return null;
}
public static boolean isBase64(String str) {
try {
Base64.decode(str);
return true;
} catch (IllegalArgumentException e) {
return false;
}
}
}

@ -0,0 +1,269 @@
/**
* Copyright (C), 2015-2019
* Author: HJL
* Date: 2019/6/13 18:49
* Description:
*/
package com.ann.demo.utils;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
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.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* HttpClient4.3
*
* @author
*/
public class HttpClientUtils {
private static Logger logger = LoggerFactory.getLogger(HttpClientUtils.class); // 日志记录
private static RequestConfig requestConfig = null;
static {
// 设置请求和传输超时时间
requestConfig = RequestConfig.custom().setSocketTimeout(600000).setConnectTimeout(600000).build();
}
/**
* postjson
*
* @param url url
* @param jsonParam
* @return
*/
public static JSONObject httpPost(String url, JSONObject jsonParam) {
// post请求返回结果
CloseableHttpClient httpClient = HttpClients.createDefault();
JSONObject jsonResult = null;
HttpPost httpPost = new HttpPost(url);
// 设置请求和传输超时时间
httpPost.setConfig(requestConfig);
try {
if (null != jsonParam) {
// 解决中文乱码问题
StringEntity entity = new StringEntity(jsonParam.toString(), "utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);
}
CloseableHttpResponse result = httpClient.execute(httpPost);
// 请求发送成功,并得到响应
if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String str = "";
try {
// 读取服务器返回过来的json字符串数据
str = EntityUtils.toString(result.getEntity(), "utf-8");
// 把json字符串转换成json对象
jsonResult = JSONObject.parseObject(str);
} catch (Exception e) {
logger.error("post请求提交失败:" + url, e);
}
}
} catch (IOException e) {
logger.error("post请求提交失败:" + url, e);
} finally {
httpPost.releaseConnection();
}
return jsonResult;
}
/**
* postString name=Jack&sex=1&type=2
* Content-type:application/x-www-form-urlencoded
*
* @param url url
* @param strParam
* @return
*/
public static JSONObject httpPost(String url, String strParam) {
// post请求返回结果
CloseableHttpClient httpClient = HttpClients.createDefault();
JSONObject jsonResult = null;
HttpPost httpPost = new HttpPost(url);
httpPost.setConfig(requestConfig);
try {
if (null != strParam) {
// 解决中文乱码问题
StringEntity entity = new StringEntity(strParam, "utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(entity);
}
CloseableHttpResponse result = httpClient.execute(httpPost);
// 请求发送成功,并得到响应
if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String str = "";
try {
// 读取服务器返回过来的json字符串数据
str = EntityUtils.toString(result.getEntity(), "utf-8");
// 把json字符串转换成json对象
jsonResult = JSONObject.parseObject(str);
} catch (Exception e) {
logger.error("post请求提交失败:" + url, e);
}
}
} catch (IOException e) {
logger.error("post请求提交失败:" + url, e);
} finally {
httpPost.releaseConnection();
}
return jsonResult;
}
/**
* get
*
* @param url
* @return
*/
public static JSONObject httpGet(String url) {
// get请求返回结果
JSONObject jsonResult = null;
CloseableHttpClient client = HttpClients.createDefault();
// 发送get请求
HttpGet request = new HttpGet(url);
request.setConfig(requestConfig);
try {
CloseableHttpResponse response = client.execute(request);
// 请求发送成功,并得到响应
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
// 读取服务器返回过来的json字符串数据
HttpEntity entity = response.getEntity();
String strResult = EntityUtils.toString(entity, "utf-8");
// 把json字符串转换成json对象
jsonResult = JSONObject.parseObject(strResult);
} else {
logger.error("get请求提交失败:" + url);
}
} catch (IOException e) {
logger.error("get请求提交失败:" + url, e);
} finally {
request.releaseConnection();
}
return jsonResult;
}
public static String doGet(String url, Map<String, String> param) {
// 创建Httpclient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
String resultString = "";
CloseableHttpResponse response = null;
try {
// 创建uri
URIBuilder builder = new URIBuilder(url);
if (param != null) {
for (String key : param.keySet()) {
builder.addParameter(key, param.get(key));
}
}
URI uri = builder.build();
// 创建http GET请求
HttpGet httpGet = new HttpGet(uri);
// 执行请求
response = httpclient.execute(httpGet);
// 判断返回状态是否为200
if (response.getStatusLine().getStatusCode() == 200) {
resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
public static String doGet(String url) {
return doGet(url, null);
}
public static String doPost(String url,String param) {
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpPost httpPost = new HttpPost(url);
StringEntity requestEntity = new StringEntity(param, ContentType.APPLICATION_JSON);
httpPost.setEntity(requestEntity);
HttpResponse response = httpClient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
String responseBody = EntityUtils.toString(responseEntity);
System.out.println(responseBody);
return responseBody;
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
public static String doPost(String url) {
return doPost(url, null);
}
public static String doPostJson(String url, String json) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建请求内容
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return resultString;
}
}

@ -0,0 +1,32 @@
package com.ann.demo.utils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonUtils {
public static String getValueByKey(String jsonString, String key) {
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(jsonString);
JsonNode valueNode = jsonNode.get(key);
if (valueNode != null) {
return valueNode.asText();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
String jsonString = "{\"name\":\"John\",\"age\":30}";
String name = getValueByKey(jsonString, "name");
int age = Integer.parseInt(getValueByKey(jsonString, "age"));
System.out.println("Name: " + name);
System.out.println("Age: " + age);
}
}

@ -0,0 +1,41 @@
package com.ann.demo.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @author
* @description: XXX
* @createTime 2023/9/5 16:57
*/
public class Md5Utils {
public static String strToMd5(String str) {
String hexString = null;
try {
// 创建MD5消息摘要对象
MessageDigest md = MessageDigest.getInstance("MD5");
// 计算消息的摘要
byte[] digest = md.digest(str.getBytes());
// 将摘要转换为十六进制字符串
hexString = bytesToHex(digest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return hexString;
}
private static String bytesToHex(byte[] bytes) {
StringBuilder hexString = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
}

@ -63,3 +63,25 @@ file:
pdfPath: D:/project_js
server:
port: 8080
#################################################
#登录接口
#子公司代码
siteCode: K0101
#客户代码
customerCode: 44000259-001
#收样点代码
collectionLocation: 44000259-001|001
#loginUrl
loginUrl: https://kmcs.kingmed.com.cn/km-op/cxf/v0.1.0.0/syncInfo2?wsdl
#namespaceURI
namespaceURI: http://com.org.kingmed
#webServiceMethod
webServiceMethod: login
#下载金域外送报告接口
#webServiceDownMethod
webServiceDownMethod: downloadPictureInfo
#调下载接口
downfileUrl: http://192.168.16.85:9292/api/downplatform/report

@ -11,6 +11,8 @@ public class DemoApplicationTests {
@Test
public void contextLoads() {
int i = (int)Math.pow(2,3);
System.out.println(i);
}
}

Loading…
Cancel
Save