Ecology-Dev-chaofa/盛虹化纤/interface/shhq/tb006.jsp

154 lines
5.8 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="weaver.general.*,java.util.*,java.math.*" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="org.apache.http.impl.client.*" %>
<%@ page import="org.apache.http.impl.client.CloseableHttpClient" %>
<%@ page import="org.apache.http.client.methods.HttpPost" %>
<%@ page import="org.apache.http.client.methods.CloseableHttpResponse" %>
<%@ page import="org.apache.http.message.BasicHeader" %>
<%@ page import="cn.hutool.core.codec.Base64" %>
<%@ page import="org.apache.http.entity.*" %>
<%@ page import="java.nio.charset.Charset" %>
<%@ page import="org.apache.http.HttpEntity" %>
<%@ page import="org.apache.http.util.EntityUtils" %>
<%@ page import="java.io.IOException" %>
<%
int sum = 0;
String url = "http://poqassrv.shenghongtec.com:50000/XISOAPAdapter/MessageServlet?senderParty=&senderService=SH_BPM_QAS&receiverParty=&receiverService=&interface=CommonInter_Info_SYN_OUT&interfaceNamespace=urn:shenghong:bpm:s4";
//
String val = "[{\"company_name\": \"江苏国望高科纤维有限公司\",\"pernr\":\"87011999\",\"name\":\"李四\",\"id_card\":\"14052419761114803Z\",\"birthday\":\"19961011\",\"sex\":\"男\",\"address\":\"云南省德宏傣族景颇族自治州梁河县曩宋乡芒东村民委员会大地组 \",\"phone\":\"13988226825\"}]";
// 同步工号的入参
// <VALUE>[{"company_name": "江苏国望高科纤维有限公司","pernr":"87011888","name":"张三","id_card":"14052419761114803Z","birthday":"19961011","sex":"男","address":"云南省德宏傣族景颇族自治州梁河县曩宋乡芒东村民委员会大地组 ","phone":"13988226825"}]</VALUE>
String action = "SSQ_PMINFO";
//SSQ_PMINFO
//SSQ_EMPINFO
String xml ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:shenghong:bpm:s4\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <urn:CommonInter_Info>\n" +
" <ACTION>"+action+"</ACTION>\n" +
" <VALUE>"+val+"</VALUE>\n" +
" </urn:CommonInter_Info>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
String usr_pwd = "po_sender:posender0807" ;
String soapAction = "";
String msgMap = doPostSoap(url,xml,soapAction,usr_pwd);
sum++;
%>
<%!
public String doPostSoap(String url, String soapXml, String soapAction, String userpass) throws Exception
{
Map<String,String> msgMap = new HashMap<String,String>();
System.out.println("url:"+url);
System.out.println("soapXml:"+soapXml);
System.out.println("soapAction:"+soapAction);
System.out.println("userpass:"+userpass);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
HttpPost httpPost = new HttpPost(url);
//设置请求和传输超时时间
String result = "";
CloseableHttpResponse response = null;
try {
httpPost.setHeader("Content-Type", "text/xml;charset=UTF-8");
httpPost.setHeader("SOAPAction", soapAction);
httpPost.addHeader(new BasicHeader("Authorization", "Basic " + new String(Base64.encode(userpass.getBytes()))));
StringEntity data = new StringEntity(soapXml, Charset.forName("UTF-8"));
System.out.println("data:"+data.toString());
httpPost.setEntity(data);
response = closeableHttpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
if (httpEntity != null)
{
String result1 = EntityUtils.toString(httpEntity, "UTF-8");
System.out.println("111 result1:"+result1);
if(!"".equals(result1))
{
result1 = result1.replace("&lt;","<").replace("&gt;",">");
System.out.println("222 result1:"+result1);
msgMap.put("result",result);
result = getValue(result1,"ISSUCCESS");
}else{
msgMap.put("code","-100");
msgMap.put("sqlcode","-100");
msgMap.put("description","ERP接口返回值为空");
}
}else{
msgMap.put("code","-200");
msgMap.put("sqlcode","-200");
msgMap.put("description","ERP接口返回值为空");
}
} catch (Exception e)
{
e.printStackTrace();
System.out.println("e"+e);
msgMap.put("code","-200");
msgMap.put("sqlcode","-200");
msgMap.put("description","ERP接口调用异常:"+e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
e.printStackTrace();
}
}
}
System.out.println("333 result:"+result);
return result;
}
public static String getValue(String xml,String name){
String value = "";
String begin = "<"+name+">";
String end = "</"+name+">";
if(xml.contains(name)){
value = xml.substring(
xml.indexOf(begin) ,
xml.indexOf(end)+ end.length());
if(value!=null && !"".equals(value)){
value = value.substring(value.indexOf(">")+1,value.indexOf("</"));
}
}
return value;
}
%>
<HEAD>
</HEAD>
<BODY>
<h1>Congratulation Mode 666666 !</h1>
<h1> 同步工号的 </h1>
<h1> 返回结果 <%=msgMap%></h1>
<h1> sum <%=sum%> </h1>
</BODY>