wzy преди 2 месеца
родител
ревизия
6ceb9f6de2

+ 68 - 0
mjava-boyang/pom.xml

@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.2.0.RELEASE</version> <!-- 使用最新的稳定版或其他适用版本 -->
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+
+    <groupId>com.malk.boyang</groupId>
+    <artifactId>mjava-boyang</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.malk</groupId>
+            <artifactId>base</artifactId>
+            <version>1.1-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <finalName>boyang</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.1</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                    <encoding>UTF-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <executable>true</executable>
+                    <includeSystemScope>true</includeSystemScope>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 4 - 6
mjava-jiangshi/src/main/java/com/malk/jiangshi/JiangshiApplication.java

@@ -1,17 +1,15 @@
-package com.malk.jiangshi;
+package com.malk.boyang;
 
-import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
-@SpringBootApplication
+@SpringBootApplication(scanBasePackages = {"com.malk"})
 @EnableScheduling
-@MapperScan("com.malk.jiangshi.mapper")
-public class JiangshiApplication {
+public class BoyangApplication {
     public static void main(String[] args) {
         try {
-            SpringApplication.run(JiangshiApplication.class,args);
+            SpringApplication.run(BoyangApplication.class,args);
         }catch (Exception e){
             e.printStackTrace();
         }

+ 403 - 0
mjava-boyang/src/main/java/com/malk/boyang/utils/HTTPHelper.java

@@ -0,0 +1,403 @@
+package com.malk.boyang.utils;
+
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.UnknownHostException;
+import java.text.MessageFormat;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HTTPHelper {
+    // slf4j日志记录器
+    private static final Logger LOG = LoggerFactory.getLogger(HTTPHelper.class);
+    // 结尾符
+    private static final String LINE_FEED = "\r\n";
+
+    /***
+     * 向指定URL发送GET方法的请求
+     *
+     * @param apiUrl
+     * @param data
+     * @param projectId
+     * @param signature
+     * @param encoding
+     * @return
+     * @throws Exception
+     */
+    public static String sendGet(String apiUrl, LinkedHashMap<String, String> headers,
+                                 String encoding) throws Exception {
+        // 获得响应内容
+        String http_RespContent = null;
+        HttpURLConnection httpURLConnection = null;
+        int http_StatusCode = 0;
+        String http_RespMessage = null;
+        try {
+            LOG.info(">>>> 实际请求Url: " + apiUrl);
+
+            // 建立连接
+            URL url = new URL(apiUrl);
+            httpURLConnection = (HttpURLConnection) url.openConnection();
+            // 需要输出
+            httpURLConnection.setDoOutput(true);
+            // 需要输入
+            httpURLConnection.setDoInput(true);
+            // 不允许缓存
+            httpURLConnection.setUseCaches(false);
+            // HTTP请求方式
+            httpURLConnection.setRequestMethod("GET");
+            // 设置Headers
+            if (null != headers) {
+                for (String key : headers.keySet()) {
+                    httpURLConnection.setRequestProperty(key, headers.get(key));
+                }
+            }
+            // 连接会话
+            httpURLConnection.connect();
+            // 获得响应状态(HTTP状态码)
+            http_StatusCode = httpURLConnection.getResponseCode();
+            // 获得响应消息(HTTP状态码描述)
+            http_RespMessage = httpURLConnection.getResponseMessage();
+            // 获得响应内容
+            if (HttpURLConnection.HTTP_OK == http_StatusCode) {
+                // 返回响应结果
+                http_RespContent = getResponseContent(httpURLConnection);
+            } else {
+                // 返回非200状态时响应结果
+                http_RespContent = getErrorResponseContent(httpURLConnection);
+                String msg =
+                        MessageFormat.format("请求失败: Http状态码 = {0} , {1}", http_StatusCode, http_RespMessage);
+                LOG.info(msg);
+            }
+        } catch (UnknownHostException e) {
+            String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } catch (MalformedURLException e) {
+            String message = MessageFormat.format("格式错误的URL: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } catch (IOException e) {
+            String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } catch (Exception e) {
+            String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } finally {
+            if (null != httpURLConnection) {
+                httpURLConnection.disconnect();
+            }
+        }
+        return http_RespContent;
+    }
+
+    /***
+     * 向指定URL发送POST方法的请求
+     *
+     * @param apiUrl
+     * @param data
+     * @param encoding
+     * @return
+     * @throws Exception
+     */
+    public static String sendPOST(String apiUrl, String data, LinkedHashMap<String, String> headers,
+                                  String encoding) throws Exception {
+        // 获得响应内容
+        String http_RespContent = null;
+        HttpURLConnection httpURLConnection = null;
+        int http_StatusCode = 0;
+        String http_RespMessage = null;
+        try {
+            // 建立连接
+            URL url = new URL(apiUrl);
+            httpURLConnection = (HttpURLConnection) url.openConnection();
+            // 需要输出
+            httpURLConnection.setDoOutput(true);
+            // 需要输入
+            httpURLConnection.setDoInput(true);
+            // 不允许缓存
+            httpURLConnection.setUseCaches(false);
+            // HTTP请求方式
+            httpURLConnection.setRequestMethod("POST");
+            // 设置Headers
+            if (null != headers) {
+                for (String key : headers.keySet()) {
+                    httpURLConnection.setRequestProperty(key, headers.get(key));
+                }
+            }
+            // 连接会话
+            httpURLConnection.connect();
+            // 建立输入流,向指向的URL传入参数
+            DataOutputStream dos = new DataOutputStream(httpURLConnection.getOutputStream());
+            // 设置请求参数
+            dos.write(data.getBytes(encoding));
+            dos.flush();
+            dos.close();
+            // 获得响应状态(HTTP状态码)
+            http_StatusCode = httpURLConnection.getResponseCode();
+            // 获得响应消息(HTTP状态码描述)
+            http_RespMessage = httpURLConnection.getResponseMessage();
+            // 获得响应内容
+            if (HttpURLConnection.HTTP_OK == http_StatusCode) {
+                // 返回响应结果
+                http_RespContent = getResponseContent(httpURLConnection);
+            } else {
+                // 返回非200状态时响应结果
+                http_RespContent = getErrorResponseContent(httpURLConnection);
+                String msg =
+                        MessageFormat.format("请求失败: Http状态码 = {0} , {1}", http_StatusCode, http_RespMessage);
+                LOG.info(msg);
+            }
+        } catch (UnknownHostException e) {
+            String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } catch (MalformedURLException e) {
+            String message = MessageFormat.format("格式错误的URL: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } catch (IOException e) {
+            String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } catch (Exception e) {
+            String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } finally {
+            if (null != httpURLConnection) {
+                httpURLConnection.disconnect();
+            }
+        }
+        return http_RespContent;
+    }
+
+    /***
+     * 读取HttpResponse响应内容
+     *
+     * @param httpURLConnection
+     * @return
+     * @throws UnsupportedEncodingException
+     * @throws IOException
+     */
+    private static String getResponseContent(HttpURLConnection httpURLConnection)
+            throws UnsupportedEncodingException, IOException {
+        StringBuffer contentBuffer = null;
+        BufferedReader responseReader = null;
+        try {
+            contentBuffer = new StringBuffer();
+            String readLine = null;
+            responseReader =
+                    new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(), "UTF-8"));
+            while ((readLine = responseReader.readLine()) != null) {
+                contentBuffer.append(readLine);
+            }
+        } finally {
+            if (null != responseReader) {
+                responseReader.close();
+            }
+        }
+        return contentBuffer.toString();
+    }
+
+    /***
+     * 读取HttpResponse响应内容
+     *
+     * @param httpURLConnection
+     * @return
+     * @throws UnsupportedEncodingException
+     * @throws IOException
+     */
+    private static String getErrorResponseContent(HttpURLConnection httpURLConnection)
+            throws UnsupportedEncodingException, IOException {
+        StringBuffer contentBuffer = null;
+        BufferedReader responseReader = null;
+        try {
+            contentBuffer = new StringBuffer();
+            String readLine = null;
+            responseReader =
+                    new BufferedReader(new InputStreamReader(httpURLConnection.getErrorStream(), "UTF-8"));
+            while ((readLine = responseReader.readLine()) != null) {
+                contentBuffer.append(readLine);
+            }
+        } finally {
+            if (null != responseReader) {
+                responseReader.close();
+            }
+        }
+        return contentBuffer.toString();
+    }
+
+    /***
+     * 上传文件
+     *
+     * @param apiUrl 请求url
+     * @param fileFieldName 文件在请求体中的field名字
+     * @param filePath 文件路径
+     * @param data 请求体
+     * @param headers headers
+     * @param encoding 编码格式
+     * @return
+     * @throws Exception
+     */
+    public static String uploadFile(String apiUrl, String fileFieldName, String filePath, Map<String, Object> data,
+                                    LinkedHashMap<String, String> headers, String encoding) throws Exception {
+        // 获得响应内容
+        String http_RespContent;
+        HttpURLConnection httpURLConnection = null;
+        int http_StatusCode = 0;
+        String http_RespMessage;
+        try {
+            String boundary = "---" + System.currentTimeMillis() + "---";
+            httpURLConnection = (HttpURLConnection) new URL(apiUrl).openConnection();
+            // 设置为POST情
+            httpURLConnection.setRequestMethod("POST");
+            // 发送POST请求必须设置如下两行
+            httpURLConnection.setDoOutput(true);
+            httpURLConnection.setDoInput(true);
+            httpURLConnection.setUseCaches(false);
+            // 设置请求头参数
+            // 设置Headers
+            if (null != headers) {
+                for (String key : headers.keySet()) {
+                    httpURLConnection.setRequestProperty(key, headers.get(key));
+                }
+            }
+            httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
+
+            OutputStream outputStream = httpURLConnection.getOutputStream();
+            PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, encoding),
+                    true);
+            if (data != null && data.size() != 0) {
+                Set<Entry<String, Object>> entries = data.entrySet();
+                for (Entry<String, Object> entry : entries) {
+                    if (entry.getValue() != null) {
+                        addFormField(writer, boundary, "UTF-8", entry.getKey(), entry.getValue().toString());
+                    }
+                }
+            }
+
+            addFilePart(writer, outputStream, boundary, fileFieldName, new File(filePath));
+            writer.println("--" + boundary + "--");
+            writer.close();
+            // 获得响应状态(HTTP状态码)
+            http_StatusCode = httpURLConnection.getResponseCode();
+            // 获得响应消息(HTTP状态码描述)
+            http_RespMessage = httpURLConnection.getResponseMessage();
+            // 获得响应内容
+            if (HttpURLConnection.HTTP_OK == http_StatusCode) {
+                // 返回响应结果
+                http_RespContent = getResponseContent(httpURLConnection);
+            } else {
+                // 返回非200状态时响应结果
+                http_RespContent = getErrorResponseContent(httpURLConnection);
+                String msg =
+                        MessageFormat.format("请求失败: Http状态码 = {0} , {1}", http_StatusCode, http_RespMessage);
+                LOG.info(msg);
+            }
+        } catch (UnknownHostException e) {
+            String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } catch (MalformedURLException e) {
+            String message = MessageFormat.format("格式错误的URL: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } catch (IOException e) {
+            String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } catch (Exception e) {
+            String message = MessageFormat.format("网络请求时发生异常: {0}", e.getMessage());
+            Exception ex = new Exception(message);
+            ex.initCause(e);
+            throw ex;
+        } finally {
+            if (null != httpURLConnection) {
+                httpURLConnection.disconnect();
+            }
+        }
+        return http_RespContent;
+    }
+
+    /**
+     * 添加请求体的key和value
+     *
+     * @param name  field name
+     * @param value field value
+     */
+    public static void addFormField(PrintWriter writer,  String boundary, String charset, String name, String value) {
+        writer.append("--" + boundary).append(LINE_FEED);
+        writer.append("Content-Disposition: form-data; name=\"" + name + "\"")
+                .append(LINE_FEED);
+        writer.append("Content-Type: text/plain; charset=" + charset).append(
+                LINE_FEED);
+        writer.append(LINE_FEED);
+        writer.append(value).append(LINE_FEED);
+        writer.flush();
+    }
+
+    /**
+     * 添加文件到请求中
+     *
+     * @param fieldName  field名字
+     * @param uploadFile 要上传的文件
+     * @throws IOException
+     */
+    public static void addFilePart(PrintWriter writer, OutputStream outputStream, String boundary,
+                                   String fieldName, File uploadFile)
+            throws IOException {
+        String fileName = uploadFile.getName();
+        writer.append("--" + boundary).append(LINE_FEED);
+        writer.append(
+                        "Content-Disposition: form-data; name=\"" + fieldName
+                                + "\"; filename=\"" + fileName + "\"")
+                .append(LINE_FEED);
+        writer.append(
+                        "Content-Type: "
+                                + URLConnection.guessContentTypeFromName(fileName))
+                .append(LINE_FEED);
+        writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED);
+        writer.append(LINE_FEED);
+        writer.flush();
+
+        FileInputStream inputStream = new FileInputStream(uploadFile);
+        byte[] buffer = new byte[4096];
+        int bytesRead = -1;
+        while ((bytesRead = inputStream.read(buffer)) != -1) {
+            outputStream.write(buffer, 0, bytesRead);
+        }
+        outputStream.flush();
+        inputStream.close();
+        writer.append(LINE_FEED);
+        writer.flush();
+    }
+}

+ 28 - 0
mjava-boyang/src/main/resources/application-dev.yml

@@ -0,0 +1,28 @@
+#测试学习
+server:
+  port: 9033
+  servlet:
+    context-path: /boyang
+
+enable:
+  scheduling: false
+logging:
+  config: classpath:logback-spring.xml
+  path: /home/server/lianxiang/log/
+  level:
+    com.malk.*: debug
+
+# dingtalk
+dingtalk:
+  agentId: 3749205961
+  appKey: dingdcxnvojhmwi1lau0
+  appSecret: K0dfunjkLVQKzEN6KXbjdUxcVAX5_hyc0rTNzrj4MugXKc-dkn0erpAxzhSeGPVC
+  corpId:
+  aesKey:
+  token:
+  operator: 344749020127590108
+
+aliwork:
+  appType: APP_TTZS5KICGVVQNZ3RS8T4
+  systemToken: DWF66OA1K1VTVWET83C0SD6RULBO31AQEYG8MQO
+

+ 28 - 0
mjava-boyang/src/main/resources/application-prod.yml

@@ -0,0 +1,28 @@
+#测试学习
+server:
+  port: 9033
+  servlet:
+    context-path: /boyang
+
+enable:
+  scheduling: false
+logging:
+  config: classpath:logback-spring.xml
+  path: /home/server/lianxiang/log/
+  level:
+    com.malk.*: info
+
+# dingtalk
+dingtalk:
+  agentId: 3749205961
+  appKey: dingdcxnvojhmwi1lau0
+  appSecret: K0dfunjkLVQKzEN6KXbjdUxcVAX5_hyc0rTNzrj4MugXKc-dkn0erpAxzhSeGPVC
+  corpId:
+  aesKey:
+  token:
+  operator: 344749020127590108
+
+aliwork:
+  appType: APP_TTZS5KICGVVQNZ3RS8T4
+  systemToken: DWF66OA1K1VTVWET83C0SD6RULBO31AQEYG8MQO
+

mjava-jiangshi/src/main/resources/application.yml → mjava-boyang/src/main/resources/application.yml


mjava-jiangshi/src/main/resources/logback-spring.xml → mjava-boyang/src/main/resources/logback-spring.xml


+ 184 - 0
mjava-boyang/src/test/java/com/malk/boyang/Test.java

@@ -0,0 +1,184 @@
+package com.malk.boyang;
+
+import com.alibaba.fastjson.JSONObject;
+import java.text.MessageFormat;
+import java.util.LinkedHashMap;
+
+import com.malk.boyang.utils.HTTPHelper;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.codec.digest.HmacAlgorithms;
+import org.apache.commons.codec.digest.HmacUtils;
+
+public class Test {
+    public static void main(String[] args) {
+        // 应用ID
+        String projectId = "1000004";
+        // 应用密钥
+        String secret = "96Uh7CR83NkN3TA6";
+        // 接口调用域名
+        String host = "http://122.227.225.202:9011/";
+
+        // 请求签名鉴权-POST请求
+        testPost(projectId, secret, host);
+
+        // 请求签名鉴权-GET请求
+//        testGet(projectId, secret, host);
+
+        // 请求签名鉴权-POST请求-文件上传
+//        testUpload(projectId, secret, host);
+    }
+
+    /***
+     * 请求签名鉴权-POST请求
+     *
+     * @param projectId 项目Id
+     * @param secret 项目密钥
+     * @param host 网关地址
+     */
+    public static void testPost(String projectId, String secret, String host) {
+        // 查询查询内部组织详情地址
+        String getInnerOrganizationsDetailApi = "/manage/v1/innerOrganizations/detail";
+        // 查询查询内部组织详情请求地址
+        String getInnerOrganizationsDetailApiUrl = host + getInnerOrganizationsDetailApi;
+
+        try {
+            // 构建请求Body体
+            JSONObject reqBodyObj = new JSONObject(true);
+            reqBodyObj.put("organizationCode", "");
+            reqBodyObj.put("customOrgNo", "");
+            reqBodyObj.put("name", "博洋");
+
+            // 请求Body体数据
+            String reqBodyData = reqBodyObj.toString();
+            // 对请求Body体内的数据计算ContentMD5
+
+            // 构建参与请求签名计算的明文
+            String plaintext = reqBodyData;
+            // 计算请求签名值
+            String reqSignature = sign(plaintext, secret);
+
+            // 构建请求头
+            LinkedHashMap<String, String> header = new LinkedHashMap<>();
+            // 构建待签名字符串
+            String accept = "*/*";
+            String contentType = "application/json; charset=UTF-8";
+            header.put("X-timevale-project-id", projectId);
+            header.put("X-timevale-signature", reqSignature);
+            header.put("Accept", accept);
+            header.put("Content-Type", contentType);
+
+            // 发送POST请求
+            String result = HTTPHelper.sendPOST(getInnerOrganizationsDetailApiUrl, reqBodyData, header, "UTF-8");
+            JSONObject resultObj = JSONObject.parseObject(result);
+            System.out.println("请求返回信息: " + resultObj.toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+            String msg = MessageFormat.format("请求签名鉴权方式调用接口出现异常: {0}", e.getMessage());
+            System.out.println(msg);
+        }
+    }
+
+    /***
+     * 请求签名鉴权-GET请求
+     *
+     * @param projectId 项目id
+     * @param secret 项目密钥
+     * @param host 网关地址
+     */
+    public static void testGet(String projectId, String secret, String host) {
+        // 获取签署地址列表API地址
+        String getSignFlowApi = "/esign-signs/v1/signFlow/signUrls?signFlowId=" + "24210df8420968c1e785a3b7582295b6";
+        // 获取签署地址列表接口请求地址
+        String hostGetSignFlowApi = host + getSignFlowApi;
+
+        try {
+            // 构建待签名字符串
+            String accept = "*/*";
+            String contentType = "application/json; charset=UTF-8";
+
+            // 构建参与请求签名计算的明文
+            int index = getSignFlowApi.indexOf("?");
+            String plaintext = index == -1 ? "" : getSignFlowApi.substring(index + 1);
+            // 计算请求签名值
+            String reqSignature = sign(plaintext, secret);
+
+            // 构建请求头
+            LinkedHashMap<String, String> header = new LinkedHashMap<>();
+            header.put("X-timevale-project-id", projectId);
+            header.put("X-timevale-signature", reqSignature);
+            header.put("Accept", accept);
+            header.put("Content-Type", contentType);
+
+            // 发送GET请求
+            String result = HTTPHelper.sendGet(hostGetSignFlowApi, header, "UTF-8");
+            JSONObject resultObj = JSONObject.parseObject(result);
+            System.out.println("请求返回信息: " + resultObj.toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+            String msg = MessageFormat.format("请求签名鉴权方式调用接口出现异常: {0}", e.getMessage());
+            System.out.println(msg);
+        }
+    }
+
+    /**
+     * hmac-sha256签名
+     *
+     * @param content 代签名的内容
+     * @param key     签名的key
+     * @return 签名
+     */
+    public static String sign(String content, String key) {
+        byte[] bytes = new HmacUtils(HmacAlgorithms.HMAC_SHA_256, key).hmac(content);
+        return new String(Hex.encodeHex(bytes));
+    }
+
+
+    /***
+     * 请求签名鉴权-POST请求
+     *
+     * @param projectId 项目Id
+     * @param secret 项目密钥
+     * @param host 网关地址
+     */
+    public static void testUpload(String projectId, String secret, String host) {
+        // 文件上传接口
+        String uploadApi = "/file/v1/pdf/uploadAndSpilt";
+        // 文件上传接口请求地址
+        String uploadApiUrl = host + uploadApi;
+
+        try {
+            // 构建请求Body体
+            JSONObject reqBodyObj = new JSONObject(true);
+            reqBodyObj.put("file", "测试文件密码123456.pdf");
+            reqBodyObj.put("filePwd", "123456");
+
+            // 请求Body体数据
+            String reqBodyData = reqBodyObj.toString();
+
+            // 构建参与请求签名计算的明文
+            String plaintext = reqBodyData;
+            // 计算请求签名值
+            String reqSignature = sign(plaintext, secret);
+
+            // 构建文件
+            String filePath = "/xxx/xxx/测试文件密码123456.pdf";
+            String fileFieldName = "file";
+
+            // 构建请求头
+            LinkedHashMap<String, String> header = new LinkedHashMap<>();
+            // 构建待签名字符串
+            String accept = "*/*";
+            header.put("X-timevale-project-id", projectId);
+            header.put("X-timevale-signature", reqSignature);
+            header.put("Accept", accept);
+            // 发送POST请求
+            String result = HTTPHelper.uploadFile(uploadApiUrl,  fileFieldName, filePath, reqBodyObj,  header, "UTF-8");
+            JSONObject resultObj = JSONObject.parseObject(result);
+            System.out.println("请求返回信息: " + resultObj.toString());
+        } catch (Exception e) {
+            e.printStackTrace();
+            String msg = MessageFormat.format("请求签名鉴权方式调用接口出现异常: {0}", e.getMessage());
+            System.out.println(msg);
+        }
+    }
+}