From 777f26027e94626c933e4848ac64d1100099dd13 Mon Sep 17 00:00:00 2001 From: lijiazhuo <13787924+lijiazhuosky@user.noreply.gitee.com> Date: Mon, 19 Jan 2026 14:36:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 + .../example/sso/controller/FddFileHeTong.java | 221 +++++++ .../com/example/sso/controller/TuTest.java | 446 ++++++++++++++ .../sso/controller/TuiZuController.java | 542 +++++++++++++++++- .../java/com/example/sso/dao/FddFileId.java | 75 +++ src/main/java/com/example/sso/dao/Photo.java | 392 +++++++++---- src/main/java/com/example/sso/test/R.java | 73 +++ .../java/com/example/sso/util/FDaDaUtil.java | 321 +++++++++++ src/main/resources/logback-spring.xml | 39 ++ 9 files changed, 1973 insertions(+), 142 deletions(-) create mode 100644 src/main/java/com/example/sso/controller/FddFileHeTong.java create mode 100644 src/main/java/com/example/sso/controller/TuTest.java create mode 100644 src/main/java/com/example/sso/dao/FddFileId.java create mode 100644 src/main/java/com/example/sso/test/R.java create mode 100644 src/main/resources/logback-spring.xml diff --git a/pom.xml b/pom.xml index 67580f9..2d1df83 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,12 @@ 0.4.20 + + org.projectlombok + lombok + true + + diff --git a/src/main/java/com/example/sso/controller/FddFileHeTong.java b/src/main/java/com/example/sso/controller/FddFileHeTong.java new file mode 100644 index 0000000..9b8b184 --- /dev/null +++ b/src/main/java/com/example/sso/controller/FddFileHeTong.java @@ -0,0 +1,221 @@ +package com.example.sso.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.example.sso.dao.FddFileId; +import com.example.sso.test.J; +import com.example.sso.util.FDaDaUtil; +import lombok.extern.log4j.Log4j; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Slf4j +@Async +public class FddFileHeTong { + + public static void main(String[] args) throws Exception { + + String flowDepartment = "银建"; + + + //创建签署任务 + JSONObject initiator = new JSONObject(); + JSONObject openid = new JSONObject(); + openid.put("idType", "corp"); + openid.put("openId", "625776ecae6742cb8eb710beedef9b4c"); + initiator.put("initiator", openid); + + initiator.put("signTaskSubject", "汽车租赁合同" + "$" + "flowName" + "$" + "flowContractno"); + + + + + + initiator.put("businessId", "a09900c24614bd4c1de10c55712a3e0e"); + //参与方数组 + JSONArray jsonArray = new JSONArray(); + JSONObject ownerId = new JSONObject(); // docid + ownerId.put("ownerId", openid); + ownerId.put("signTemplateId", "1767841802943145947"); + String ownerIdJSONString = ownerId.toJSONString(); + String doc = FDaDaUtil.doc(ownerIdJSONString); + + //actor个人对象 + JSONObject actor = new JSONObject(); + //actor详细信息个人 + JSONObject actorlist = new JSONObject(); + actorlist.put("actorId", "参与方2"); + actorlist.put("actorType", "person"); + + actorlist.put("actorName", "李嘉卓"); + + JSONArray permissions = new JSONArray(); + permissions.add("sign"); + + actorlist.put("identNameForMatch", "李嘉卓"); + + actorlist.put("certType", "id_card"); + + // actorlist.put("certNoForMatch", "130283199705306053"); + + + actorlist.put("notifyAddress", "15232585208"); + + JSONArray notifyType = new JSONArray(); + notifyType.add("start"); + notifyType.add("finish"); + actorlist.put("notifyType", notifyType); + actorlist.put("permissions", permissions); + + JSONArray signFieldsgeren = new JSONArray(); + JSONObject jsonObject55 = new JSONObject(); + jsonObject55.put("fieldDocId",doc); + jsonObject55.put("fieldId","4100411846"); + signFieldsgeren.add(jsonObject55); + + + actor.put("actor", actorlist); + actor.put("signFields",signFieldsgeren); + + + //企业方对象 + JSONObject actors = new JSONObject(); + //actor详细信息企业 + JSONObject actorlists = new JSONObject(); + actorlists.put("actorId", "参与方1"); + actorlists.put("actorType", "corp"); + + actorlists.put("actorName", "flowPaname"); + + /*JSONArray permissionss = new JSONArray(); + permissionss.add("sign"); + actorlists.put("permissions",permissionss);*/ + if (!flowDepartment.equals("银建新能源")) { + actorlists.put("actorOpenId", "625776ecae6742cb8eb710beedef9b4c"); + String entryids = FDaDaUtil.entryids("北京银建实业股份有限公司"); + actorlists.put("actorEntityId", entryids); + } else if (flowDepartment.equals("银建新能源")) { + actorlists.put("actorOpenId", "a0c12949a1c54ff9bfa45dbe957fbc5d"); + } + /*actorlists.put("notifyAddress", "13520145209");*/ + JSONArray notifyTypes = new JSONArray(); + notifyTypes.add("start"); + notifyTypes.add("finish"); + actorlists.put("notifyType", notifyTypes); + JSONArray objects = new JSONArray(); + objects.add("sign"); + actorlists.put("permissions", objects); + JSONArray SignField = new JSONArray(); + JSONObject jsonObject2 = new JSONObject(); + + + + + jsonObject2.put("fieldDocId", doc); + + + if (flowDepartment.equals("银建")) { + jsonObject2.put("sealId", 1705990704393128941l); + + jsonObject2.put("fieldId", "8342392107"); + + } else if (flowDepartment.equals("金建")) { + jsonObject2.put("sealId", 1705991374867130717l); + jsonObject2.put("fieldId", "8342392107"); + + } else if (flowDepartment.equals("金银建")) { + jsonObject2.put("sealId", 1705991362754131529l); + jsonObject2.put("fieldId", "8342392107");; + + } else if (flowDepartment.equals("华建")) { + jsonObject2.put("sealId", 1705991079845184562l); + jsonObject2.put("fieldId", "8342392107"); + + } else if (flowDepartment.equals("银建新能源")) { + jsonObject2.put("sealId", 1706510414541115296l); + jsonObject2.put("fieldId", "8342392107"); + + } + + + + + + + SignField.add(jsonObject2); + + JSONObject signConfigInfo = new JSONObject(); + JSONObject signConfigInfos = new JSONObject(); + signConfigInfos.put("requestVerifyFree", true); + signConfigInfo.put("signConfigInfo", signConfigInfo); + + + actors.put("actor", actorlists); + actors.put("signFields", SignField); + actors.put("signConfigInfo", signConfigInfos); + + + jsonArray.add(actor); + jsonArray.add(actors); + + + JSONArray docs = new JSONArray(); + + JSONObject qy = new JSONObject(); + qy.put("docId",doc); + qy.put("docName","文件文档"); + String id = FddFileId.id(""); + qy.put("docFileId",id); + JSONArray docFields = new JSONArray(); + + JSONObject yiye = new JSONObject(); + yiye.put("fieldId","8342392107"); + yiye.put("fieldName","签章"); + JSONObject position = new JSONObject(); + position.put("positionMode","keyword"); + position.put("positionKeyword","盖章"); + yiye.put("position",position); + yiye.put("moveable","false"); + yiye.put("fieldType","corp_seal"); + + docFields.add(yiye); + + + JSONObject yiyes = new JSONObject(); + yiyes.put("fieldId","4100411846"); + yiyes.put("fieldName","签字"); + JSONObject positions = new JSONObject(); + positions.put("positionMode","keyword"); + positions.put("positionKeyword","签字"); + yiyes.put("position",positions); + yiyes.put("moveable","false"); + yiyes.put("fieldType","person_sign"); + + docFields.add(yiyes); + + qy.put("docFields",docFields); + + docs.add(qy); + initiator.put("docs", docs); + + + initiator.put("actors", jsonArray); + String jsonString = initiator.toJSONString(); + log.info("我是参数 " + jsonString); + + String fdd = FDaDaUtil.fdds(jsonString); + log.info("车损明细文件生成:" + fdd); + JSONObject jsonObject = JSON.parseObject(fdd); + //任务id + String signTaskId = jsonObject.getJSONObject("data").getString("signTaskId"); + String signTaskIds = String.valueOf(jsonObject.getJSONObject("data")); + System.out.println("signTaskId____________________" + signTaskId); + System.out.println("signTaskIds========================" + signTaskIds); + String signtask = FDaDaUtil.signtask(signTaskIds); + log.info("车损明细文件生成完成" + signtask); + + } +} diff --git a/src/main/java/com/example/sso/controller/TuTest.java b/src/main/java/com/example/sso/controller/TuTest.java new file mode 100644 index 0000000..2d85b9c --- /dev/null +++ b/src/main/java/com/example/sso/controller/TuTest.java @@ -0,0 +1,446 @@ +package com.example.sso.controller; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.example.sso.dao.FddFileId; +import com.example.sso.dao.Photo; +import com.example.sso.dao.ThumbnailCompressor; +import com.example.sso.util.APIUtils; +import com.example.sso.util.FDaDaUtil; +import com.example.sso.util.TimeUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Async; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@Async +@RestController +@Slf4j +public class TuTest { + + @PostMapping("/tz1") + public void yuezu(@RequestBody JSONObject data) throws Exception { + + log.info("退租数据" + data.toJSONString()); + + JSONObject object = data.getJSONObject("data"); + String id = object.getString("_id"); + String car = object.getString("car"); + String sj = object.getString("sj"); + String timss = TimeUtil.timss(sj); + Integer gl = object.getInteger("gl"); + Integer dl = object.getInteger("dl"); + JSONArray mx = object.getJSONArray("mx"); + JSONArray yz = object.getJSONArray("yz"); + JSONArray cj = object.getJSONArray("cj"); + + String jsyss = object.getString("jsyss"); + String name = object.getString("name"); + String phone = object.getString("phone"); + String id1 = object.getString("id1"); + String a = object.getString("a"); + + String zq = object.getString("zq"); + String zh = object.getString("zh"); + String yq = object.getString("yq"); + String yh = object.getString("yh"); + String fs = object.getString("fs"); + + + String ww = object.getString("ww"); + + String wws = "姓名/联营方公司: " + ww; + String cars = "车牌号码:" + car; + String gls = "车辆公里数(KM): " + gl.toString(); + String dls = "车辆剩余电量(KM): " + dl.toString(); + String sjs = "验车时间:" + timss; + Photo.startPDF("/home/java/dpapp8090/pdf/" + id + ".pdf"); + Photo.TextAlignment(" 交车定损单"); + Photo.appendTextSection(" 驾驶员信息"); + Photo.appendTextSection(" " +wws); + Photo.appendTextSection(" 车辆信息"); + + Photo.appendTextSection(" " +cars); + Photo.appendTextSection(" " +gls); + Photo.appendTextSection(" "+dls); + Photo.appendTextSection(" "+sjs); + + Photo.appendTextSection(" 车辆整体照片"); + + + for (Object yzs : yz) { + JSONObject jsonObject = (JSONObject) yzs; + String url = jsonObject.getString("url"); + String hkfile = APIUtils.hkfile(url); + ThumbnailCompressor.compressWithThumbnailator(hkfile, hkfile); + Photo.appendImageSection(hkfile); + + } + + Photo.appendTextSection(" 车架号照片"); + + for (Object yzs : cj) { + JSONObject jsonObject = (JSONObject) yzs; + String url = jsonObject.getString("url"); + String hkfile = APIUtils.hkfile(url); + ThumbnailCompressor.compressWithThumbnailator(hkfile, hkfile); + Photo.appendImageSection(hkfile); + + } + + + + + + for (Object o : mx) { + + JSONObject test = (JSONObject) o; + String xiang = test.getString("xiang"); + + String xiangs = "验车受损项:" + xiang; + + + + Photo.appendTextSection(" " +xiangs); + + JSONArray tp = test.getJSONArray("tp"); + if (tp != null && tp.size() != 0) { + for (Object o1 : tp) { + JSONObject tests = (JSONObject) o1; + String url = tests.getString("url"); + String hkfile = APIUtils.hkfile(url); + ThumbnailCompressor.compressWithThumbnailator(hkfile, hkfile); + Photo.appendTextSection(" 车损详情图片:"); + Photo.appendImageSection(hkfile); + } + } + + + + + + } + + Photo.appendTextSections(" 签字"); + Photo.appendTextSections1("驾驶员/联营负责人签名:"); + Photo.appendTextSectionss(" 盖章"); + Photo.appendTextSectionss1("定损单位落章:"); + + + + + + Photo.closePDF(); + + + + + //创建签署任务 + JSONObject initiator = new JSONObject(); + JSONObject openid = new JSONObject(); + openid.put("idType", "corp"); + openid.put("openId", "625776ecae6742cb8eb710beedef9b4c"); + initiator.put("initiator", openid); + + initiator.put("signTaskSubject", "交车定损单"); + + + + + + initiator.put("businessId", "a09900c24614bd4c1de10c55712a3e0e"); + //参与方数组 + JSONArray jsonArray = new JSONArray(); + JSONObject ownerId = new JSONObject(); // docid + ownerId.put("ownerId", openid); + ownerId.put("signTemplateId", "1767841802943145947"); + String ownerIdJSONString = ownerId.toJSONString(); + String doc = FDaDaUtil.doc(ownerIdJSONString); + + //actor个人对象 + JSONObject actor = new JSONObject(); + //actor详细信息个人 + JSONObject actorlist = new JSONObject(); + actorlist.put("actorId", "参与方2"); + actorlist.put("actorType", "person"); + + actorlist.put("actorName", name); + + JSONArray permissions = new JSONArray(); + permissions.add("sign"); + + actorlist.put("identNameForMatch", name); + + actorlist.put("certType", "id_card"); + + actorlist.put("certNoForMatch", id1); + + + actorlist.put("notifyAddress", phone); + + JSONArray notifyType = new JSONArray(); + notifyType.add("start"); + notifyType.add("finish"); + actorlist.put("notifyType", notifyType); + actorlist.put("permissions", permissions); + + JSONArray signFieldsgeren = new JSONArray(); + JSONObject jsonObject55 = new JSONObject(); + jsonObject55.put("fieldDocId",doc); + jsonObject55.put("fieldName","签字"); + signFieldsgeren.add(jsonObject55); + + + actor.put("actor", actorlist); + actor.put("signFields",signFieldsgeren); + + + + + + jsonArray.add(actor); + + + + JSONArray docs = new JSONArray(); + + JSONObject qy = new JSONObject(); + qy.put("docId",doc); + qy.put("docName","文件文档"); + String ided = FddFileId.id("/home/java/dpapp8090/pdf/" + id + ".pdf"); + qy.put("docFileId",ided); + JSONArray docFields = new JSONArray(); + + + + + JSONObject yiyes = new JSONObject(); + yiyes.put("fieldId","4100411846"); + yiyes.put("fieldName","签字"); + JSONObject positions = new JSONObject(); + positions.put("positionMode","keyword"); + positions.put("positionKeyword","签字"); + yiyes.put("position",positions); + yiyes.put("moveable","false"); + yiyes.put("fieldType","person_sign"); + + docFields.add(yiyes); + + qy.put("docFields",docFields); + + docs.add(qy); + initiator.put("docs", docs); + + + initiator.put("actors", jsonArray); + String jsonString = initiator.toJSONString(); + log.info("我是参数 " + jsonString); + + String fdd = FDaDaUtil.fdds(jsonString); + log.info("车损明细文件生成:" + fdd); + JSONObject jsonObject = JSON.parseObject(fdd); + //任务id + String signTaskId = jsonObject.getJSONObject("data").getString("signTaskId"); + String signTaskIds = String.valueOf(jsonObject.getJSONObject("data")); + System.out.println("signTaskId____________________" + signTaskId); + System.out.println("signTaskIds========================" + signTaskIds); + String signtask = FDaDaUtil.signtask(signTaskIds); + log.info("车损明细文件生成完成" + signtask); + + + + if (true){ + Photo.startPDF("/home/java/dpapp8090/pdf/" + id + "a" + ".pdf"); + Photo.TextAlignment(" 交车验收单"); + Photo.appendTextSection(" 车号: " + car + " " + "所属分司: " + fs); + + + +// Photo.appendTextSection("驾驶员信息"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection(wws); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("车辆信息"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection(cars); +// Photo.appendTextSection(gls); +// Photo.appendTextSection(dls); +// Photo.appendTextSection(sjs); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("车辆整体照片"); + + + for (Object yzs : mx) { + JSONObject jsonObject12 = (JSONObject) yzs; + String xiang = jsonObject12.getString("xiang"); + Double jine = jsonObject12.getDouble("jine"); + String bz = jsonObject12.getString("bz"); + Photo.appendTextSection(" 项目: " +xiang + " " + " 金额: " + jine + " 备注: " + bz ); + + + + + + } + + + Photo.appendTextSection(" 备注: "); + + Photo.appendTextSection(" 左前轮: " + zq); + + Photo.appendTextSection(" 左后轮: " + zh); + + Photo.appendTextSection(" 右前轮: " + yq); + + Photo.appendTextSection(" 右后轮: " + yh); + + Photo.appendTextSection(" 行驶里程(KM): " + gl); + + Photo.appendTextSection(" 剩余电量(KM):" + dl); + + + Photo.appendTextSections(" 签字"); + Photo.appendTextSections1("驾驶员/联营负责人签名:"); + Photo.appendTextSectionss(" 盖章"); + Photo.appendTextSectionss1("定损单位落章:"); + + + + + + Photo.closePDF(); + + + + + //创建签署任务 + JSONObject initiator12 = new JSONObject(); + JSONObject openid12 = new JSONObject(); + openid12.put("idType", "corp"); + openid12.put("openId", "625776ecae6742cb8eb710beedef9b4c"); + initiator12.put("initiator", openid12); + + initiator12.put("signTaskSubject", "交车验收单"); + + + + + + initiator12.put("businessId", "a09900c24614bd4c1de10c55712a3e0e"); + //参与方数组 + JSONArray jsonArray12 = new JSONArray(); + JSONObject ownerId12 = new JSONObject(); // docid + ownerId12.put("ownerId", openid12); + ownerId12.put("signTemplateId", "1767841802943145947"); + String ownerIdJSONString12 = ownerId12.toJSONString(); + String doc12 = FDaDaUtil.doc(ownerIdJSONString12); + + //actor个人对象 + JSONObject actor12 = new JSONObject(); + //actor详细信息个人 + JSONObject actorlist12 = new JSONObject(); + actorlist12.put("actorId", "参与方2"); + actorlist12.put("actorType", "person"); + + actorlist12.put("actorName", name); + + JSONArray permissions12 = new JSONArray(); + permissions12.add("sign"); + + actorlist12.put("identNameForMatch", name); + + actorlist12.put("certType", "id_card"); + + actorlist12.put("certNoForMatch", id1); + + + actorlist12.put("notifyAddress", phone); + + JSONArray notifyType12 = new JSONArray(); + notifyType12.add("start"); + notifyType12.add("finish"); + actorlist12.put("notifyType", notifyType12); + actorlist12.put("permissions", permissions12); + + JSONArray signFieldsgeren12 = new JSONArray(); + JSONObject jsonObject5512 = new JSONObject(); + jsonObject5512.put("fieldDocId",doc12); + jsonObject5512.put("fieldName","签字"); + signFieldsgeren12.add(jsonObject5512); + + + actor12.put("actor", actorlist12); + actor12.put("signFields",signFieldsgeren12); + + + + + jsonArray12.add(actor12); + + + + JSONArray docs12 = new JSONArray(); + + JSONObject qy12 = new JSONObject(); + qy12.put("docId",doc12); + qy12.put("docName","文件文档"); + String ided12 = FddFileId.id("/home/java/dpapp8090/pdf/" + id + "a"+ ".pdf"); + qy12.put("docFileId",ided12); + JSONArray docFields12 = new JSONArray(); + + + + + JSONObject yiyes12 = new JSONObject(); + yiyes12.put("fieldId","4100411846"); + yiyes12.put("fieldName","签字"); + JSONObject positions12 = new JSONObject(); + positions12.put("positionMode","keyword"); + positions12.put("positionKeyword","签字"); + yiyes12.put("position",positions12); + yiyes12.put("moveable","false"); + yiyes12.put("fieldType","person_sign"); + + docFields12.add(yiyes12); + + qy12.put("docFields",docFields12); + + docs12.add(qy12); + initiator12.put("docs", docs12); + + + initiator12.put("actors", jsonArray12); + String jsonString12 = initiator12.toJSONString(); + log.info("我是参数a " + jsonString12); + + String fdd12 = FDaDaUtil.fdds(jsonString12); + log.info("车损明细文件生成a:" + fdd12); + JSONObject jsonObject12 = JSON.parseObject(fdd12); + //任务id + String signTaskId12 = jsonObject12.getJSONObject("data").getString("signTaskId"); + String signTaskIds12 = String.valueOf(jsonObject12.getJSONObject("data")); + System.out.println("signTaskId____________________" + signTaskId12); + System.out.println("signTaskIds========================" + signTaskIds12); + String signtask12 = FDaDaUtil.signtask(signTaskIds12); + log.info("车损明细文件生成完成a" + signtask12); + + } + + + + + + + + + + + + } +} diff --git a/src/main/java/com/example/sso/controller/TuiZuController.java b/src/main/java/com/example/sso/controller/TuiZuController.java index 5d97663..2c0c1e1 100644 --- a/src/main/java/com/example/sso/controller/TuiZuController.java +++ b/src/main/java/com/example/sso/controller/TuiZuController.java @@ -1,11 +1,14 @@ package com.example.sso.controller; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.example.sso.dao.FddFileId; import com.example.sso.dao.Photo; import com.example.sso.dao.ThumbnailCompressor; import com.example.sso.test.O; import com.example.sso.util.APIUtils; +import com.example.sso.util.FDaDaUtil; import com.example.sso.util.TimeUtil; import com.example.sso.util.TimeUtils; import lombok.extern.slf4j.Slf4j; @@ -22,7 +25,7 @@ import java.io.IOException; public class TuiZuController { @PostMapping("/tz") - public void yuezu(@RequestBody JSONObject data) throws IOException { + public void yuezu(@RequestBody JSONObject data) throws Exception { log.info("退租数据" + data.toJSONString()); @@ -37,6 +40,19 @@ public class TuiZuController { JSONArray yz = object.getJSONArray("yz"); JSONArray cj = object.getJSONArray("cj"); + String jsyss = object.getString("jsyss"); + String name = object.getString("name"); + String phone = object.getString("phone"); + String id1 = object.getString("id1"); + String a = object.getString("a"); + + String zq = object.getString("zq"); + String zh = object.getString("zh"); + String yq = object.getString("yq"); + String yh = object.getString("yh"); + String fs = object.getString("fs"); + + String ww = object.getString("ww"); String wws = "姓名/联营方公司: " + ww; @@ -45,24 +61,17 @@ public class TuiZuController { String dls = "车辆剩余电量(KM): " + dl.toString(); String sjs = "验车时间:" + timss; Photo.startPDF("/home/java/dpapp8090/pdf/" + id + ".pdf"); - Photo.TextAlignment("交车定损单"); - Photo.appendTextSection("\n"); - Photo.appendTextSection("驾驶员信息"); - Photo.appendTextSection("\n"); - Photo.appendTextSection(wws); - Photo.appendTextSection("\n"); - Photo.appendTextSection("\n"); - Photo.appendTextSection("\n"); - Photo.appendTextSection("车辆信息"); - Photo.appendTextSection("\n"); - Photo.appendTextSection(cars); - Photo.appendTextSection(gls); - Photo.appendTextSection(dls); - Photo.appendTextSection(sjs); - Photo.appendTextSection("\n"); - Photo.appendTextSection("\n"); - Photo.appendTextSection("\n"); - Photo.appendTextSection("车辆整体照片"); + Photo.TextAlignment(" 交车定损单"); + Photo.appendTextSection(" 驾驶员信息"); + Photo.appendTextSection(" " +wws); + Photo.appendTextSection(" 车辆信息"); + + Photo.appendTextSection(" " +cars); + Photo.appendTextSection(" " +gls); + Photo.appendTextSection(" "+dls); + Photo.appendTextSection(" "+sjs); + + Photo.appendTextSection(" 车辆整体照片"); for (Object yzs : yz) { @@ -74,7 +83,7 @@ public class TuiZuController { } - Photo.appendTextSection("车架号照片"); + Photo.appendTextSection(" 车架号照片"); for (Object yzs : cj) { JSONObject jsonObject = (JSONObject) yzs; @@ -85,9 +94,7 @@ public class TuiZuController { } - Photo.appendTextSection("\n"); - Photo.appendTextSection("\n"); - Photo.appendTextSection("\n"); + @@ -100,7 +107,7 @@ public class TuiZuController { - Photo.appendTextSection(xiangs); + Photo.appendTextSection(" " +xiangs); JSONArray tp = test.getJSONArray("tp"); if (tp != null && tp.size() != 0) { @@ -109,23 +116,504 @@ public class TuiZuController { String url = tests.getString("url"); String hkfile = APIUtils.hkfile(url); ThumbnailCompressor.compressWithThumbnailator(hkfile, hkfile); - Photo.appendTextSection("车损详情图片:"); - Photo.appendTextSection("\n"); + Photo.appendTextSection(" 车损详情图片:"); Photo.appendImageSection(hkfile); } } - Photo.appendTextSection("\n"); + } + Photo.appendTextSections(" 签字"); + Photo.appendTextSections1("驾驶员/联营负责人签名:"); + Photo.appendTextSectionss(" 盖章"); + Photo.appendTextSectionss1("定损单位落章:"); + Photo.closePDF(); + + + + //创建签署任务 + JSONObject initiator = new JSONObject(); + JSONObject openid = new JSONObject(); + openid.put("idType", "corp"); + openid.put("openId", "625776ecae6742cb8eb710beedef9b4c"); + initiator.put("initiator", openid); + + initiator.put("signTaskSubject", "交车定损单"); + + + + + + initiator.put("businessId", "a09900c24614bd4c1de10c55712a3e0e"); + //参与方数组 + JSONArray jsonArray = new JSONArray(); + JSONObject ownerId = new JSONObject(); // docid + ownerId.put("ownerId", openid); + ownerId.put("signTemplateId", "1767841802943145947"); + String ownerIdJSONString = ownerId.toJSONString(); + String doc = FDaDaUtil.doc(ownerIdJSONString); + + //actor个人对象 + JSONObject actor = new JSONObject(); + //actor详细信息个人 + JSONObject actorlist = new JSONObject(); + actorlist.put("actorId", "参与方2"); + actorlist.put("actorType", "person"); + + actorlist.put("actorName", name); + + JSONArray permissions = new JSONArray(); + permissions.add("sign"); + + actorlist.put("identNameForMatch", name); + + actorlist.put("certType", "id_card"); + + actorlist.put("certNoForMatch", id1); + + + actorlist.put("notifyAddress", phone); + + JSONArray notifyType = new JSONArray(); + notifyType.add("start"); + notifyType.add("finish"); + actorlist.put("notifyType", notifyType); + actorlist.put("permissions", permissions); + + JSONArray signFieldsgeren = new JSONArray(); + JSONObject jsonObject55 = new JSONObject(); + jsonObject55.put("fieldDocId",doc); + jsonObject55.put("fieldName","签字"); + signFieldsgeren.add(jsonObject55); + + + actor.put("actor", actorlist); + actor.put("signFields",signFieldsgeren); + + + //企业方对象 + JSONObject actors = new JSONObject(); + //actor详细信息企业 + JSONObject actorlists = new JSONObject(); + actorlists.put("actorId", "参与方1"); + actorlists.put("actorType", "corp"); + + actorlists.put("actorName", a); + + /*JSONArray permissionss = new JSONArray(); + permissionss.add("sign"); + actorlists.put("permissions",permissionss);*/ + if (!jsyss.equals("银建新能源")) { + actorlists.put("actorOpenId", "625776ecae6742cb8eb710beedef9b4c"); + String entryids = FDaDaUtil.entryids(a); + actorlists.put("actorEntityId", entryids); + } else if (jsyss.equals("银建新能源")) { + actorlists.put("actorOpenId", "a0c12949a1c54ff9bfa45dbe957fbc5d"); + } + /*actorlists.put("notifyAddress", "13520145209");*/ + JSONArray notifyTypes = new JSONArray(); + notifyTypes.add("start"); + notifyTypes.add("finish"); + actorlists.put("notifyType", notifyTypes); + JSONArray objects = new JSONArray(); + objects.add("sign"); + actorlists.put("permissions", objects); + JSONArray SignField = new JSONArray(); + JSONObject jsonObject2 = new JSONObject(); + + + + + jsonObject2.put("fieldDocId", doc); + + + if (jsyss.equals("银建")) { + jsonObject2.put("sealId", 1705990704393128941l); + + jsonObject2.put("fieldName", "签章"); + + } else if (jsyss.equals("金建")) { + jsonObject2.put("sealId", 1705991374867130717l); + jsonObject2.put("fieldName", "签章"); + + } else if (jsyss.equals("金银建")) { + jsonObject2.put("sealId", 1705991362754131529l); + jsonObject2.put("fieldName", "签章");; + + } else if (jsyss.equals("华建")) { + jsonObject2.put("sealId", 1705991079845184562l); + jsonObject2.put("fieldName", "签章"); + + } else if (jsyss.equals("银建新能源")) { + jsonObject2.put("sealId", 1706510414541115296l); + jsonObject2.put("fieldName", "签章"); + + } + + + + + + + SignField.add(jsonObject2); + + JSONObject signConfigInfo = new JSONObject(); + JSONObject signConfigInfos = new JSONObject(); + signConfigInfos.put("requestVerifyFree", true); + signConfigInfo.put("signConfigInfo", signConfigInfo); + + + actors.put("actor", actorlists); + actors.put("signFields", SignField); + actors.put("signConfigInfo", signConfigInfos); + + + jsonArray.add(actor); + jsonArray.add(actors); + + + JSONArray docs = new JSONArray(); + + JSONObject qy = new JSONObject(); + qy.put("docId",doc); + qy.put("docName","文件文档"); + String ided = FddFileId.id("/home/java/dpapp8090/pdf/" + id + ".pdf"); + qy.put("docFileId",ided); + JSONArray docFields = new JSONArray(); + + JSONObject yiye = new JSONObject(); + yiye.put("fieldId","8342392107"); + yiye.put("fieldName","签章"); + JSONObject position = new JSONObject(); + position.put("positionMode","keyword"); + position.put("positionKeyword","盖章"); + yiye.put("position",position); + yiye.put("moveable","false"); + yiye.put("fieldType","corp_seal"); + + docFields.add(yiye); + + + JSONObject yiyes = new JSONObject(); + yiyes.put("fieldId","4100411846"); + yiyes.put("fieldName","签字"); + JSONObject positions = new JSONObject(); + positions.put("positionMode","keyword"); + positions.put("positionKeyword","签字"); + yiyes.put("position",positions); + yiyes.put("moveable","false"); + yiyes.put("fieldType","person_sign"); + + docFields.add(yiyes); + + qy.put("docFields",docFields); + + docs.add(qy); + initiator.put("docs", docs); + + + initiator.put("actors", jsonArray); + String jsonString = initiator.toJSONString(); + log.info("我是参数 " + jsonString); + + String fdd = FDaDaUtil.fdds(jsonString); + log.info("车损明细文件生成:" + fdd); + JSONObject jsonObject = JSON.parseObject(fdd); + //任务id + String signTaskId = jsonObject.getJSONObject("data").getString("signTaskId"); + String signTaskIds = String.valueOf(jsonObject.getJSONObject("data")); + System.out.println("signTaskId____________________" + signTaskId); + System.out.println("signTaskIds========================" + signTaskIds); + String signtask = FDaDaUtil.signtask(signTaskIds); + log.info("车损明细文件生成完成" + signtask); + + + + if (true){ + Photo.startPDF("/home/java/dpapp8090/pdf/" + id + "a" + ".pdf"); + Photo.TextAlignment(" 交车验收单"); + Photo.appendTextSection(" 车号: " + car + " " + "所属分司: " + fs); + + + +// Photo.appendTextSection("驾驶员信息"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection(wws); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("车辆信息"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection(cars); +// Photo.appendTextSection(gls); +// Photo.appendTextSection(dls); +// Photo.appendTextSection(sjs); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("\n"); +// Photo.appendTextSection("车辆整体照片"); + + + for (Object yzs : mx) { + JSONObject jsonObject12 = (JSONObject) yzs; + String xiang = jsonObject12.getString("xiang"); + Double jine = jsonObject12.getDouble("jine"); + String bz = jsonObject12.getString("bz"); + Photo.appendTextSection(" 项目: " +xiang + " " + " 金额: " + jine + " 备注: " + bz ); + + + + + + } + + + Photo.appendTextSection(" 备注: "); + + Photo.appendTextSection(" 左前轮: " + zq); + + Photo.appendTextSection(" 左后轮: " + zh); + + Photo.appendTextSection(" 右前轮: " + yq); + + Photo.appendTextSection(" 右后轮: " + yh); + + Photo.appendTextSection(" 行驶里程(KM): " + gl); + + Photo.appendTextSection(" 剩余电量(KM):" + dl); + + + Photo.appendTextSections(" 签字"); + Photo.appendTextSections1("驾驶员/联营负责人签名:"); + Photo.appendTextSectionss(" 盖章"); + Photo.appendTextSectionss1("定损单位落章:"); + + + + + + Photo.closePDF(); + + + + + //创建签署任务 + JSONObject initiator12 = new JSONObject(); + JSONObject openid12 = new JSONObject(); + openid12.put("idType", "corp"); + openid12.put("openId", "625776ecae6742cb8eb710beedef9b4c"); + initiator12.put("initiator", openid12); + + initiator12.put("signTaskSubject", "交车验收单"); + + + + + + initiator12.put("businessId", "a09900c24614bd4c1de10c55712a3e0e"); + //参与方数组 + JSONArray jsonArray12 = new JSONArray(); + JSONObject ownerId12 = new JSONObject(); // docid + ownerId12.put("ownerId", openid12); + ownerId12.put("signTemplateId", "1767841802943145947"); + String ownerIdJSONString12 = ownerId12.toJSONString(); + String doc12 = FDaDaUtil.doc(ownerIdJSONString12); + + //actor个人对象 + JSONObject actor12 = new JSONObject(); + //actor详细信息个人 + JSONObject actorlist12 = new JSONObject(); + actorlist12.put("actorId", "参与方2"); + actorlist12.put("actorType", "person"); + + actorlist12.put("actorName", name); + + JSONArray permissions12 = new JSONArray(); + permissions12.add("sign"); + + actorlist12.put("identNameForMatch", name); + + actorlist12.put("certType", "id_card"); + + actorlist12.put("certNoForMatch", id1); + + + actorlist12.put("notifyAddress", phone); + + JSONArray notifyType12 = new JSONArray(); + notifyType12.add("start"); + notifyType12.add("finish"); + actorlist12.put("notifyType", notifyType12); + actorlist12.put("permissions", permissions12); + + JSONArray signFieldsgeren12 = new JSONArray(); + JSONObject jsonObject5512 = new JSONObject(); + jsonObject5512.put("fieldDocId",doc12); + jsonObject5512.put("fieldName","签字"); + signFieldsgeren12.add(jsonObject5512); + + + actor12.put("actor", actorlist12); + actor12.put("signFields",signFieldsgeren12); + + + //企业方对象 + JSONObject actors12 = new JSONObject(); + //actor详细信息企业 + JSONObject actorlists12 = new JSONObject(); + actorlists12.put("actorId", "参与方1"); + actorlists12.put("actorType", "corp"); + + actorlists12.put("actorName", a); + + /*JSONArray permissionss = new JSONArray(); + permissionss.add("sign"); + actorlists.put("permissions",permissionss);*/ + if (!jsyss.equals("银建新能源")) { + actorlists12.put("actorOpenId", "625776ecae6742cb8eb710beedef9b4c"); + String entryids = FDaDaUtil.entryids(a); + actorlists12.put("actorEntityId", entryids); + } else if (jsyss.equals("银建新能源")) { + actorlists12.put("actorOpenId", "a0c12949a1c54ff9bfa45dbe957fbc5d"); + } + /*actorlists.put("notifyAddress", "13520145209");*/ + JSONArray notifyTypes12 = new JSONArray(); + notifyTypes12.add("start"); + notifyTypes12.add("finish"); + actorlists12.put("notifyType", notifyTypes12); + JSONArray objects12 = new JSONArray(); + objects12.add("sign"); + actorlists12.put("permissions", objects12); + JSONArray SignField12 = new JSONArray(); + JSONObject jsonObject212 = new JSONObject(); + + + + + jsonObject212.put("fieldDocId", doc12); + + + if (jsyss.equals("银建")) { + jsonObject212.put("sealId", 1705990704393128941l); + + jsonObject212.put("fieldName", "签章"); + + } else if (jsyss.equals("金建")) { + jsonObject212.put("sealId", 1705991374867130717l); + jsonObject212.put("fieldName", "签章"); + + } else if (jsyss.equals("金银建")) { + jsonObject212.put("sealId", 1705991362754131529l); + jsonObject212.put("fieldName", "签章");; + + } else if (jsyss.equals("华建")) { + jsonObject212.put("sealId", 1705991079845184562l); + jsonObject212.put("fieldName", "签章"); + + } else if (jsyss.equals("银建新能源")) { + jsonObject212.put("sealId", 1706510414541115296l); + jsonObject212.put("fieldName", "签章"); + + } + + + + + + + SignField12.add(jsonObject212); + + JSONObject signConfigInfo12 = new JSONObject(); + JSONObject signConfigInfos12 = new JSONObject(); + signConfigInfos12.put("requestVerifyFree", true); + signConfigInfo12.put("signConfigInfo", signConfigInfo12); + + + actors12.put("actor", actorlists12); + actors12.put("signFields", SignField12); + actors12.put("signConfigInfo", signConfigInfos12); + + + jsonArray12.add(actor12); + jsonArray12.add(actors12); + + + JSONArray docs12 = new JSONArray(); + + JSONObject qy12 = new JSONObject(); + qy12.put("docId",doc12); + qy12.put("docName","文件文档"); + String ided12 = FddFileId.id("/home/java/dpapp8090/pdf/" + id + "a"+ ".pdf"); + qy12.put("docFileId",ided12); + JSONArray docFields12 = new JSONArray(); + + JSONObject yiye12 = new JSONObject(); + yiye12.put("fieldId","8342392107"); + yiye12.put("fieldName","签章"); + JSONObject position12 = new JSONObject(); + position12.put("positionMode","keyword"); + position12.put("positionKeyword","盖章"); + yiye12.put("position",position12); + yiye12.put("moveable","false"); + yiye12.put("fieldType","corp_seal"); + + docFields12.add(yiye12); + + + JSONObject yiyes12 = new JSONObject(); + yiyes12.put("fieldId","4100411846"); + yiyes12.put("fieldName","签字"); + JSONObject positions12 = new JSONObject(); + positions12.put("positionMode","keyword"); + positions12.put("positionKeyword","签字"); + yiyes12.put("position",positions12); + yiyes12.put("moveable","false"); + yiyes12.put("fieldType","person_sign"); + + docFields12.add(yiyes12); + + qy12.put("docFields",docFields12); + + docs12.add(qy12); + initiator12.put("docs", docs12); + + + initiator12.put("actors", jsonArray12); + String jsonString12 = initiator12.toJSONString(); + log.info("我是参数a " + jsonString12); + + String fdd12 = FDaDaUtil.fdds(jsonString12); + log.info("车损明细文件生成a:" + fdd12); + JSONObject jsonObject12 = JSON.parseObject(fdd12); + //任务id + String signTaskId12 = jsonObject12.getJSONObject("data").getString("signTaskId"); + String signTaskIds12 = String.valueOf(jsonObject12.getJSONObject("data")); + System.out.println("signTaskId____________________" + signTaskId12); + System.out.println("signTaskIds========================" + signTaskIds12); + String signtask12 = FDaDaUtil.signtask(signTaskIds12); + log.info("车损明细文件生成完成a" + signtask12); + + } + + + + + + + + + + + } } diff --git a/src/main/java/com/example/sso/dao/FddFileId.java b/src/main/java/com/example/sso/dao/FddFileId.java new file mode 100644 index 0000000..94eaa7f --- /dev/null +++ b/src/main/java/com/example/sso/dao/FddFileId.java @@ -0,0 +1,75 @@ +package com.example.sso.dao; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.example.sso.util.FDaDaUtil; +import lombok.extern.slf4j.Slf4j; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +@Slf4j +public class FddFileId { + public static String id(String file) throws Exception { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fileType","doc"); + String jsonString = jsonObject.toJSONString(); + + + String files = FDaDaUtil.files(jsonString); + JSONObject jsonObject1 = JSON.parseObject(files); + String string = jsonObject1.getJSONObject("data").getString("uploadUrl"); + + String fddFileUrl = jsonObject1.getJSONObject("data").getString("fddFileUrl"); + + log.info("xxxx " + files); + + final File localFile = new File(file); + URL uploadUrl = new URL(string); + HttpURLConnection connection = (HttpURLConnection) uploadUrl.openConnection(); + connection.setRequestMethod("PUT"); + connection.setRequestProperty("Content-Type", "application/octet-stream"); + connection.setDoOutput(true); + BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream()); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(localFile)); + int readByte = -1; + while ((readByte = bis.read()) != -1) { + bos.write(readByte); + } + bis.close(); + bos.close(); + int responseCode = connection.getResponseCode(); + System.out.println("返回的信息如下:"); + System.out.println(responseCode + ":" + connection.getResponseMessage()); + + JSONObject jsonObject2 = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + JSONObject jsonObject3 = new JSONObject(); + jsonObject3.put("fileType","doc"); + jsonObject3.put("fddFileUrl",fddFileUrl); + jsonObject3.put("fileName","694cd73a46b10f23d91ce48b.pdf"); + jsonArray.add(jsonObject3); + jsonObject2.put("fddFileUrlList",jsonArray); + String jsonString1 = jsonObject2.toJSONString(); + log.info("文件参数 " + jsonString1); + String fileid = FDaDaUtil.fileid(jsonString1); + log.info("文件返沪 "+fileid ); + + JSONObject jsonObject4 = JSON.parseObject(fileid); + JSONObject string1 = jsonObject4.getJSONObject("data"); + JSONArray fileIdList = string1.getJSONArray("fileIdList"); + String a = ""; + for(Object o : fileIdList ){ + JSONObject te = (JSONObject) o; + a = te.getString("fileId"); + + } + System.out.println(a); + return a; + } +} diff --git a/src/main/java/com/example/sso/dao/Photo.java b/src/main/java/com/example/sso/dao/Photo.java index 23d2e64..976932a 100644 --- a/src/main/java/com/example/sso/dao/Photo.java +++ b/src/main/java/com/example/sso/dao/Photo.java @@ -2,87 +2,182 @@ package com.example.sso.dao; import com.itextpdf.io.image.ImageData; import com.itextpdf.io.image.ImageDataFactory; +import com.itextpdf.kernel.colors.DeviceRgb; import com.itextpdf.kernel.font.PdfFont; import com.itextpdf.kernel.font.PdfFontFactory; import com.itextpdf.kernel.geom.PageSize; +import com.itextpdf.kernel.geom.Rectangle; import com.itextpdf.kernel.pdf.PdfDocument; import com.itextpdf.kernel.pdf.PdfWriter; +import com.itextpdf.kernel.pdf.canvas.PdfCanvas; +import com.itextpdf.layout.Canvas; import com.itextpdf.layout.Document; import com.itextpdf.layout.element.Image; import com.itextpdf.layout.element.Paragraph; import com.itextpdf.layout.properties.TextAlignment; +import com.itextpdf.layout.properties.VerticalAlignment; +import com.itextpdf.kernel.events.PdfDocumentEvent; +import com.itextpdf.kernel.events.IEventHandler; +import com.itextpdf.kernel.events.Event; import java.io.File; import java.io.IOException; -import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; public class Photo { + // 使用 ThreadLocal 存储每个线程的独立变量 + private static final ThreadLocal pdfDocThreadLocal = new ThreadLocal<>(); + private static final ThreadLocal documentThreadLocal = new ThreadLocal<>(); + private static final ThreadLocal currentPdfPathThreadLocal = new ThreadLocal<>(); + private static final ThreadLocal chineseFontThreadLocal = new ThreadLocal<>(); - private static PdfDocument pdfDoc = null; - private static Document document = null; - private static String currentPdfPath = null; + // 存储每页的页脚文本(使用ThreadLocal确保线程安全) + private static final ThreadLocal> footerTextsThreadLocal = new ThreadLocal<>(); + + // 页脚文本类 + private static class FooterText { + String text; + float x; + float y; + DeviceRgb color; + + FooterText(String text, float x, float y, DeviceRgb color) { + this.text = text; + this.x = x; + this.y = y; + this.color = color; + } + } + + // 页脚事件处理器 + private static class FooterEventHandler implements IEventHandler { + @Override + public void handleEvent(Event event) { + PdfDocumentEvent docEvent = (PdfDocumentEvent) event; + PdfCanvas canvas = new PdfCanvas(docEvent.getPage()); + Rectangle pageSize = docEvent.getPage().getPageSize(); + + // 获取当前线程的字体和页脚文本 + PdfFont chineseFont = chineseFontThreadLocal.get(); + List footerTexts = footerTextsThreadLocal.get(); + + if (chineseFont == null || footerTexts == null || footerTexts.isEmpty()) { + canvas.release(); + return; + } + + // 创建Canvas用于绘制 + Canvas pageCanvas = new Canvas(canvas, pageSize); + + // 绘制所有页脚文本 + for (FooterText footerText : footerTexts) { + Paragraph paragraph = new Paragraph(footerText.text) + .setFont(chineseFont) + .setFontSize(12); + + if (footerText.color != null) { + paragraph.setFontColor(footerText.color); + } + + // 在指定位置绘制文本 + pageCanvas.showTextAligned( + paragraph, + footerText.x, + footerText.y, + TextAlignment.LEFT, + VerticalAlignment.BOTTOM + ); + } + + canvas.release(); + } + } /** * 开始创建PDF */ public static void startPDF(String pdfPath) throws IOException { - if (pdfDoc != null) { + // 获取当前线程的变量 + PdfDocument pdfDoc = pdfDocThreadLocal.get(); + Document document = documentThreadLocal.get(); + + // 如果已经存在,先关闭 + if (pdfDoc != null || document != null) { closePDF(); } - /* currentPdfPath = pdfPath; + // 创建新的PDF文档 + currentPdfPathThreadLocal.set(pdfPath); PdfWriter writer = new PdfWriter(pdfPath); pdfDoc = new PdfDocument(writer); - // document = new Document(pdfDoc); - // 创建文档时设置0边距 + + // 注册页脚事件处理器 + FooterEventHandler footerHandler = new FooterEventHandler(); + pdfDoc.addEventHandler(PdfDocumentEvent.END_PAGE, footerHandler); + + // 使用标准A4纸 document = new Document(pdfDoc, PageSize.A4, false); - - // 设置页边距为0 - document.setMargins(0, 0, 0, 0); - // 或者使用具体的值 - // document.setMargins(0f, 0f, 0f, 0f); - - // 移除默认的页眉页脚 - pdfDoc.getDefaultPageSize();*/ - - - - currentPdfPath = pdfPath; - PdfWriter writer = new PdfWriter(pdfPath); - pdfDoc = new PdfDocument(writer); - - // A4纸的标准宽度是595点(约210mm),高度自定义 - // PageSize.A4.getWidth() 获取A4宽度 - PageSize customPageSize = new PageSize(PageSize.A4.getWidth(), 842*20); - - document = new Document(pdfDoc, customPageSize, false); document.setMargins(0, 0, 0, 0); + // 初始化中文字体 + PdfFont chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + // 初始化页脚文本列表 + footerTextsThreadLocal.set(new ArrayList<>()); - System.out.println("开始创建PDF: " + pdfPath); + // 保存到ThreadLocal + pdfDocThreadLocal.set(pdfDoc); + documentThreadLocal.set(document); + chineseFontThreadLocal.set(chineseFont); + + System.out.println(Thread.currentThread().getName() + " 开始创建PDF: " + pdfPath); + } + + /** + * 设置页脚文本(会在每一页底部显示) + */ + public static void setFooterText(String text) throws IOException { + Document document = documentThreadLocal.get(); + PdfFont chineseFont = chineseFontThreadLocal.get(); + + if (document == null) { + throw new IllegalStateException("请先调用 startPDF() 方法"); + } + + if (chineseFont == null) { + chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + chineseFontThreadLocal.set(chineseFont); + } + + // 获取页脚文本列表 + List footerTexts = footerTextsThreadLocal.get(); + if (footerTexts == null) { + footerTexts = new ArrayList<>(); + footerTextsThreadLocal.set(footerTexts); + } + + // 清空原有页脚,添加新的页脚文本 + footerTexts.clear(); + footerTexts.add(new FooterText(text, 50F, 30F, (DeviceRgb) DeviceRgb.BLACK)); + + System.out.println(Thread.currentThread().getName() + " 已设置页脚文本: " + text); } /** * 添加图片章节 */ public static void appendImageSection(String imagePath) throws IOException { + Document document = documentThreadLocal.get(); if (document == null) { throw new IllegalStateException("请先调用 startPDF() 方法"); } - // 添加章节标题 -// document.add(new Paragraph("图片部分") -// .setFontSize(20) -// .setBold() -// .setMarginTop(20)); - // 添加图片 if (imagePath != null && new File(imagePath).exists()) { ImageData imageData = ImageDataFactory.create(imagePath); Image image = new Image(imageData); - // image.setAutoScale(true); image.setHorizontalAlignment(com.itextpdf.layout.properties.HorizontalAlignment.CENTER); image.setMarginTop(5); image.setMarginBottom(5); @@ -90,55 +185,48 @@ public class Photo { image.setWidth(200); document.add(image); -// document.add(new Paragraph("图片说明") -// .setFontSize(10) -// .setItalic() -// .setTextAlignment(com.itextpdf.layout.properties.TextAlignment.CENTER)); } - System.out.println("已添加图片章节"); + System.out.println(Thread.currentThread().getName() + " 已添加图片章节"); } /** * 添加文本章节 */ public static void appendTextSection(String text) throws IOException { + Document document = documentThreadLocal.get(); + PdfFont chineseFont = chineseFontThreadLocal.get(); + if (document == null) { throw new IllegalStateException("请先调用 startPDF() 方法"); - - } - PdfFont chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + if (chineseFont == null) { + chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + chineseFontThreadLocal.set(chineseFont); + } - // 添加章节标题 document.add(new Paragraph(text) .setFont(chineseFont) .setFontSize(20) .setBold() .setMarginTop(20)); - /* // 添加文本 - if (text != null && !text.trim().isEmpty()) { - String[] paragraphs = text.split("\n"); - for (String para : paragraphs) { - document.add(new Paragraph(para) - .setFontSize(12) - .setMarginBottom(10)); - } - }*/ - - System.out.println("已添加文本章节"); + System.out.println(Thread.currentThread().getName() + " 已添加文本章节"); } public static void TextAlignment(String text) throws IOException { + Document document = documentThreadLocal.get(); + PdfFont chineseFont = chineseFontThreadLocal.get(); + if (document == null) { throw new IllegalStateException("请先调用 startPDF() 方法"); - - } - PdfFont chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + if (chineseFont == null) { + chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + chineseFontThreadLocal.set(chineseFont); + } // 创建段落并设置居中对齐 Paragraph paragraph = new Paragraph(text) @@ -146,52 +234,120 @@ public class Photo { .setFontSize(20) .setBold() .setMarginTop(20) - .setTextAlignment(TextAlignment.CENTER); // 添加这行实现居中 + .setTextAlignment(TextAlignment.CENTER); document.add(paragraph); - System.out.println("已添加文本章节"); + System.out.println(Thread.currentThread().getName() + " 已添加文本章节"); } - public static void appendTextSections(String text) throws IOException { + Document document = documentThreadLocal.get(); + PdfFont chineseFont = chineseFontThreadLocal.get(); + if (document == null) { throw new IllegalStateException("请先调用 startPDF() 方法"); - - } - PdfFont chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + if (chineseFont == null) { + chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + chineseFontThreadLocal.set(chineseFont); + } - // 添加章节标题 - // 设置绝对位置在页面底部 - Paragraph paragraph = new Paragraph(text); - float pageHeight = PageSize.A4.getHeight(); // 842点 - float bottomMargin = 50; // 距离底部50点 - float leftMargin = 400; // 左边距 + List footerTexts = footerTextsThreadLocal.get(); + if (footerTexts == null) { + footerTexts = new ArrayList<>(); + footerTextsThreadLocal.set(footerTexts); + } - paragraph.setFixedPosition(leftMargin, bottomMargin, PageSize.A4.getWidth() - 40).setFont(chineseFont); - document.add(paragraph); + // 添加白色文本 + footerTexts.add(new FooterText(text, 475F, 25f, (DeviceRgb) DeviceRgb.WHITE)); - /* // 添加文本 - if (text != null && !text.trim().isEmpty()) { - String[] paragraphs = text.split("\n"); - for (String para : paragraphs) { - document.add(new Paragraph(para) - .setFontSize(12) - .setMarginBottom(10)); - } - }*/ + System.out.println(Thread.currentThread().getName() + " 已添加白色页脚文本: " + text); + } - System.out.println("已添加文本章节"); + public static void appendTextSections1(String text) throws IOException { + Document document = documentThreadLocal.get(); + PdfFont chineseFont = chineseFontThreadLocal.get(); + + if (document == null) { + throw new IllegalStateException("请先调用 startPDF() 方法"); + } + + if (chineseFont == null) { + chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + chineseFontThreadLocal.set(chineseFont); + } + + List footerTexts = footerTextsThreadLocal.get(); + if (footerTexts == null) { + footerTexts = new ArrayList<>(); + footerTextsThreadLocal.set(footerTexts); + } + + // 添加黑色文本 + footerTexts.add(new FooterText(text, 310f, 25f, null)); + + System.out.println(Thread.currentThread().getName() + " 已添加黑色页脚文本: " + text); + } + + public static void appendTextSectionss(String text) throws IOException { + Document document = documentThreadLocal.get(); + PdfFont chineseFont = chineseFontThreadLocal.get(); + + if (document == null) { + throw new IllegalStateException("请先调用 startPDF() 方法"); + } + + if (chineseFont == null) { + chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + chineseFontThreadLocal.set(chineseFont); + } + + List footerTexts = footerTextsThreadLocal.get(); + if (footerTexts == null) { + footerTexts = new ArrayList<>(); + footerTextsThreadLocal.set(footerTexts); + } + + // 添加白色文本 + footerTexts.add(new FooterText(text, 400F, 50F, (DeviceRgb) DeviceRgb.WHITE)); + + System.out.println(Thread.currentThread().getName() + " 已添加白色页脚文本: " + text); + } + + public static void appendTextSectionss1(String text) throws IOException { + Document document = documentThreadLocal.get(); + PdfFont chineseFont = chineseFontThreadLocal.get(); + + if (document == null) { + throw new IllegalStateException("请先调用 startPDF() 方法"); + } + + if (chineseFont == null) { + chineseFont = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H"); + chineseFontThreadLocal.set(chineseFont); + } + + List footerTexts = footerTextsThreadLocal.get(); + if (footerTexts == null) { + footerTexts = new ArrayList<>(); + footerTextsThreadLocal.set(footerTexts); + } + + // 添加黑色文本 + footerTexts.add(new FooterText(text, 310, 50, null)); + + System.out.println(Thread.currentThread().getName() + " 已添加黑色页脚文本: " + text); } /** * 添加分页符 */ public static void addPageBreak() { + Document document = documentThreadLocal.get(); if (document != null) { document.add(new com.itextpdf.layout.element.AreaBreak()); - System.out.println("已添加分页符"); + System.out.println(Thread.currentThread().getName() + " 已添加分页符"); } } @@ -199,17 +355,30 @@ public class Photo { * 关闭并保存PDF */ public static void closePDF() { + // 获取当前线程的变量 + Document document = documentThreadLocal.get(); + PdfDocument pdfDoc = pdfDocThreadLocal.get(); + String currentPdfPath = currentPdfPathThreadLocal.get(); + PdfFont chineseFont = chineseFontThreadLocal.get(); + if (document != null) { document.close(); - document = null; - } - if (pdfDoc != null) { - pdfDoc.close(); - pdfDoc = null; + documentThreadLocal.remove(); } - System.out.println("PDF已保存: " + currentPdfPath); - currentPdfPath = null; + if (pdfDoc != null) { + pdfDoc.close(); + pdfDocThreadLocal.remove(); + } + + if (chineseFont != null) { + chineseFontThreadLocal.remove(); + } + + if (currentPdfPath != null) { + System.out.println(Thread.currentThread().getName() + " PDF已保存: " + currentPdfPath); + currentPdfPathThreadLocal.remove(); + } } /** @@ -218,24 +387,21 @@ public class Photo { public static void createPDFWithMultipleSections(String pdfPath) throws IOException { startPDF(pdfPath); - // 添加各种内容 - appendTextSection("这是文档的第一部分\n包含一些介绍性的文字"); - - - appendImageSection("image1.jpg"); - appendTextSection("这是图片1的描述文字"); - - appendImageSection("image2.png"); - appendTextSection("这是图片2的描述文字"); - - // 关闭并保存 - closePDF(); + try { + // 添加各种内容 + appendTextSection("这是文档的第一部分\n包含一些介绍性的文字"); + appendImageSection("image1.jpg"); + appendTextSection("这是图片1的描述文字"); + appendImageSection("image2.png"); + appendTextSection("这是图片2的描述文字"); + } finally { + // 确保资源被释放 + closePDF(); + } } - - - public static void createSimpleChinesePDF() throws IOException { + // 这个方法不使用ThreadLocal变量,因为它自己创建PDF // 1. 创建PDF PdfWriter writer = new PdfWriter("D:\\下载模板\\a.pdf"); PdfDocument pdfDoc = new PdfDocument(writer); @@ -258,17 +424,13 @@ public class Photo { // 4. 关闭文档 document.close(); + pdfDoc.close(); System.out.println("PDF创建完成"); } - public static void main(String[] args) { - try { - createSimpleChinesePDF(); - } catch (IOException e) { - System.out.println("错误: " + e.getMessage()); - System.out.println("请确保添加了 font-asian 依赖"); - } - } + /** + * 测试多线程并发 + */ -} \ No newline at end of file +} diff --git a/src/main/java/com/example/sso/test/R.java b/src/main/java/com/example/sso/test/R.java new file mode 100644 index 0000000..21233ad --- /dev/null +++ b/src/main/java/com/example/sso/test/R.java @@ -0,0 +1,73 @@ +package com.example.sso.test; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.example.sso.util.FDaDaUtil; +import lombok.extern.slf4j.Slf4j; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.net.HttpURLConnection; +import java.net.URL; +@Slf4j +public class R { + public static void main(String[] args) throws Exception { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("fileType","doc"); + String jsonString = jsonObject.toJSONString(); + + + String files = FDaDaUtil.files(jsonString); + JSONObject jsonObject1 = JSON.parseObject(files); + String string = jsonObject1.getJSONObject("data").getString("uploadUrl"); + + String fddFileUrl = jsonObject1.getJSONObject("data").getString("fddFileUrl"); + + log.info("xxxx " + files); + + final File localFile = new File("D:\\下载模板\\a.pdf"); + URL uploadUrl = new URL(string); + HttpURLConnection connection = (HttpURLConnection) uploadUrl.openConnection(); + connection.setRequestMethod("PUT"); + connection.setRequestProperty("Content-Type", "application/octet-stream"); + connection.setDoOutput(true); + BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream()); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(localFile)); + int readByte = -1; + while ((readByte = bis.read()) != -1) { + bos.write(readByte); + } + bis.close(); + bos.close(); + int responseCode = connection.getResponseCode(); + System.out.println("返回的信息如下:"); + System.out.println(responseCode + ":" + connection.getResponseMessage()); + + JSONObject jsonObject2 = new JSONObject(); + JSONArray jsonArray = new JSONArray(); + JSONObject jsonObject3 = new JSONObject(); + jsonObject3.put("fileType","doc"); + jsonObject3.put("fddFileUrl",fddFileUrl); + jsonObject3.put("fileName","a.pdf"); + jsonArray.add(jsonObject3); + jsonObject2.put("fddFileUrlList",jsonArray); + String jsonString1 = jsonObject2.toJSONString(); + log.info("文件参数 " + jsonString1); + String fileid = FDaDaUtil.fileid(jsonString1); + log.info("文件返沪 "+fileid ); + + JSONObject jsonObject4 = JSON.parseObject(fileid); + JSONObject string1 = jsonObject4.getJSONObject("data"); + JSONArray fileIdList = string1.getJSONArray("fileIdList"); + String a = ""; + for(Object o : fileIdList ){ + JSONObject te = (JSONObject) o; + a = te.getString("fileId"); + + } + System.out.println(a); + } +} diff --git a/src/main/java/com/example/sso/util/FDaDaUtil.java b/src/main/java/com/example/sso/util/FDaDaUtil.java index 34ef011..1a27830 100644 --- a/src/main/java/com/example/sso/util/FDaDaUtil.java +++ b/src/main/java/com/example/sso/util/FDaDaUtil.java @@ -164,6 +164,112 @@ public class FDaDaUtil { return outcome; } + public static String fdds( String bizContent) throws Exception { + + String token = getToken(); + + // 获取当前时间的毫秒数 + long currentTimeMillis = System.currentTimeMillis(); + + // 将毫秒数转换为13位时间戳 + String timestamp = String.valueOf(currentTimeMillis); + while (timestamp.length() < 13) { + timestamp = "0" + timestamp; + } + + // 输出13位时间戳 + /* System.out.println("13位时间戳: " + timestamp);*/ + + //Nonce,先定义取值范围 + String chars = "0123456789QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz"; + StringBuffer value = new StringBuffer(); + for (int i = 0; i < 10; i++) { + value.append(chars.charAt((int) (Math.random() * 62))); + } + + /* System.out.println("随机选取的10个数为:" + value.toString());*/ + + String nonce = value.toString(); + + // appid + String appId = "00000916"; + //密钥 + String appSecret = "0WPTPAJKWRULHJ9BGBCZGWGLNZRHY5HD"; + //令牌 + String AccessToken = token; + + + //公共参数 + /*String bizContent="{\"ownerId\":{\"idType\":\"corp\",\"openId\":\"625776ecae6742cb8eb710beedef9b4c\"}}";*/ + /* System.out.println(nonce);*/ + Map paramMap = new TreeMap<>(new Comparator() { + @Override + public int compare(String str1, String str2) { + return str1.compareTo(str2); + } + }); + paramMap.put("X-FASC-App-Id", appId); + paramMap.put("X-FASC-Sign-Type", "HMAC-SHA256"); + paramMap.put("X-FASC-Timestamp", timestamp); + paramMap.put("X-FASC-Nonce", nonce); + paramMap.put("X-FASC-Api-SubVersion", "5.1"); + paramMap.put("X-FASC-AccessToken", AccessToken); + paramMap.put("bizContent", bizContent); + String str = ""; + for (String key : paramMap.keySet()) { + /* System.out.println("key: " + key + " value: " + paramMap.get(key));*/ + if (str.equals("") && str != null) { + str = str + key + "=" + paramMap.get(key); + } else { + str = str + "&" + key + "=" + paramMap.get(key); + } + + } + /* System.out.println(str);*/ + + byte[] secretSigning = hmac256(appSecret.getBytes(), timestamp); + /* System.out.println(byte2Hex(secretSigning));*/ + + String signText = getSha256Str(str); + + byte[] secretSigning2 = hmac256(secretSigning, signText); + String sign = byte2Hex(secretSigning2); + /* System.out.println(sign);*/ + + + String url = "https://api.fadada.com/api/v5/sign-task/create"; + + // 设置请求头 + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + headers.add("X-FASC-App-Id", appId); + headers.add("X-FASC-Sign-Type", "HMAC-SHA256"); + headers.add("X-FASC-Sign", sign); + headers.add("X-FASC-Timestamp", timestamp); + headers.add("X-FASC-Nonce", nonce); + headers.add("X-FASC-AccessToken", AccessToken); + headers.add("X-FASC-Grant-Type", "client_credential"); + headers.add("X-FASC-Api-SubVersion", "5.1"); + RestTemplate restTemplate = new RestTemplate(); + + MultiValueMap forms = new LinkedMultiValueMap(); + + forms.put("bizContent", Collections.singletonList(bizContent)); + /* forms.put("X-FASC-Sign-Type", Collections.singletonList("HMAC-SHA256")); + forms.put("X-FASC-Sign", Collections.singletonList(sign)); + forms.put("X-FASC-Timestamp", Collections.singletonList(timestamp)); + forms.put("X-FASC-Nonce", Collections.singletonList(nonce)); + forms.put("X-FASC-Grant-Type", Collections.singletonList("client_credential")); + forms.put("X-FASC-Api-SubVersion", Collections.singletonList("5.1"));*/ + + HttpEntity> httpEntity = new HttpEntity>(forms, headers); + //获取返回数据 + String outcome = restTemplate.postForObject(url, httpEntity, String.class); + + + return outcome; + } + public static String zuofei( String bizContent) throws Exception { String token = getToken(); @@ -1209,6 +1315,219 @@ public class FDaDaUtil { } + public static String files( String bizContent) throws Exception { + + String token = getToken(); + + // 获取当前时间的毫秒数 + long currentTimeMillis = System.currentTimeMillis(); + + // 将毫秒数转换为13位时间戳 + String timestamp = String.valueOf(currentTimeMillis); + while (timestamp.length() < 13) { + timestamp = "0" + timestamp; + } + + // 输出13位时间戳 + /* System.out.println("13位时间戳: " + timestamp);*/ + + //Nonce,先定义取值范围 + String chars = "0123456789QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz"; + StringBuffer value = new StringBuffer(); + for (int i = 0; i < 10; i++) { + value.append(chars.charAt((int) (Math.random() * 62))); + } + + /* System.out.println("随机选取的10个数为:" + value.toString());*/ + + String nonce = value.toString(); + + // appid + String appId = "00000916"; + //密钥 + String appSecret = "0WPTPAJKWRULHJ9BGBCZGWGLNZRHY5HD"; + //令牌 + String AccessToken = token; + + + //公共参数 + /*String bizContent="{\"ownerId\":{\"idType\":\"corp\",\"openId\":\"625776ecae6742cb8eb710beedef9b4c\"}}";*/ + /* System.out.println(nonce);*/ + Map paramMap = new TreeMap<>(new Comparator() { + @Override + public int compare(String str1, String str2) { + return str1.compareTo(str2); + } + }); + paramMap.put("X-FASC-App-Id", appId); + paramMap.put("X-FASC-Sign-Type", "HMAC-SHA256"); + paramMap.put("X-FASC-Timestamp", timestamp); + paramMap.put("X-FASC-Nonce", nonce); + paramMap.put("X-FASC-Api-SubVersion", "5.1"); + paramMap.put("X-FASC-AccessToken", AccessToken); + paramMap.put("bizContent", bizContent); + String str = ""; + for (String key : paramMap.keySet()) { + /* System.out.println("key: " + key + " value: " + paramMap.get(key));*/ + if (str.equals("") && str != null) { + str = str + key + "=" + paramMap.get(key); + } else { + str = str + "&" + key + "=" + paramMap.get(key); + } + + } + /* System.out.println(str);*/ + + byte[] secretSigning = hmac256(appSecret.getBytes(), timestamp); + /* System.out.println(byte2Hex(secretSigning));*/ + + String signText = getSha256Str(str); + + byte[] secretSigning2 = hmac256(secretSigning, signText); + String sign = byte2Hex(secretSigning2); + /* System.out.println(sign);*/ + + + String url = "https://api.fadada.com/api/v5/file/get-upload-url"; + + // 设置请求头 + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + headers.add("X-FASC-App-Id", appId); + headers.add("X-FASC-Sign-Type", "HMAC-SHA256"); + headers.add("X-FASC-Sign", sign); + headers.add("X-FASC-Timestamp", timestamp); + headers.add("X-FASC-Nonce", nonce); + headers.add("X-FASC-AccessToken", AccessToken); + headers.add("X-FASC-Grant-Type", "client_credential"); + headers.add("X-FASC-Api-SubVersion", "5.1"); + RestTemplate restTemplate = new RestTemplate(); + + MultiValueMap forms = new LinkedMultiValueMap(); + + forms.put("bizContent", Collections.singletonList(bizContent)); + /* forms.put("X-FASC-Sign-Type", Collections.singletonList("HMAC-SHA256")); + forms.put("X-FASC-Sign", Collections.singletonList(sign)); + forms.put("X-FASC-Timestamp", Collections.singletonList(timestamp)); + forms.put("X-FASC-Nonce", Collections.singletonList(nonce)); + forms.put("X-FASC-Grant-Type", Collections.singletonList("client_credential")); + forms.put("X-FASC-Api-SubVersion", Collections.singletonList("5.1"));*/ + + HttpEntity> httpEntity = new HttpEntity>(forms, headers); + //获取返回数据 + String outcome = restTemplate.postForObject(url, httpEntity, String.class); + + + return outcome; + } + + + public static String fileid( String bizContent) throws Exception { + + String token = getToken(); + + // 获取当前时间的毫秒数 + long currentTimeMillis = System.currentTimeMillis(); + + // 将毫秒数转换为13位时间戳 + String timestamp = String.valueOf(currentTimeMillis); + while (timestamp.length() < 13) { + timestamp = "0" + timestamp; + } + + // 输出13位时间戳 + /* System.out.println("13位时间戳: " + timestamp);*/ + + //Nonce,先定义取值范围 + String chars = "0123456789QWERTYUIOPASDFGHJKLZXCVBNMabcdefghijklmnopqrstuvwxyz"; + StringBuffer value = new StringBuffer(); + for (int i = 0; i < 10; i++) { + value.append(chars.charAt((int) (Math.random() * 62))); + } + + /* System.out.println("随机选取的10个数为:" + value.toString());*/ + + String nonce = value.toString(); + + // appid + String appId = "00000916"; + //密钥 + String appSecret = "0WPTPAJKWRULHJ9BGBCZGWGLNZRHY5HD"; + //令牌 + String AccessToken = token; + + + //公共参数 + /*String bizContent="{\"ownerId\":{\"idType\":\"corp\",\"openId\":\"625776ecae6742cb8eb710beedef9b4c\"}}";*/ + /* System.out.println(nonce);*/ + Map paramMap = new TreeMap<>(new Comparator() { + @Override + public int compare(String str1, String str2) { + return str1.compareTo(str2); + } + }); + paramMap.put("X-FASC-App-Id", appId); + paramMap.put("X-FASC-Sign-Type", "HMAC-SHA256"); + paramMap.put("X-FASC-Timestamp", timestamp); + paramMap.put("X-FASC-Nonce", nonce); + paramMap.put("X-FASC-Api-SubVersion", "5.1"); + paramMap.put("X-FASC-AccessToken", AccessToken); + paramMap.put("bizContent", bizContent); + String str = ""; + for (String key : paramMap.keySet()) { + /* System.out.println("key: " + key + " value: " + paramMap.get(key));*/ + if (str.equals("") && str != null) { + str = str + key + "=" + paramMap.get(key); + } else { + str = str + "&" + key + "=" + paramMap.get(key); + } + + } + /* System.out.println(str);*/ + + byte[] secretSigning = hmac256(appSecret.getBytes(), timestamp); + /* System.out.println(byte2Hex(secretSigning));*/ + + String signText = getSha256Str(str); + + byte[] secretSigning2 = hmac256(secretSigning, signText); + String sign = byte2Hex(secretSigning2); + /* System.out.println(sign);*/ + + + String url = "https://api.fadada.com/api/v5/file/process"; + + // 设置请求头 + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Type", "application/x-www-form-urlencoded"); + headers.add("X-FASC-App-Id", appId); + headers.add("X-FASC-Sign-Type", "HMAC-SHA256"); + headers.add("X-FASC-Sign", sign); + headers.add("X-FASC-Timestamp", timestamp); + headers.add("X-FASC-Nonce", nonce); + headers.add("X-FASC-AccessToken", AccessToken); + headers.add("X-FASC-Grant-Type", "client_credential"); + headers.add("X-FASC-Api-SubVersion", "5.1"); + RestTemplate restTemplate = new RestTemplate(); + + MultiValueMap forms = new LinkedMultiValueMap(); + + forms.put("bizContent", Collections.singletonList(bizContent)); + /* forms.put("X-FASC-Sign-Type", Collections.singletonList("HMAC-SHA256")); + forms.put("X-FASC-Sign", Collections.singletonList(sign)); + forms.put("X-FASC-Timestamp", Collections.singletonList(timestamp)); + forms.put("X-FASC-Nonce", Collections.singletonList(nonce)); + forms.put("X-FASC-Grant-Type", Collections.singletonList("client_credential")); + forms.put("X-FASC-Api-SubVersion", Collections.singletonList("5.1"));*/ + + HttpEntity> httpEntity = new HttpEntity>(forms, headers); + //获取返回数据 + String outcome = restTemplate.postForObject(url, httpEntity, String.class); + + + return outcome; + } + /* 企业主体 @@ -1321,6 +1640,8 @@ public class FDaDaUtil { } + + /* 企业主体ebtryid */ diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..c57a06f --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,39 @@ + + + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + ${LOG_PATH}/${LOG_FILE}.log + + + + + ${LOG_PATH}/${LOG_FILE}.%d{yyyy-MM-dd}.log + + ${MAX_HISTORY} + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + true + + + + + + + \ No newline at end of file