2025-05-15 15:01:29 +08:00
|
|
|
|
package nccloud.pubift.commen.impl.utils;
|
2025-05-15 11:00:51 +08:00
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
2025-05-15 15:01:29 +08:00
|
|
|
|
import nccloud.pubift.commen.itf.utils.IHttpPostOtherSys;
|
2025-05-15 11:00:51 +08:00
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
2025-05-15 12:17:42 +08:00
|
|
|
|
import java.io.IOException;
|
2025-05-15 11:00:51 +08:00
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.HashMap;
|
2025-05-15 12:17:42 +08:00
|
|
|
|
import java.util.List;
|
2025-05-15 11:00:51 +08:00
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public class HttpPostOtherSysImpl implements IHttpPostOtherSys {
|
|
|
|
|
|
2025-05-15 12:17:42 +08:00
|
|
|
|
private static final String USER_ID = "BIP";
|
|
|
|
|
private static final String PASSWORD = "BIP@2025bip";
|
|
|
|
|
private static final String CLIENT_TYPE = "S";
|
|
|
|
|
private static final String EP_ID = "";
|
|
|
|
|
private static final String LOGIN_URL = "/GTHINKING/AjaxService/N_MISPRO/100208057.ashx/Login";
|
|
|
|
|
|
2025-05-15 11:00:51 +08:00
|
|
|
|
@Override
|
|
|
|
|
public String callLE(String url, JSONObject json) {
|
2025-05-15 12:17:42 +08:00
|
|
|
|
// String leip = SysParaInitQuery.getParaString(PubEnv.getPk_group(), "LEIP");
|
|
|
|
|
String mesip = "http://192.168.29.32";
|
|
|
|
|
String baseurl = mesip + url;
|
|
|
|
|
String cookie = this.getMESToken(mesip);
|
2025-05-15 11:00:51 +08:00
|
|
|
|
Map<String, String> headers = new HashMap<>();
|
2025-05-15 12:17:42 +08:00
|
|
|
|
headers.put("Set-Cookie", cookie);
|
|
|
|
|
return doPost(baseurl, headers, json);
|
2025-05-15 11:00:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-15 12:17:42 +08:00
|
|
|
|
private String getMESToken(String leip) {
|
2025-05-15 11:00:51 +08:00
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
2025-05-15 12:17:42 +08:00
|
|
|
|
jsonObject.put("userId", USER_ID);
|
|
|
|
|
jsonObject.put("password", PASSWORD);
|
|
|
|
|
jsonObject.put("clientType", CLIENT_TYPE);
|
|
|
|
|
jsonObject.put("epId", EP_ID);
|
|
|
|
|
return postCookie(leip + LOGIN_URL, null, jsonObject);
|
2025-05-15 11:00:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-15 12:17:42 +08:00
|
|
|
|
/**
|
|
|
|
|
* ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>post<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
2025-05-15 11:00:51 +08:00
|
|
|
|
private String doPost(String baseurl, Map<String, String> map, JSONObject json) {
|
|
|
|
|
BufferedReader reader = null;
|
|
|
|
|
try {
|
|
|
|
|
URL url = new URL(baseurl);// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
|
connection.setDoInput(true);
|
|
|
|
|
connection.setUseCaches(false);
|
|
|
|
|
connection.setInstanceFollowRedirects(true);
|
|
|
|
|
connection.setRequestMethod("POST"); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
|
|
|
|
|
// <20><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĸ<DDB5>ʽ
|
|
|
|
|
connection.setRequestProperty("Content-Type", "application/json"); // <20><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĸ<DDB5>ʽ
|
|
|
|
|
if (map != null) {
|
|
|
|
|
for (String key : map.keySet()) {
|
|
|
|
|
connection.setRequestProperty(key, map.get(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
connection.connect();
|
|
|
|
|
// һ<><D2BB>Ҫ<EFBFBD><D2AA>BufferedReader <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6> ʹ<><CAB9><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD>ǽ<EFBFBD><C7BD>ղ<EFBFBD><D5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>
|
|
|
|
|
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); // UTF-8<><38><EFBFBD><EFBFBD>
|
|
|
|
|
if (json != null) {
|
|
|
|
|
out.append(json.toString());
|
|
|
|
|
}
|
|
|
|
|
out.flush();
|
|
|
|
|
out.close();
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>Ӧ
|
|
|
|
|
reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
|
|
|
|
String line;
|
|
|
|
|
String res = "";
|
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
|
res += line;
|
|
|
|
|
}
|
|
|
|
|
reader.close();
|
|
|
|
|
return res;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-15 12:17:42 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD>ȡcookie<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>post
|
|
|
|
|
*/
|
|
|
|
|
private String postCookie(String baseurl, Map<String, String> map, JSONObject json) {
|
|
|
|
|
BufferedReader reader = null;
|
|
|
|
|
try {
|
|
|
|
|
URL url = new URL(baseurl);
|
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
|
connection.setDoInput(true);
|
|
|
|
|
connection.setUseCaches(false);
|
|
|
|
|
connection.setInstanceFollowRedirects(true);
|
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
|
connection.setRequestProperty("Content-Type", "application/json");
|
|
|
|
|
|
|
|
|
|
if (map != null) {
|
|
|
|
|
for (String key : map.keySet()) {
|
|
|
|
|
connection.setRequestProperty(key, map.get(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connection.connect();
|
|
|
|
|
|
|
|
|
|
// д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
|
|
|
|
|
if (json != null) {
|
|
|
|
|
out.append(json.toString());
|
|
|
|
|
}
|
|
|
|
|
out.flush();
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1>Ӧͷ<D3A6>е<EFBFBD> Set-Cookie
|
|
|
|
|
Map<String, List<String>> headers = connection.getHeaderFields();
|
|
|
|
|
String setCookieHeader = null;
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
|
|
|
|
if ("Set-Cookie".equalsIgnoreCase(entry.getKey())) {
|
|
|
|
|
setCookieHeader = entry.getValue().get(0); // ȡ<><C8A1>һ<EFBFBD><D2BB> Set-Cookie ͷ
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (setCookieHeader != null) {
|
|
|
|
|
return extractAspxAuth(setCookieHeader); // <20><><EFBFBD><EFBFBD> ASPXAUTH <20><>ֵ
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} finally {
|
|
|
|
|
if (reader != null) {
|
|
|
|
|
try {
|
|
|
|
|
reader.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ .ASPXAUTH <20><>ֵ
|
|
|
|
|
private String extractAspxAuth(String cookieHeader) {
|
|
|
|
|
String[] cookies = cookieHeader.split("; ");
|
|
|
|
|
for (String cookie : cookies) {
|
|
|
|
|
if (cookie.startsWith(".ASPXAUTH=")) {
|
|
|
|
|
return cookie.substring(".ASPXAUTH=".length());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2025-05-15 11:00:51 +08:00
|
|
|
|
}
|