|
@ -1,5 +1,6 @@
|
|
|
package com.yihu.jw.utils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
@ -31,7 +32,6 @@ import javax.xml.transform.stream.StreamResult;
|
|
|
import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
@ -318,7 +318,7 @@ public class HttpClientUtil {
|
|
|
//3.1设置发送方式:POST必须大写
|
|
|
connection.setRequestMethod("POST");
|
|
|
//3.2设置数据格式:Content-type
|
|
|
connection.setRequestProperty("content-type", "text/xml;charset=utf-8");
|
|
|
connection.setRequestProperty("content-type", "text/xml;charset=gb2312");
|
|
|
//3.3设置输入输出,新创建的connection默认是没有读写权限的,
|
|
|
connection.setDoInput(true);
|
|
|
connection.setDoOutput(true);
|
|
@ -347,17 +347,6 @@ public class HttpClientUtil {
|
|
|
sb.append(temp);
|
|
|
}
|
|
|
logger.warn("[WebService]:推送结果{}", sb);
|
|
|
/* Map<String, Map> bodyMap = XmlUtils.xm(sb.toString());
|
|
|
Map<String, Map> sendMessageResponseMap = bodyMap.get("Body");
|
|
|
Map<String, String> resultStringMap = sendMessageResponseMap.get("sendMessageResponse");
|
|
|
String stringXML = resultStringMap.get("String");
|
|
|
stringXML = "<root>" + stringXML + "</root>";
|
|
|
Map<String, String> stringMap = XmlUtils.xmlTOMap(stringXML);*/
|
|
|
// String -> <resident>1694505193442</resident><rescode>1</rescode><resmsg>ok</resmsg>
|
|
|
// String -> <resident>1678862927956</resident><rescode>0</rescode><resmsg>数据处理错误!</resmsg>
|
|
|
// 0失败,1成功
|
|
|
/*resultMap.put("code", stringMap.get("rescode"));
|
|
|
resultMap.put("msg", stringMap.get("resmsg"));*/
|
|
|
Map<String, Object> map = XmlUtil.xmlToMap(sb.toString());
|
|
|
Map<String, Map> sendMessageResponseMap = (Map<String, Map>) map.get("Body");
|
|
|
Map<String, String> resultStringMap = sendMessageResponseMap.get("_174HisIntf3Response");
|
|
@ -404,5 +393,127 @@ public class HttpClientUtil {
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
private static String jlUrl = "http://192.0.10.145:8090/api/JLTransApi/JLTransApi";
|
|
|
|
|
|
/**
|
|
|
* 巨浪预约调用方式
|
|
|
*
|
|
|
* @param ACode 功能码
|
|
|
* @param AInParams 请求参数
|
|
|
* @param AType Xml
|
|
|
* @param ASign 空值
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public static JSONObject JLTransApi(String ACode, String AInParams, String AType, String ASign) throws Exception {
|
|
|
JSONObject map = new JSONObject();
|
|
|
map.put("ACode",ACode);
|
|
|
map.put("AParams",AInParams);
|
|
|
map.put("AType",AType);
|
|
|
map.put("ASign",ASign);
|
|
|
String url = jlUrl+"?ACode="+ACode+"&AParams="+AInParams+"&AType="+AType;
|
|
|
String response = com.yihu.jw.util.http.HttpClientUtil.postBody(url,map);
|
|
|
logger.info("请求entrance的参数:"+map.toString());
|
|
|
logger.info("请求JLTransApi:" + response);
|
|
|
String res = response.replace("\\","");
|
|
|
JSONObject result = JSONObject.parseObject(res);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* WebService推送报文封装请求推送
|
|
|
* WebService 接口地址为 http://{ip}:{port}/services/TraderService?wsdl
|
|
|
* @param //webServicePushUrl 为 http://{ip}:{port}/services/TraderService
|
|
|
* @param ACode 接口入参
|
|
|
* @return
|
|
|
*/
|
|
|
public static String webServicePushJm(String ACode,String AInParams,String AType,String ASign) {
|
|
|
logger.info("入参"+ACode+"===="+AInParams);
|
|
|
InputStream is = null;
|
|
|
InputStreamReader isr = null;
|
|
|
BufferedReader br = null;
|
|
|
OutputStream os = null;
|
|
|
String json = null;
|
|
|
try {
|
|
|
//第一步:创建服务地址,不是WSDL地址
|
|
|
URL url = new URL(jlUrl);
|
|
|
//2:打开到服务地址的一个连接
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
//3:设置连接参数
|
|
|
//3.1设置发送方式:POST必须大写
|
|
|
connection.setRequestMethod("POST");
|
|
|
//3.2设置数据格式:Content-type
|
|
|
connection.setRequestProperty("content-type", "text/xml;charset=gb2312");
|
|
|
//3.3设置输入输出,新创建的connection默认是没有读写权限的,
|
|
|
connection.setDoInput(true);
|
|
|
connection.setDoOutput(true);
|
|
|
//4:组织SOAP协议数据,发送给服务端;报文参考SoapUI测试工具的XML请求报文
|
|
|
String soapXML = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
|
|
|
" <soap:Body>\n" +
|
|
|
" <JLTrans xmlns=\"http://tempuri.org/\">\n" +
|
|
|
" <ACode>"+ACode+"</ACode>\n" +
|
|
|
" <AInParams>string</AInParams>\n" +
|
|
|
" <AType>string</AType>\n" +
|
|
|
" <ASign>string</ASign>\n" +
|
|
|
" </JLTrans>\n" +
|
|
|
" </soap:Body>\n" +
|
|
|
"</soap:Envelope>";
|
|
|
logger.warn("[WebService]:推送请求{}", soapXML);
|
|
|
os = connection.getOutputStream();
|
|
|
os.write(soapXML.getBytes());
|
|
|
//5:接收服务端的响应
|
|
|
int responseCode = connection.getResponseCode();
|
|
|
if(200 == responseCode){//表示服务端响应成功
|
|
|
is = connection.getInputStream();
|
|
|
isr = new InputStreamReader(is);
|
|
|
br = new BufferedReader(isr);
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
String temp = null;
|
|
|
while(null != (temp = br.readLine())){
|
|
|
sb.append(temp);
|
|
|
}
|
|
|
logger.warn("[WebService]:推送结果{}", sb);
|
|
|
Map<String, Object> map = XmlUtil.xmlToMap(sb.toString());
|
|
|
Map<String, Map> sendMessageResponseMap = (Map<String, Map>) map.get("Body");
|
|
|
logger.info(sendMessageResponseMap.toString());
|
|
|
json = map.toString();
|
|
|
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error("[WebService]推送异常", e);
|
|
|
} finally {
|
|
|
if (null != is) {
|
|
|
try {
|
|
|
is.close();
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
if (null != isr) {
|
|
|
try {
|
|
|
isr.close();
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
if (null != br) {
|
|
|
try {
|
|
|
br.close();
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
if (null != os) {
|
|
|
try {
|
|
|
os.close();
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
}
|