Browse Source

华高e签宝对接

wzy 10 hours ago
parent
commit
2d06270c5c

+ 2 - 2
mjava-huagao/pom.xml

@@ -7,7 +7,7 @@
     <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
-        <version>2.2.0.RELEASE</version> <!-- 使用最新的稳定版或其他适用版本 -->
+        <version>2.7.18</version> <!-- 使用最新的稳定版或其他适用版本 -->
         <relativePath/> <!-- lookup parent from repository -->
     </parent>
 
@@ -67,7 +67,7 @@
         <dependency>
             <groupId>com.malk</groupId>
             <artifactId>base</artifactId>
-            <version>1.1-SNAPSHOT</version>
+            <version>1.3</version>
             <scope>compile</scope>
         </dependency>
         <dependency>

+ 150 - 0
mjava-huagao/src/main/java/com/malk/huagao/controller/HgEqbController.java

@@ -0,0 +1,150 @@
+package com.malk.huagao.controller;
+
+import org.springframework.core.io.UrlResource;
+import org.springframework.core.io.Resource;
+import com.alibaba.fastjson.JSON;
+import com.malk.huagao.service.EqbService;
+import com.malk.server.common.McR;
+import com.malk.utils.UtilMap;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.TimeUnit;
+
+@Slf4j
+@RestController
+@RequestMapping("/eqb")
+public class HgEqbController {
+    @Autowired
+    private EqbService eqbService;
+
+    @Value(value = "${eqb.downloadFilePath}")
+    private String fileStoragePath;
+
+
+    @PostMapping("/sign")
+    public McR sign(@RequestBody Map map){
+        return eqbService.sign(map);
+    }
+
+    // 使用ConcurrentHashMap保证线程安全
+    private final ConcurrentMap<String, Long> eventList = new ConcurrentHashMap<>();
+    // 记录最后一次清理时间
+    private volatile long lastCleanTime = System.currentTimeMillis();
+    // 清理间隔时间(毫秒)
+    private static final long CLEAN_INTERVAL = 60_000;
+
+
+    @PostMapping("/callback")
+    public McR callback(@RequestBody Map map){
+        System.out.println(map);
+
+        log.info("e签宝回调: {}", JSON.toJSONString(map));
+
+        //签署回调通知:SIGN_MISSON_COMPLETE   事件订阅-签署流程完成:SIGN_FLOW_FINISH
+        String action = UtilMap.getString(map, "action");
+        String signFlowId = UtilMap.getString(map, "signFlowId");//e签宝签署流程id
+
+        String info = action + "-" + signFlowId;
+
+        // 定期清理过期记录
+        cleanExpiredEvents();
+
+        if (isCallbackProcessed(info)){
+            log.info("info:{},重复回调,不做处理",info);
+        }else {
+            eventList.put(info, System.currentTimeMillis());
+            //签署回调结束
+            if ("SIGN_MISSON_COMPLETE".equals(action)) {
+                int signResult = UtilMap.getInt(map, "signResult");//2 - 签署完成,4 - 拒签
+                if (2 == signResult) {
+                    String processInstanceId = UtilMap.getString(map, "customBizNum");//宜搭审批实例id
+                    //自动同意审批节点
+                    eqbService.autoAgree(signFlowId,processInstanceId);
+                }
+            }
+        }
+
+        return McR.success();
+    }
+
+    @GetMapping("/files/{fileId}")
+    public ResponseEntity<Resource> getFileResource(
+            @PathVariable String fileId,
+            @RequestParam(defaultValue = "download") String option) throws IOException {
+
+        // 根据fileId获取实际文件路径,这里简化处理,实际可能需要从数据库查询
+        Path filePath = Paths.get(fileStoragePath).resolve(fileId).normalize();
+
+        // 检查文件是否存在
+        if (!Files.exists(filePath)) {
+            return ResponseEntity.notFound().build();
+        }
+
+        // 创建Resource对象
+        Resource resource =  new UrlResource(filePath.toUri());
+
+        // 根据选项设置响应头
+        HttpHeaders headers = new HttpHeaders();
+        if ("preview".equalsIgnoreCase(option)) {
+            // 预览模式 - 尝试确定内容类型
+            String contentType = Files.probeContentType(filePath);
+            // 强制修正 PDF 的 Content-Type
+            if (filePath.toString().toLowerCase().endsWith(".pdf")) {
+                contentType = "application/pdf";
+            } else if (contentType == null) {
+                contentType = "application/octet-stream";
+            }
+            headers.setContentType(MediaType.parseMediaType(contentType));
+            headers.add("Content-Disposition", "inline; filename=\"" + resource.getFilename() + "\"");
+            headers.add("X-Content-Type-Options", "nosniff"); // 防止浏览器忽略 Content-Type
+        } else {
+            // 下载模式 - 默认处理
+            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
+            headers.add("Content-Disposition", "attachment; filename=\"" + resource.getFilename() + "\"");
+        }
+
+        return ResponseEntity.ok()
+                .headers(headers)
+                .contentLength(resource.contentLength())
+                .body(resource);
+    }
+
+    /**
+     * 检查并清理过期事件
+     */
+    private void cleanExpiredEvents() {
+        long currentTime = System.currentTimeMillis();
+        // 只在达到清理间隔时执行清理
+        if (currentTime - lastCleanTime > CLEAN_INTERVAL) {
+            synchronized (this) {
+                // 双重检查,避免重复清理
+                if (currentTime - lastCleanTime > CLEAN_INTERVAL) {
+                    long expirationTime = currentTime - TimeUnit.MINUTES.toMillis(1);
+                    eventList.entrySet().removeIf(entry -> entry.getValue() < expirationTime);
+                    lastCleanTime = currentTime;
+                }
+            }
+        }
+    }
+
+    /**
+     * 检查该回调事件在一分钟内是否处理过
+     */
+    private boolean isCallbackProcessed(String detail) {
+        return eventList.containsKey(detail);
+    }
+
+}

+ 889 - 0
mjava-huagao/src/main/java/com/malk/huagao/service/impl/EqbServiceImpl.java

@@ -0,0 +1,889 @@
+package com.malk.huagao.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.malk.huagao.service.EqbService;
+import com.malk.huagao.utils.HTTPHelper;
+import com.malk.server.aliwork.YDConf;
+import com.malk.server.aliwork.YDParam;
+import com.malk.server.common.McR;
+import com.malk.service.aliwork.YDClient;
+import com.malk.service.dingtalk.DDClient;
+import com.malk.utils.UtilHttp;
+import com.malk.utils.UtilMap;
+import org.apache.commons.codec.binary.Base64;
+import org.slf4j.MDC;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.security.InvalidKeyException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.text.MessageFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@Service
+public class EqbServiceImpl implements EqbService {
+    @Autowired
+    private YDConf ydConf;
+
+    @Autowired
+    private YDClient ydClient;
+
+    @Autowired
+    private DDClient ddClient;
+
+    // 应用ID
+    final static String appId = "5112033166";
+    // 应用密钥(AppSecret)
+    final static String appKey = "c0641a1f648a68a7014be5a490f0159a";
+    // e签宝接口调用域名(正式环境)
+    final static String host = "https://openapi.esign.cn";
+
+    //正式环境模板id 经销商模板
+    final static String jxs_templateId = "6a23f76742d74b858cdc2259a5d5c32f";
+    //正式环境模板id 其他客户模板
+    final static String qtkh_templateId = "8b7fef2257bc4093ada330dbf7c874c5";
+    //正式环境模板id 采购订单模板
+    final static String cgdd_templateId = "a0827f8946994ebfbed7f44e6b8a6ed8";
+
+    @Value(value = "${eqb.downloadFilePath}")
+    private String downloadFilePath;
+
+    @Value(value = "${server.host}")
+    private String serverHost;
+
+    @Value(value = "${eqb.signatoryPsnId}")
+    private String signatoryPsnId;
+
+
+
+    @Async
+    @Override
+    public void autoAgree(String signFlowId,String processInstanceId) {
+        MDC.put("MDC_KEY_PID","1003");
+
+        //1、签署后文件回写宜搭
+        Map fileInfo = downloadSignedFile(signFlowId);
+        String fileId = UtilMap.getString(fileInfo, "fileId");
+        String fileName = UtilMap.getString(fileInfo, "fileName");
+
+        String downloadUrl = serverHost + "/huagao/eqb/files/" + fileId + ".pdf?option=download";
+        String previewUrl = serverHost + "/huagao/eqb/files/" + fileId + ".pdf?option=preview";
+
+        //更新宜搭实例签署后文件
+        Map formData = new HashMap();
+        Map file = new HashMap();
+        file.put("downloadUrl",downloadUrl);
+        file.put("name",fileName);
+        file.put("previewUrl",previewUrl);
+        file.put("url",downloadUrl);
+        file.put("ext","pdf");
+
+        formData.put("attachmentField_mj8dt3g2",Arrays.asList(file));
+
+        ydClient.operateData(YDParam.builder()
+                .updateFormDataJson(JSONObject.toJSONString(formData))
+                .formInstanceId(processInstanceId)
+                .build(), YDConf.FORM_OPERATION.update);
+
+        //2、自动同意宜搭审批节点
+        String activityId = "node_ockpz6phx73";//审批节点id【e签宝签署(系统节点,禁止删除!)】
+        long taskId = 0;
+        String userId = "";//审批人id
+
+        //获取审批记录
+        List<Map> result = (List<Map>) ydClient.queryData(YDParam.builder()
+                .processInstanceId(processInstanceId)
+                .build(), YDConf.FORM_QUERY.retrieve_approval_record).getResult();
+        for (Map approveInfo : result) {
+            if (activityId.equals(UtilMap.getString(approveInfo, "activityId"))){
+                //获取taskId
+                taskId = UtilMap.getLong(approveInfo, "taskId");
+                userId = UtilMap.getString(approveInfo, "operatorUserId");
+                break;
+            }
+        }
+
+        //审批
+        Map body = new HashMap();
+        body.put("outResult","AGREE");//AGREE:同意 DISAGREE:拒绝。
+        body.put("appType",ydConf.getAppType());
+        body.put("systemToken",ydConf.getSystemToken());
+        body.put("remark","e签宝签署完成,自动通过");//审批意见
+        body.put("processInstanceId",processInstanceId);//审批实例id
+        body.put("userId",userId);//用户userid
+        body.put("taskId",taskId);//任务id
+
+        UtilHttp.doPost("https://api.dingtalk.com/v1.0/yida/tasks/execute", ddClient.initTokenHeader(), null,body);
+    }
+
+    @Override
+    public McR sign(Map map) {
+        MDC.put("MDC_KEY_PID","1003");
+        //1、查询宜搭实例详情
+        String formInstId = UtilMap.getString(map, "formInstId");
+
+        Map formData = ydClient.queryData(YDParam.builder()
+                .formInstanceId(formInstId)
+                .build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
+
+        String type = UtilMap.getString(formData, "selectField_mj89qndi");//用印文件类型
+
+        String fileName = UtilMap.getString(formData, "textField_meqr38kq");//用印文件名称
+
+        JSONObject reqBodyObj = new JSONObject();
+
+        List<Map> components = new ArrayList<>();
+
+
+        switch (type){
+            case "销售合同-经销商":
+                getJxsObj(formData, components, reqBodyObj, fileName);
+                break;
+            case "销售合同-其他客户":
+                getQtkhObj(formData,components,reqBodyObj,fileName);
+                break;
+            case "采购订单":
+                getCgddObj(formData,components,reqBodyObj,fileName);
+                break;
+            default:break;
+        }
+
+        //2、填充模板生成文件
+        Map result = eqbPost("/v3/files/create-by-doc-template", reqBodyObj);
+
+        String fileId = UtilMap.getString(result,"fileId");
+
+        //3、基于文件发起签署
+        JSONObject reqBodyObj2 = new JSONObject();
+        //设置待签署文件信息
+        Map docs = new HashMap();
+        docs.put("fileId", fileId);
+        reqBodyObj2.put("docs", Arrays.asList(docs));
+
+        //签署流程配置项
+        Map signFlowConfig = new HashMap();
+        signFlowConfig.put("signFlowTitle",fileName);
+        signFlowConfig.put("autoFinish",true);
+        signFlowConfig.put("notifyUrl",serverHost + "/huagao/eqb/callback");//回调地址
+        reqBodyObj2.put("signFlowConfig",signFlowConfig);
+
+        //签署方信息
+        Map signer = new HashMap();
+        signer.put("signerType",0);//签署方类型,0 - 个人,1 - 企业/机构,2 - 法定代表人,3 - 经办人
+            /*Map orgSignerInfo = new HashMap();
+            orgSignerInfo.put("orgId","a5ec8fb7d8cc4276bd486824df0ec640");
+            signer.put("orgSignerInfo",orgSignerInfo);*/
+        Map psnSignerInfo = new HashMap();
+        psnSignerInfo.put("psnId",signatoryPsnId);//陈伟东
+        signer.put("psnSignerInfo",psnSignerInfo);
+
+        Map signField = new HashMap();
+        signField.put("fileId",fileId);
+        signField.put("customBizNum",formInstId);
+        Map normalSignFieldConfig = new HashMap();
+        normalSignFieldConfig.put("freeMode",true);
+            /*normalSignFieldConfig.put("autoSign",true);
+            normalSignFieldConfig.put("signFieldStyle",1);
+            Map signFieldPosition = new HashMap();
+            signFieldPosition.put("positionPage",1);
+            normalSignFieldConfig.put("signFieldPosition",signFieldPosition);*/
+        signField.put("normalSignFieldConfig",normalSignFieldConfig);
+        signer.put("signFields",Arrays.asList(signField));
+
+        reqBodyObj2.put("signers",Arrays.asList(signer));
+
+        Map result2 = eqbPost("/v3/sign-flow/create-by-file", reqBodyObj2);
+
+        String signFlowId = UtilMap.getString(result2, "signFlowId");
+
+
+        //4、回写签署地址
+        JSONObject reqBodyObj3 = new JSONObject();
+        Map operator = new HashMap();
+        operator.put("psnId", "0fd3eb8b0c424b4e827bb3bf1fba62f3");
+        reqBodyObj3.put("operator", operator);
+        Map result3 = eqbPost("/v3/sign-flow/" + signFlowId + "/sign-url", reqBodyObj3);
+
+        String shortUrl = UtilMap.getString(result3, "shortUrl");
+
+        ydClient.operateData(YDParam.builder()
+                .formInstanceId(formInstId)
+                .content("签署地址:"+shortUrl)
+                .userId("344749020127590108")
+                .atUserId("344749020127590108")
+                .build(), YDConf.FORM_OPERATION.remarks);
+
+
+        return McR.success();
+    }
+
+    private void getJxsObj(Map formData,List<Map> components,JSONObject reqBodyObj,String fileName){
+        String dgdbh = UtilMap.getString(formData, "textField_mjas1rkm");//订购单编号
+        String xf = UtilMap.getString(formData, "textField_mjaukh2p");//需方
+        String xfdz = UtilMap.getString(formData, "textareaField_mf50cbqt");//需方地址
+        String xfdh = UtilMap.getString(formData, "textField_mf50cbqw");//需方电话
+        String xfjbr = UtilMap.getString(formData, "textField_mj8dt3fj");//需方经办人
+        String gfdh = UtilMap.getString(formData, "textField_mjau7ffr");//供方电话
+        String gfjbr = UtilMap.getString(formData, "textField_mjauqjr9");//供方经办人
+        long ddrq = UtilMap.getLong(formData, "dateField_mj8dt3fa");//订单日期
+        String ghkjxybh = UtilMap.getString(formData, "textField_mjas1rkn");//供货框架协议编号
+        Double jehj = UtilMap.getDouble(formData, "numberField_me1335n7");//金额合计
+        String jehjdx = UtilMap.getString(formData, "textField_mf50cbvj");//金额合计大写
+        String fktj = UtilMap.getString(formData, "radioField_mf50cbu7");//付款条件
+        String xfnsrsbh = UtilMap.getString(formData, "textField_mf50cbuj");//需方纳税人识别号
+        String xfkhyh = UtilMap.getString(formData, "textField_mf50cbup");//需方开户银行
+        String xfzh = UtilMap.getString(formData, "textField_mf50cbuk");//需方账号
+
+        List<Map> xshtmxList = UtilMap.getList(formData, "tableField_mf50cbre");//销售合同明细
+        List<Map> jhdzList = UtilMap.getList(formData, "tableField_mj8dt3fk");//交货地址
+
+        //订购单编号
+        Map jxsComponent = new HashMap();
+        jxsComponent.put("componentKey", "dgdbh");
+        jxsComponent.put("componentValue", dgdbh);
+
+        //需方
+        Map jxsComponent2 = new HashMap();
+        jxsComponent2.put("componentKey", "xf");
+        jxsComponent2.put("componentValue", xf);
+
+        //需方地址
+        Map jxsComponent3 = new HashMap();
+        jxsComponent3.put("componentKey", "xfdz");
+        jxsComponent3.put("componentValue", xfdz);
+
+        //需方电话
+        Map jxsComponent4 = new HashMap();
+        jxsComponent4.put("componentKey", "xfdh");
+        jxsComponent4.put("componentValue", xfdh);
+
+        //需方经办人
+        Map jxsComponent5 = new HashMap();
+        jxsComponent5.put("componentKey", "xfjbr");
+        jxsComponent5.put("componentValue", xfjbr);
+
+        //供方电话
+        Map jxsComponent6 = new HashMap();
+        jxsComponent6.put("componentKey", "gfdh");
+        jxsComponent6.put("componentValue", gfdh);
+
+        //供方经办人
+        Map jxsComponent7 = new HashMap();
+        jxsComponent7.put("componentKey", "gfjbr");
+        jxsComponent7.put("componentValue", gfjbr);
+
+        //订单日期
+        Map jxsComponent8 = new HashMap();
+        jxsComponent8.put("componentKey", "ddrq");
+        jxsComponent8.put("componentValue", ddrq);
+
+        //供货框架协议编号
+        Map jxsComponent9 = new HashMap();
+        jxsComponent9.put("componentKey", "ghkjxybh");
+        jxsComponent9.put("componentValue", ghkjxybh);
+
+        //金额合计
+        Map jxsComponent10 = new HashMap();
+        jxsComponent10.put("componentKey", "jehj");
+        jxsComponent10.put("componentValue", jehj);
+
+        //金额合计大写
+        Map jxsComponent11 = new HashMap();
+        jxsComponent11.put("componentKey", "jehjdx");
+        jxsComponent11.put("componentValue", jehjdx);
+
+        //付款条件
+        Map jxsComponent12 = new HashMap();
+        if ("款到发货".equals(fktj)){
+            jxsComponent12.put("componentKey", "xkhh");
+            jxsComponent12.put("componentValue", true);
+        }else {
+            jxsComponent12.put("componentKey", "qt");
+            jxsComponent12.put("componentValue", true);
+        }
+
+        //需方纳税人识别号
+        Map jxsComponent13 = new HashMap();
+        jxsComponent13.put("componentKey", "xfnsrsbh");
+        jxsComponent13.put("componentValue", xfnsrsbh);
+
+        //需方开户银行
+        Map jxsComponent14 = new HashMap();
+        jxsComponent14.put("componentKey", "xfkhyh");
+        jxsComponent14.put("componentValue", xfkhyh);
+
+        //需方账号
+        Map jxsComponent15 = new HashMap();
+        jxsComponent15.put("componentKey", "xfzh");
+        jxsComponent15.put("componentValue", xfzh);
+
+        //销售合同明细
+        List<Map> xshtmx = new ArrayList<>();
+        xshtmx.add(getRowMap(false));
+        for (int i = 0; i < xshtmxList.size(); i++) {
+            String cpmc = UtilMap.getString(xshtmxList.get(i), "textField_mf50cbrf");//产品名称
+            String cpxh = UtilMap.getString(xshtmxList.get(i), "textField_mf50cbrg");//产品型号
+            String dw = UtilMap.getString(xshtmxList.get(i), "textField_mf50cbrh");//单位
+            String xssl = UtilMap.getString(xshtmxList.get(i), "numberField_mfbx1pr4");//销售数量
+            double lsdj = UtilMap.getDouble(xshtmxList.get(i), "numberField_mf50cbri");//零售单价
+            double pfyhdj = UtilMap.getDouble(xshtmxList.get(i), "numberField_mf50cbrj");//批发优惠单价
+            String zbq = UtilMap.getString(xshtmxList.get(i), "textField_mjas1rkx");//质保期
+
+            if (i == 0){
+                xshtmx.add(getRowMap(false,i+1,cpmc,cpxh,dw,lsdj,pfyhdj,zbq));
+            }else {
+                xshtmx.add(getRowMap(true,i+1,cpmc,cpxh,dw,lsdj,pfyhdj,zbq));
+            }
+        }
+        Map jxsComponent16 = new HashMap();
+        jxsComponent16.put("componentKey", "xshtmx");
+        jxsComponent16.put("componentValue", JSONObject.toJSONString(xshtmx));
+
+        //交货地址
+        List<Map> jhdz = new ArrayList<>();
+        jhdz.add(getRowMap(false));
+        for (int i = 0; i < jhdzList.size(); i++) {
+            String shdz = UtilMap.getString(jhdzList.get(i), "textField_mj8dt3fl");//收货地址
+            String shr = UtilMap.getString(jhdzList.get(i), "textField_mj8dt3fm");//收货人
+            String shrlxdh = UtilMap.getString(jhdzList.get(i), "textField_mj8dt3fn");//收货人联系电话
+
+            if (i == 0){
+                jhdz.add(getRowMap(false,i+1,shdz,shr,shrlxdh));
+            }else {
+                jhdz.add(getRowMap(true,i+1,shdz,shr,shrlxdh));
+            }
+        }
+        Map jxsComponent17 = new HashMap();
+        jxsComponent17.put("componentKey", "jhdz");
+        jxsComponent17.put("componentValue", JSONObject.toJSONString(jhdz));
+
+        Map jxsComponent19 = new HashMap();
+        jxsComponent19.put("componentKey", "xf2");
+        jxsComponent19.put("componentValue", xf);
+
+        Map jxsComponent20 = new HashMap();
+        jxsComponent20.put("componentKey", "xfdz2");
+        jxsComponent20.put("componentValue", xfdz);
+
+        components.add(jxsComponent);
+        components.add(jxsComponent2);
+        components.add(jxsComponent3);
+        components.add(jxsComponent4);
+        components.add(jxsComponent5);
+        components.add(jxsComponent6);
+        components.add(jxsComponent7);
+        components.add(jxsComponent8);
+        components.add(jxsComponent9);
+        components.add(jxsComponent10);
+        components.add(jxsComponent11);
+        components.add(jxsComponent12);
+        components.add(jxsComponent13);
+        components.add(jxsComponent14);
+        components.add(jxsComponent15);
+        components.add(jxsComponent16);
+        components.add(jxsComponent17);
+        components.add(jxsComponent19);
+        components.add(jxsComponent20);
+
+        if (!"款到发货".equals(fktj)){
+            Map jxsComponent18 = new HashMap();
+            jxsComponent18.put("componentKey", "qtnr");
+            jxsComponent18.put("componentValue", fktj);
+            components.add(jxsComponent18);
+        }
+
+        // 构建请求Body体
+        reqBodyObj.put("docTemplateId", jxs_templateId);
+        reqBodyObj.put("fileName", fileName+".pdf");
+        reqBodyObj.put("components", components);
+    }
+
+    private void getQtkhObj(Map formData, List<Map> components, JSONObject reqBodyObj, String fileName){
+        String htbh = UtilMap.getString(formData, "textField_mjb71q95");//合同编号
+        String jf = UtilMap.getString(formData, "textField_mjaukh2p");//甲方
+        double xsze = UtilMap.getDouble(formData, "numberField_mjb71qac");//销售总额
+        String fkfs = UtilMap.getString(formData, "textField_mjb886fw");//付款方式
+        String jfnsrsbh = UtilMap.getString(formData, "textField_mjb71q9w");//甲方纳税人识别号
+        String spyx = UtilMap.getString(formData, "textField_mjb71q9y");//收票邮箱
+        String jfdb = UtilMap.getString(formData, "textField_mjb886fx");//甲方代表
+        String yfdb = UtilMap.getString(formData, "textField_mj8dt3fj");//乙方代表
+
+        List<Map> xshtmxList = UtilMap.getList(formData, "tableField_mjb71qab");//销售合同明细
+
+        //订购单编号
+        Map jxsComponent = new HashMap();
+        jxsComponent.put("componentKey", "htbh");
+        jxsComponent.put("componentValue", htbh);
+
+        //甲方
+        Map jxsComponent2 = new HashMap();
+        jxsComponent2.put("componentKey", "jf");
+        jxsComponent2.put("componentValue", jf);
+
+        //销售总额
+        Map jxsComponent3 = new HashMap();
+        jxsComponent3.put("componentKey", "xsze");
+        jxsComponent3.put("componentValue", xsze);
+
+        //付款方式
+        Map jxsComponent4 = new HashMap();
+        jxsComponent4.put("componentKey", "fkfs");
+        jxsComponent4.put("componentValue", fkfs);
+
+        //甲方纳税人识别号
+        Map jxsComponent5 = new HashMap();
+        jxsComponent5.put("componentKey", "jfnsrsbh");
+        jxsComponent5.put("componentValue", jfnsrsbh);
+
+        //收票邮箱
+        Map jxsComponent6 = new HashMap();
+        jxsComponent6.put("componentKey", "spyx");
+        jxsComponent6.put("componentValue", spyx);
+
+        //甲方代表
+        Map jxsComponent7 = new HashMap();
+        jxsComponent7.put("componentKey", "jfdb");
+        jxsComponent7.put("componentValue", jfdb);
+
+        //乙方代表
+        Map jxsComponent8 = new HashMap();
+        jxsComponent8.put("componentKey", "yfdb");
+        jxsComponent8.put("componentValue", yfdb);
+
+        //销售合同明细
+        List<Map> xshtmx = new ArrayList<>();
+        xshtmx.add(getRowMap(false));
+        for (int i = 0; i < xshtmxList.size(); i++) {
+            String cpmc = UtilMap.getString(xshtmxList.get(i), "textField_mjb71qa4");//产品名称
+            String cpxh = UtilMap.getString(xshtmxList.get(i), "textField_mjb71qa5");//产品型号
+            String dw = UtilMap.getString(xshtmxList.get(i), "textField_mjb71qa6");//单位
+            String xssl = UtilMap.getString(xshtmxList.get(i), "numberField_mjb71qa7");//销售数量
+            double hsdj = UtilMap.getDouble(xshtmxList.get(i), "numberField_mjb71qa8");//含税单价
+            int zbq = UtilMap.getInt(xshtmxList.get(i), "numberField_mjb71qaw");//质保期
+            String smzs = UtilMap.getString(xshtmxList.get(i), "textField_mjb71qam");//扫描张数
+            double jshj = UtilMap.getDouble(xshtmxList.get(i), "numberField_mjb71qan");//价税合计
+            double zke = UtilMap.getDouble(xshtmxList.get(i), "numberField_mjb71qao");//折扣额
+            String bz = UtilMap.getString(xshtmxList.get(i), "textField_mjb71qaq");//备注
+
+            if (i == 0){
+                xshtmx.add(getRowMap(false,cpmc,cpxh,dw,xssl,hsdj,zbq+"年",smzs,jshj,zke,bz));
+            }else {
+                xshtmx.add(getRowMap(true,cpmc,cpxh,dw,xssl,hsdj,zbq+"年",smzs,jshj,zke,bz));
+            }
+        }
+        Map jxsComponent9 = new HashMap();
+        jxsComponent9.put("componentKey", "xshtmx");
+        jxsComponent9.put("componentValue", JSONObject.toJSONString(xshtmx));
+
+        //甲方
+        Map jxsComponent10 = new HashMap();
+        jxsComponent10.put("componentKey", "jf2");
+        jxsComponent10.put("componentValue", jf);
+
+        //甲方
+        Map jxsComponent11 = new HashMap();
+        jxsComponent11.put("componentKey", "jf3");
+        jxsComponent11.put("componentValue", jf);
+
+
+        components.add(jxsComponent);
+        components.add(jxsComponent2);
+        components.add(jxsComponent3);
+        components.add(jxsComponent4);
+        components.add(jxsComponent5);
+        components.add(jxsComponent6);
+        components.add(jxsComponent7);
+        components.add(jxsComponent8);
+        components.add(jxsComponent9);
+        components.add(jxsComponent10);
+        components.add(jxsComponent11);
+
+        // 构建请求Body体
+        reqBodyObj.put("docTemplateId", qtkh_templateId);
+        reqBodyObj.put("fileName", fileName+".pdf");
+        reqBodyObj.put("components", components);
+    }
+
+    private void getCgddObj(Map formData,List<Map> components,JSONObject reqBodyObj,String fileName){
+        String cgddbh = UtilMap.getString(formData, "textField_mj9msq4v");//采购订单编号
+        long date = UtilMap.getLong(formData, "dateField_mj8dt3g6");//签订日期
+        String yf = UtilMap.getString(formData, "textField_mj8dt3g7");//乙方
+        String yfdz = UtilMap.getString(formData, "textField_mj8dt3gt");//乙方地址
+        String yflxr = UtilMap.getString(formData, "textField_mj8dt3g8");//乙方联系人
+        String yfdh = UtilMap.getString(formData, "textField_mj8dt3g9");//乙方电话
+        String nsrsbh = UtilMap.getString(formData, "textField_mj8dt3gs");//乙方纳税人识别号
+        String khyh = UtilMap.getString(formData, "textField_mj8dt3gq");//乙方开户银行
+        String zh = UtilMap.getString(formData, "textField_mj8dt3gr");//乙方账号
+        String zlyq = UtilMap.getString(formData, "textField_mj8dt3gn");//质量要求
+        String jsfs = UtilMap.getString(formData, "textField_mj8dt3go");//结算方式及付款期限
+        String bz = UtilMap.getString(formData, "textareaField_mj9msq4w");//备注
+        List<Map> cgmx = UtilMap.getList(formData, "tableField_mizdd3qf");//采购明细
+        double zjyf = UtilMap.getDouble(formData, "numberField_mj9msq4x");//总计应付
+        String jflxr = UtilMap.getString(formData, "textField_mjb2kuhf");//甲方联系人
+        String jflxdh = UtilMap.getString(formData, "textField_mjb2kuhh");//甲方联系电话
+
+        //订单编号
+        Map component = new HashMap();
+        component.put("componentKey", "ddbh");
+        component.put("componentValue", cgddbh);
+
+        //签订日期
+        Map component2 = new HashMap();
+        component2.put("componentKey", "qdrq");
+        component2.put("componentValue", date);
+
+        //乙方
+        Map component3 = new HashMap();
+        component3.put("componentKey", "yf");
+        component3.put("componentValue", yf);
+
+        //乙方联系人
+        Map component4 = new HashMap();
+        component4.put("componentKey", "yflxr");
+        component4.put("componentValue", yflxr);
+
+        //乙方联系电话
+        Map component5 = new HashMap();
+        component5.put("componentKey", "yflxdh");
+        component5.put("componentValue", yfdh);
+
+        //备注
+        Map component6 = new HashMap();
+        component6.put("componentKey", "bz");
+        component6.put("componentValue", bz);
+
+        //销售合同明细
+        List<Map> cghtmx = new ArrayList<>();
+        cghtmx.add(getRowMap(false));
+        for (int i = 0; i < cgmx.size(); i++) {
+            String wlbm = UtilMap.getString(cgmx.get(i), "textField_mizdd3qg");//物料编码
+            String wlmc = UtilMap.getString(cgmx.get(i), "textField_mizdd3qh");//物料名称
+            String ggxh = UtilMap.getString(cgmx.get(i), "textField_mizdd3qi");//规格型号
+            String cgdw = UtilMap.getString(cgmx.get(i), "textField_mizdd3qj");//采购单位
+            double cgsl = UtilMap.getDouble(cgmx.get(i), "numberField_mizdd3ql");//采购数量
+            double hsdj = UtilMap.getDouble(cgmx.get(i), "numberField_mizdd3qs");//含税单价
+            double jshj = UtilMap.getDouble(cgmx.get(i), "numberField_mizdd3qx");//价税合计
+            long jhrq = UtilMap.getLong(cgmx.get(i), "dateField_mizdd3qp");//交货日期
+            //时间戳转化为年月日
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            String jhrqStr = sdf.format(new Date(jhrq));
+
+            String mxbz = UtilMap.getString(cgmx.get(i), "textField_mizdd3r0");//备注
+
+            if (i == 0){
+                cghtmx.add(getRowMap(false,i+1,wlbm,wlmc,null,ggxh,cgdw,cgsl,hsdj,jshj,jhrqStr,mxbz));
+            }else {
+                cghtmx.add(getRowMap(true,i+1,wlbm,wlmc,null,ggxh,cgdw,cgsl,hsdj,jshj,jhrqStr,mxbz));
+            }
+        }
+        Map component7 = new HashMap();
+        component7.put("componentKey", "cgmx");
+        component7.put("componentValue", JSONObject.toJSONString(cghtmx));
+
+        //总计应付
+        Map component8 = new HashMap();
+        component8.put("componentKey", "zjyf");
+        component8.put("componentValue", zjyf);
+
+        //质量要求
+        Map component9 = new HashMap();
+        component9.put("componentKey", "zlyq");
+        component9.put("componentValue", zlyq);
+
+        //结算方式及付款期限
+        Map component10 = new HashMap();
+        component10.put("componentKey", "jsfs");
+        component10.put("componentValue", jsfs);
+
+        //乙方
+        Map component11 = new HashMap();
+        component11.put("componentKey", "yf2");
+        component11.put("componentValue", yf);
+
+        //乙方开户银行
+        Map component12 = new HashMap();
+        component12.put("componentKey", "yfkhyh");
+        component12.put("componentValue", khyh);
+
+        //乙方账号
+        Map component13 = new HashMap();
+        component13.put("componentKey", "yfzh");
+        component13.put("componentValue", zh);
+
+        //乙方纳税人识别号
+        Map component14 = new HashMap();
+        component14.put("componentKey", "yfnsrsbh");
+        component14.put("componentValue", nsrsbh);
+
+        //乙方地址
+        Map component15 = new HashMap();
+        component15.put("componentKey", "yfdz");
+        component15.put("componentValue", yfdz);
+
+        //甲方联系人
+        Map component16 = new HashMap();
+        component16.put("componentKey", "jflxr");
+        component16.put("componentValue", jflxr);
+
+        //甲方联系电话
+        Map component17 = new HashMap();
+        component17.put("componentKey", "jflxdh");
+        component17.put("componentValue", jflxdh);
+
+        components.add(component);
+        components.add(component2);
+        components.add(component3);
+        components.add(component4);
+        components.add(component5);
+        components.add(component6);
+        components.add(component7);
+        components.add(component8);
+        components.add(component9);
+        components.add(component10);
+        components.add(component11);
+        components.add(component12);
+        components.add(component13);
+        components.add(component14);
+        components.add(component15);
+        components.add(component16);
+        components.add(component17);
+
+        // 构建请求Body体
+        reqBodyObj.put("docTemplateId", cgdd_templateId);
+        reqBodyObj.put("fileName", fileName+".pdf");
+        reqBodyObj.put("components", components);
+    }
+
+    /***
+     * e签宝post请求
+     */
+    public static Map eqbPost(String postUrl,JSONObject reqBodyObj) {
+        // 完整的请求地址
+        String postAllUrl = host + postUrl;
+
+        try {
+            // 请求Body体数据
+            String reqBodyData = reqBodyObj.toString();
+            // 对请求Body体内的数据计算ContentMD5
+            String contentMD5 = doContentMD5(reqBodyData);
+            System.out.println("请求body数据:"+reqBodyData);
+            System.out.println("body的md5值:"+ contentMD5);
+
+            // 构建待签名字符串
+            String method = "POST";
+            String accept = "*/*";
+            String contentType = "application/json";
+            String url = postUrl;
+            String date = "";
+            String headers = "";
+
+            StringBuffer sb = new StringBuffer();
+            sb.append(method).append("\n").append(accept).append("\n").append(contentMD5).append("\n")
+                    .append(contentType).append("\n").append(date).append("\n");
+            if ("".equals(headers)) {
+                sb.append(headers).append(url);
+            } else {
+                sb.append(headers).append("\n").append(url);
+            }
+
+            // 构建参与请求签名计算的明文
+            String plaintext = sb.toString();
+            // 计算请求签名值
+            String reqSignature = doSignatureBase64(plaintext, appKey);
+            System.out.println("计算请求签名值:"+reqSignature);
+
+            // 获取时间戳(精确到毫秒)
+            long timeStamp = timeStamp();
+
+            // 构建请求头
+            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);
+
+            // 发送POST请求
+            String result = HTTPHelper.sendPOST(postAllUrl, reqBodyData, header, "UTF-8");
+
+            System.out.println("请求返回信息: " + result);
+
+            Map resultObj =(Map) JSONObject.parse(result);
+
+            Map data = UtilMap.getMap(resultObj, "data");
+
+            return data;
+        } catch (Exception e) {
+            e.printStackTrace();
+            String msg = MessageFormat.format("请求签名鉴权方式调用接口出现异常: {0}", e.getMessage());
+            System.out.println(msg);
+            throw new RuntimeException(e);
+        }
+    }
+
+    private Map downloadSignedFile(String signFlowId){
+        // 计算签名拼接的url
+        String postUrl = "/v3/sign-flow/" + signFlowId + "/file-download-url";
+
+        Map result = eqbPost(postUrl, new JSONObject());
+
+        List<Map> files =(List<Map>) UtilMap.getList(result, "files");
+
+        String downloadUrl = UtilMap.getString(files.get(0), "downloadUrl");
+        String fileName = UtilMap.getString(files.get(0), "fileName");
+        UUID fileId = UUID.randomUUID();
+
+        String downloadPath = downloadFilePath + fileId + ".pdf";
+
+        downloadFile(downloadUrl,downloadPath);
+
+        Map result2 = new HashMap();
+        result2.put("downloadPath",downloadPath);
+        result2.put("fileName",fileName);
+        result2.put("fileId",fileId);
+
+        return result2;
+    }
+
+    //文件下载到本地
+    private void downloadFile(String downloadUri,String downloadPath){
+        try {
+            URL url = new URL(downloadUri);
+
+            HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
+            int responseCode = httpConn.getResponseCode();
+
+            // 检查HTTP响应代码是否为200
+            if (responseCode == HttpURLConnection.HTTP_OK) {
+                InputStream inputStream = httpConn.getInputStream();
+                FileOutputStream outputStream = new FileOutputStream(downloadPath);
+
+                byte[] buffer = new byte[4096];
+                int bytesRead = -1;
+
+                while ((bytesRead = inputStream.read(buffer)) != -1) {
+                    outputStream.write(buffer, 0, bytesRead);
+                }
+
+                outputStream.close();
+                inputStream.close();
+            } else {
+                System.out.println("无法下载文件。HTTP响应代码: " + responseCode);
+            }
+            httpConn.disconnect();
+        }catch (Exception e){
+            throw new RuntimeException(e);
+        }
+    }
+
+
+    /***
+     *
+     * @param str 待计算的消息
+     * @return MD5计算后摘要值的Base64编码(ContentMD5)
+     * @throws Exception 加密过程中的异常信息
+     */
+    public static String doContentMD5(String str) throws Exception {
+        byte[] md5Bytes = null;
+        MessageDigest md5 = null;
+        String contentMD5 = null;
+        try {
+            md5 = MessageDigest.getInstance("MD5");
+            // 计算md5函数
+            md5.update(str.getBytes("UTF-8"));
+            // 获取文件MD5的二进制数组(128位)
+            md5Bytes = md5.digest();
+            // 把MD5摘要后的二进制数组md5Bytes使用Base64进行编码(而不是对32位的16进制字符串进行编码)
+            contentMD5 = new String(Base64.encodeBase64(md5Bytes), "UTF-8");
+        } catch (NoSuchAlgorithmException e) {
+            String msg = MessageFormat.format("不支持此算法: {0}", e.getMessage());
+            Exception ex = new Exception(msg);
+            ex.initCause(e);
+            throw ex;
+        } catch (UnsupportedEncodingException e) {
+            String msg = MessageFormat.format("不支持的字符编码: {0}", e.getMessage());
+            Exception ex = new Exception(msg);
+            ex.initCause(e);
+            throw ex;
+        }
+        return contentMD5;
+    }
+
+    /***
+     * 计算请求签名值
+     *
+     * @param message 待计算的消息
+     * @param secret 密钥
+     * @return HmacSHA256计算后摘要值的Base64编码
+     * @throws Exception 加密过程中的异常信息
+     */
+    public static String doSignatureBase64(String message, String secret) throws Exception {
+        String algorithm = "HmacSHA256";
+        Mac hmacSha256;
+        String digestBase64 = null;
+        try {
+            hmacSha256 = Mac.getInstance(algorithm);
+            byte[] keyBytes = secret.getBytes("UTF-8");
+            byte[] messageBytes = message.getBytes("UTF-8");
+            hmacSha256.init(new SecretKeySpec(keyBytes, 0, keyBytes.length, algorithm));
+            // 使用HmacSHA256对二进制数据消息Bytes计算摘要
+            byte[] digestBytes = hmacSha256.doFinal(messageBytes);
+            // 把摘要后的结果digestBytes使用Base64进行编码
+            digestBase64 = new String(Base64.encodeBase64(digestBytes), "UTF-8");
+        } catch (NoSuchAlgorithmException e) {
+            String msg = MessageFormat.format("不支持此算法: {0}", e.getMessage());
+            Exception ex = new Exception(msg);
+            ex.initCause(e);
+            throw ex;
+        } catch (UnsupportedEncodingException e) {
+            String msg = MessageFormat.format("不支持的字符编码: {0}", e.getMessage());
+            Exception ex = new Exception(msg);
+            ex.initCause(e);
+            throw ex;
+        } catch (InvalidKeyException e) {
+            String msg = MessageFormat.format("无效的密钥规范: {0}", e.getMessage());
+            Exception ex = new Exception(msg);
+            ex.initCause(e);
+            throw ex;
+        }
+        return digestBase64;
+    }
+
+
+    /***
+     * 获取时间戳(毫秒级)
+     *
+     * @return 毫秒级时间戳,如 1578446909000
+     */
+    public static long timeStamp() {
+        long timeStamp = System.currentTimeMillis();
+        return timeStamp;
+    }
+
+    private static Map getRowMap(boolean insertRow,Object... columnValues) {
+        Map row = new HashMap();
+
+        for (int i = 0; i < columnValues.length; i++) {
+            row.put("column" + (i + 1), columnValues[i]);
+        }
+
+        Map result = new HashMap();
+        result.put("row",row);
+        result.put("insertRow",insertRow);
+
+        return result;
+    }
+}

+ 270 - 0
mjava-huagao/src/main/java/com/malk/huagao/utils/HTTPHelper.java

@@ -0,0 +1,270 @@
+package com.malk.huagao.utils;
+
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HTTPHelper {
+    // slf4j日志记录器
+    private static final Logger LOG = LoggerFactory.getLogger(HTTPHelper.class);
+
+    /***
+     * 向指定URL发送GET方法的请求
+     *
+     * @param apiUrl
+     * @param data
+     * @param projectId
+     * @param signature
+     * @param encoding
+     * @return
+     * @throws Exception
+     */
+    public static String sendGet(String apiUrl, HashMap<String, Object> param,
+                                 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
+            StringBuffer fullUrl = new StringBuffer();
+            if (null != param) {
+                if (0 != param.size()) {
+                    StringBuffer params = new StringBuffer();
+                    for (Entry<String, Object> entry : param.entrySet()) {
+                        params.append(entry.getKey());
+                        params.append("=");
+                        params.append(entry.getValue().toString());
+                        params.append("&");
+                    }
+                    if (params.length() > 0) {
+                        params.deleteCharAt(params.lastIndexOf("&"));
+                    }
+                    fullUrl.append(apiUrl).append((params.length() > 0) ? "?" + params.toString() : "");
+                } else {
+                    fullUrl.append(apiUrl);
+                }
+            } else {
+                fullUrl.append(apiUrl);
+            }
+
+            LOG.info(">>>> 实际请求Url: " + fullUrl.toString());
+
+            // 建立连接
+            URL url = new URL(fullUrl.toString());
+            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 projectId
+     * @param signature
+     * @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();
+    }
+}

+ 6 - 0
mjava-huagao/src/main/resources/application-dev.yml

@@ -2,6 +2,7 @@ server:
   port: 7708
   servlet:
     context-path: /huagao
+  host: https://33d4c762.r23.cpolar.top
 
 enable:
   scheduling: false
@@ -64,5 +65,10 @@ kingdee:
   # 允许的最大读取延时,单位为秒
   # X-KDApi-RequestTimeout: 120
 
+eqb:
+  downloadFilePath: C:\\Users\\EDY\\Desktop\\项目\\华高\\电子签\\files\\
+  signatoryPsnId: c3fb35cb7e574baf97ed9f8917c6327b #签署人 陈伟东
+
+
 
 

+ 5 - 0
mjava-huagao/src/main/resources/application-prod.yml

@@ -2,6 +2,7 @@ server:
   port: 7708
   servlet:
     context-path: /huagao
+  host: https://mes.huagaochina.com:8022
 
 enable:
   scheduling: true
@@ -63,3 +64,7 @@ kingdee:
   # X-KDApi-ConnectTimeout: 120
   # 允许的最大读取延时,单位为秒
   # X-KDApi-RequestTimeout: 120
+
+eqb:
+  downloadFilePath: /home/server/huagao/files/
+  signatoryPsnId: c3fb35cb7e574baf97ed9f8917c6327b #签署人 陈伟东

+ 5 - 0
mjava-huagao/src/main/resources/application-prod2.yml

@@ -3,6 +3,7 @@ server:
   port: 7708
   servlet:
     context-path: /huagao
+    host: https://mes.huagaochina.com:8022
 
 enable:
   scheduling: true
@@ -64,3 +65,7 @@ kingdee:
   # X-KDApi-ConnectTimeout: 120
   # 允许的最大读取延时,单位为秒
   # X-KDApi-RequestTimeout: 120
+
+eqb:
+  downloadFilePath: /home/server/huagao/files/
+  signatoryPsnId: c3fb35cb7e574baf97ed9f8917c6327b #签署人 陈伟东

File diff suppressed because it is too large
+ 1391 - 0
mjava-huagao/src/test/java/com/malk/huagao/YqbTest.java