|
|
@@ -2,11 +2,13 @@ package com.dk.mnls_mp.infrastructure.util;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.dk.mnls_mp.infrastructure.config.ConfigStatic;
|
|
|
import com.dk.mnls_mp.infrastructure.config.HegiiTokenConfig;
|
|
|
import com.dongke.base.exceptionHandler.ResponseCodeEnum;
|
|
|
import com.dongke.base.exceptionHandler.ResponseResultUtil;
|
|
|
import com.dongke.base.exceptionHandler.ResponseResultVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.client.config.RequestConfig;
|
|
|
@@ -26,6 +28,7 @@ import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.SocketTimeoutException;
|
|
|
import java.net.URL;
|
|
|
+import java.nio.charset.Charset;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
@@ -328,4 +331,51 @@ public class HttpHelper {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @desc : 调用iBOSS-webservice接口通过方法
|
|
|
+ * @author : 张潇木
|
|
|
+ * @date : 2022-9-19 16:39
|
|
|
+ */
|
|
|
+ public static ResponseResultVO postMY(String urlInfo, Object param) {
|
|
|
+ HttpURLConnection connection;
|
|
|
+ InputStream is;
|
|
|
+ OutputStream os;
|
|
|
+ BufferedReader br;
|
|
|
+ String result = null;
|
|
|
+ try {
|
|
|
+ log.info("post_url-> " + urlInfo);
|
|
|
+ URL url = new URL(urlInfo);
|
|
|
+ connection = (HttpURLConnection) url.openConnection();
|
|
|
+ connection.setRequestMethod("POST");
|
|
|
+ connection.setConnectTimeout(1000 * 60 * 60 * 2);
|
|
|
+ connection.setReadTimeout(1000 * 60 * 60 * 2);
|
|
|
+ connection.setDoOutput(true);
|
|
|
+ connection.setDoInput(true);
|
|
|
+ connection.setRequestProperty("Content-Type", "application/json");
|
|
|
+ String auth = ConfigStatic.getClientId() + ":" + ConfigStatic.getClientSecret();
|
|
|
+ connection.setRequestProperty("authorization", "Basic "+new String(Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")))));
|
|
|
+
|
|
|
+ os = connection.getOutputStream();
|
|
|
+ os.write(JSONObject.toJSON(param).toString().getBytes("UTF-8"));
|
|
|
+
|
|
|
+ if (connection.getResponseCode() == 200) {
|
|
|
+ is = connection.getInputStream();
|
|
|
+ br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
|
|
+
|
|
|
+ StringBuffer sbf = new StringBuffer();
|
|
|
+ String temp = null;
|
|
|
+ while ((temp = br.readLine()) != null) {
|
|
|
+ sbf.append(temp);
|
|
|
+ sbf.append("\r\n");
|
|
|
+ }
|
|
|
+ result = sbf.toString();
|
|
|
+ return ResponseResultUtil.success(result);
|
|
|
+ }
|
|
|
+ return ResponseResultUtil.error(connection.getResponseCode(), connection.getResponseMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ return ResponseResultUtil.error(-200, "调用美云接口异常,接口地址"+urlInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|