|
@@ -1,9 +1,9 @@
|
|
|
package com.itheima.file;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.itheima.file.util.HTTPHelper;
|
|
|
import com.itheima.file.util.PostMethodUtils;
|
|
|
import com.itheima.file.util.SslUtils;
|
|
|
-import dm.jdbc.filter.stat.json.JSONObject;
|
|
|
import org.apache.hc.client5.http.auth.AuthScope;
|
|
|
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
|
|
|
import org.apache.hc.client5.http.classic.methods.HttpGet;
|
|
@@ -19,14 +19,16 @@ import javax.net.ssl.TrustManager;
|
|
|
import javax.net.ssl.X509TrustManager;
|
|
|
import java.net.URISyntaxException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.Base64;
|
|
|
import java.util.LinkedHashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
// @RunWith(SpringRunner.class)
|
|
|
// @SpringBootTest
|
|
|
public class ApiTestData {
|
|
|
|
|
|
- public static void main(final String[] args) throws Exception {
|
|
|
+ public static void main111(final String[] args) throws Exception {
|
|
|
// 忽略SSL证书验证的TrustManager
|
|
|
TrustManager[] trustAllCerts = new TrustManager[] {
|
|
|
new X509TrustManager() {
|
|
@@ -129,7 +131,7 @@ public class ApiTestData {
|
|
|
* @param args
|
|
|
* @throws URISyntaxException
|
|
|
*/
|
|
|
- public static void main401(String[] args) throws URISyntaxException {
|
|
|
+ public static void main44(String[] args) throws URISyntaxException {
|
|
|
// 设置Basic Authentication的凭证(用户名和密码)
|
|
|
String username = "po_soap1";
|
|
|
String password = "z123456789";
|
|
@@ -177,18 +179,80 @@ public class ApiTestData {
|
|
|
return "Basic " + base64Auth;
|
|
|
}
|
|
|
|
|
|
- public static void main11(String[] args) {
|
|
|
+ public static void main(String[] args) {
|
|
|
JSONObject reqBodyObj = new JSONObject();
|
|
|
reqBodyObj.put("app_id", "hcmcloud");
|
|
|
reqBodyObj.put("table_name", "");
|
|
|
reqBodyObj.put("stringDate", "20210301");
|
|
|
reqBodyObj.put("condition", "1=1");
|
|
|
reqBodyObj.put("secretKey", "f3ac852124d2f991a3f63f2e33dae18b");
|
|
|
+ String string = reqBodyObj.toString();
|
|
|
String username = "po_soap1";
|
|
|
String password = "z123456789";
|
|
|
String postUrl = "https://podev.minmetals.com.cn:50001/RESTAdapter/BS_OA/BS_MDM/DeleteAssHrtree";
|
|
|
- String s = PostMethodUtils.sendPost(postUrl, reqBodyObj.toString(), username, password);
|
|
|
+ String s = PostMethodUtils.sendPost(postUrl, string, username, password);
|
|
|
System.out.println(s);
|
|
|
}
|
|
|
|
|
|
+ public static void main0(String[] args) throws Exception {
|
|
|
+ String contentType = "application/pdf";
|
|
|
+ JSONObject reqBodyObj = new JSONObject();
|
|
|
+ reqBodyObj.put("contentMd5", "contentMD5");
|
|
|
+ reqBodyObj.put("contentType", contentType);
|
|
|
+ reqBodyObj.put("convertToPDF", true);
|
|
|
+ reqBodyObj.put("fileName", "最终版授权声明.docx");
|
|
|
+ reqBodyObj.put("fileSize", "123");
|
|
|
+ // 请求Body体数据
|
|
|
+ String reqBodyData = reqBodyObj.toString();
|
|
|
+ // 对请求Body体内的数据计算ContentMD5
|
|
|
+ String contentMD5 = "ESignUtils.getBodyContentMD5(reqBodyData";
|
|
|
+ System.out.println("请求body数据:" + reqBodyData);
|
|
|
+ System.out.println("body的md5值:" + contentMD5);
|
|
|
+
|
|
|
+ // 构建待签名字符串
|
|
|
+ String method = "POST";
|
|
|
+ String accept = "*/*";
|
|
|
+ String contentType1 = "application/json; charset=UTF-8";
|
|
|
+ String date = "";
|
|
|
+ String headers = "";
|
|
|
+ String postUrl = "/v3/files/file-upload-url";
|
|
|
+
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ sb.append(method).append("\n").append(accept).append("\n").append(contentMD5).append("\n")
|
|
|
+ .append(contentType1).append("\n").append(date).append("\n");
|
|
|
+ if ("".equals(headers)) {
|
|
|
+ sb.append(headers).append(postUrl);
|
|
|
+ } else {
|
|
|
+ sb.append(headers).append("\n").append(postUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建参与请求签名计算的明文
|
|
|
+ // String plaintext = sb.toString();
|
|
|
+ // 计算请求签名值
|
|
|
+ String reqSignature = "ESignUtils.doSignatureBase64(plaintext, appSecret)";
|
|
|
+ System.out.println("计算请求签名值:" + reqSignature);
|
|
|
+
|
|
|
+ // 获取时间戳(精确到毫秒)
|
|
|
+ long timeStamp = System.currentTimeMillis();;
|
|
|
+
|
|
|
+ // 构建请求头
|
|
|
+ LinkedHashMap<String, String> header = new LinkedHashMap<String, String>();
|
|
|
+ header.put("X-Tsign-Open-App-Id", "appId");
|
|
|
+ header.put("X-Tsign-Open-Auth-Mode", "Signature");
|
|
|
+ header.put("X-Tsign-Open-Ca-Timestamp", String.valueOf(timeStamp));
|
|
|
+ header.put("Accept", accept);
|
|
|
+ header.put("Content-Type", contentType);
|
|
|
+ header.put("X-Tsign-Open-Ca-Signature", reqSignature);
|
|
|
+ header.put("Content-MD5", contentMD5);
|
|
|
+ System.out.println("header" + header);
|
|
|
+
|
|
|
+ String postAllUrl = "https://smlopenapi.esign.cn" + postUrl;
|
|
|
+ String result = HTTPHelper.sendPOST(postAllUrl, reqBodyData, header, "UTF-8");
|
|
|
+ JSONObject resultObj = JSONObject.parseObject(result);
|
|
|
+ // json转map
|
|
|
+ Map<String, Object> resultMap = (Map<String, Object>) JSONObject.toJavaObject(resultObj, Map.class);
|
|
|
+ System.out.println("请求返回信息: " + resultObj.toString());
|
|
|
+ System.out.println("请求返回信息: " + resultMap.toString());
|
|
|
+ }
|
|
|
+
|
|
|
}
|