|
@@ -1,10 +1,17 @@
|
|
|
package com.dgtly.wxportal.service.impl;
|
|
package com.dgtly.wxportal.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.dgtly.system.domain.CustomersExt;
|
|
import com.dgtly.system.domain.CustomersExt;
|
|
|
|
|
+import com.dgtly.system.domain.ESignCorpAuthParam;
|
|
|
|
|
+import com.dgtly.system.domain.EsignCorpAuthSignRecord;
|
|
|
|
|
+import com.dgtly.system.domain.Result;
|
|
|
|
|
+import com.dgtly.system.util.HttpUtil;
|
|
|
|
|
+import com.dgtly.system.util.ResultUtil;
|
|
|
import com.dgtly.wxportal.domain.EReceivingNote;
|
|
import com.dgtly.wxportal.domain.EReceivingNote;
|
|
|
import com.dgtly.system.domain.SysUser;
|
|
import com.dgtly.system.domain.SysUser;
|
|
|
import com.dgtly.system.service.ICustomersExtService;
|
|
import com.dgtly.system.service.ICustomersExtService;
|
|
|
|
|
+import com.dgtly.system.service.IEsignCorpAuthSignRecordService;
|
|
|
import com.dgtly.wxportal.domain.ESignUpPDFModal;
|
|
import com.dgtly.wxportal.domain.ESignUpPDFModal;
|
|
|
import com.dgtly.wxportal.domain.OrderFile;
|
|
import com.dgtly.wxportal.domain.OrderFile;
|
|
|
import com.dgtly.wxportal.domain.OrderSelfNote;
|
|
import com.dgtly.wxportal.domain.OrderSelfNote;
|
|
@@ -21,6 +28,7 @@ import com.dgtly.wxportal.utils.pdf.Watermark;
|
|
|
import com.itextpdf.text.Document;
|
|
import com.itextpdf.text.Document;
|
|
|
import com.itextpdf.text.PageSize;
|
|
import com.itextpdf.text.PageSize;
|
|
|
import com.itextpdf.text.pdf.PdfWriter;
|
|
import com.itextpdf.text.pdf.PdfWriter;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -28,6 +36,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -58,6 +67,9 @@ public class ESignServiceImpl implements ESignService {
|
|
|
private ESignConfig eSignConfig;
|
|
private ESignConfig eSignConfig;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IEReceivingNoteService iMetaHanaSalesOrderService;
|
|
private IEReceivingNoteService iMetaHanaSalesOrderService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IEsignCorpAuthSignRecordService esignCorpAuthSignRecordService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public ESignUpPDFModal upload(String orderId,String tmsShipNumber,String customerCode,String customerName,String userName) {
|
|
public ESignUpPDFModal upload(String orderId,String tmsShipNumber,String customerCode,String customerName,String userName) {
|
|
@@ -176,6 +188,7 @@ public class ESignServiceImpl implements ESignService {
|
|
|
@Override
|
|
@Override
|
|
|
public CustomersExt createThirdParty(CustomersExt customersExt) {
|
|
public CustomersExt createThirdParty(CustomersExt customersExt) {
|
|
|
JSONObject json = new JSONObject();
|
|
JSONObject json = new JSONObject();
|
|
|
|
|
+ log.info("333333333333:{}", JSON.toJSON(customersExt));
|
|
|
int isok = 1;
|
|
int isok = 1;
|
|
|
json.put("thirdPartyUserId",customersExt.getChainsCode());
|
|
json.put("thirdPartyUserId",customersExt.getChainsCode());
|
|
|
json.put("creator",customersExt.getCreator());
|
|
json.put("creator",customersExt.getCreator());
|
|
@@ -476,4 +489,243 @@ public class ESignServiceImpl implements ESignService {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发起企业授权书签署任务
|
|
|
|
|
+ *
|
|
|
|
|
+ * <pre>
|
|
|
|
|
+ * 请求示例:
|
|
|
|
|
+ * POST https://openapi.esign.cn/v3/org-auth/corp-auth-sign/tasks
|
|
|
|
|
+ * {
|
|
|
|
|
+ * "accountId" : "机构账号ID",
|
|
|
|
|
+ * "transactorAccountId" : "经办人个人账号ID",
|
|
|
|
|
+ * "authorizedType" : 1,
|
|
|
|
|
+ * "sendNotice" : true,
|
|
|
|
|
+ * "validDate" : 20271231,
|
|
|
|
|
+ * "notifyUrl" : "https://your-domain.com/esign/notify",
|
|
|
|
|
+ * "redirectUrl" : "https://your-domain.com/esign/redirect"
|
|
|
|
|
+ * }
|
|
|
|
|
+ *
|
|
|
|
|
+ * 成功响应示例:
|
|
|
|
|
+ * {
|
|
|
|
|
+ * "code" : 0,
|
|
|
|
|
+ * "message" : "成功",
|
|
|
|
|
+ * "data" : {
|
|
|
|
|
+ * "taskId" : "xxx",
|
|
|
|
|
+ * "signUrl" : "https://..."
|
|
|
|
|
+ * }
|
|
|
|
|
+ * }
|
|
|
|
|
+ * </pre>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param param 请求参数
|
|
|
|
|
+ * @return Result
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Result initiateCorpAuthSign(ESignCorpAuthParam param) throws IOException {
|
|
|
|
|
+ // 1. 参数基础校验
|
|
|
|
|
+ if (param == null) {
|
|
|
|
|
+ return ResultUtil.error(500, "请求参数不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(param.getAccountId())) {
|
|
|
|
|
+ return ResultUtil.error(500, "机构账号ID(accountId)不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+// if (StringUtils.isBlank(param.getTransactorAccountId())) {
|
|
|
|
|
+// return ResultUtil.error(500, "经办人账号ID(transactorAccountId)不能为空");
|
|
|
|
|
+// }
|
|
|
|
|
+ if (param.getValidDate() == null) {
|
|
|
|
|
+ return ResultUtil.error(500, "授权有效期截止时间(validDate)不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ // authorizedType=2 时 authorizedAccountId 必传
|
|
|
|
|
+ if (param.getAuthorizedType() != null && param.getAuthorizedType() == 2
|
|
|
|
|
+ && StringUtils.isBlank(param.getAuthorizedAccountId())) {
|
|
|
|
|
+ return ResultUtil.error(500, "授权至经办人模式(authorizedType=2)时,被授权人账号ID(authorizedAccountId)不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 构建请求体
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("accountId", param.getAccountId());
|
|
|
|
|
+ json.put("transactorAccountId", param.getTransactorAccountId());
|
|
|
|
|
+
|
|
|
|
|
+ if (param.getAuthorizedType() != null) {
|
|
|
|
|
+ json.put("authorizedType", param.getAuthorizedType());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(param.getAuthorizedAccountId())) {
|
|
|
|
|
+ json.put("authorizedAccountId", param.getAuthorizedAccountId());
|
|
|
|
|
+ }
|
|
|
|
|
+ // sendNotice 默认 true,仅显式传 false 时才覆盖
|
|
|
|
|
+ if (param.getSendNotice() != null) {
|
|
|
|
|
+ json.put("sendNotice", param.getSendNotice());
|
|
|
|
|
+ }
|
|
|
|
|
+ json.put("validDate", param.getValidDate());
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotBlank(param.getNotifyUrl())) {
|
|
|
|
|
+ json.put("notifyUrl", param.getNotifyUrl());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(param.getRedirectUrl())) {
|
|
|
|
|
+ json.put("redirectUrl", param.getRedirectUrl());
|
|
|
|
|
+ }
|
|
|
|
|
+ json.put("sendNotice",false);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("[ESign] 发起企业授权书签署任务, url={}, accountId={}, transactorAccountId={}",
|
|
|
|
|
+ ESignUrl.createEsignAuthUrl, param.getAccountId(), param.getTransactorAccountId());
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 发起 HTTP 请求
|
|
|
|
|
+ JSONObject responseJson = eSignHttpUtil.doPostGetJson(ESignUrl.createEsignAuthUrl,json);
|
|
|
|
|
+ log.info("[ESign] 企业授权书签署任务响应, response={}", responseJson);
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 解析响应
|
|
|
|
|
+ if (responseJson == null) {
|
|
|
|
|
+ return ResultUtil.error(500, "e签宝接口返回为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (responseJson == null) {
|
|
|
|
|
+ return ResultUtil.error(500, "e签宝接口响应解析失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer code = responseJson.getInteger("code");
|
|
|
|
|
+ String message = responseJson.getString("message");
|
|
|
|
|
+
|
|
|
|
|
+ if (code == null || code != 0) {
|
|
|
|
|
+ log.warn("[ESign] 企业授权书签署任务失败, code={}, message={}", code, message);
|
|
|
|
|
+ return ResultUtil.error(500, "发起企业授权书签署任务失败:" + message);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 成功,返回 data(含 taskId / signUrl 等)
|
|
|
|
|
+ Object data = responseJson.get("data");
|
|
|
|
|
+
|
|
|
|
|
+ // 7. 将 authId 写入本地签署状态记录表
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSONObject dataJson = responseJson.getJSONObject("data");
|
|
|
|
|
+ String authId = dataJson != null ? dataJson.getString("authId") : null;
|
|
|
|
|
+ if (StringUtils.isNotBlank(authId)) {
|
|
|
|
|
+ EsignCorpAuthSignRecord record = new EsignCorpAuthSignRecord();
|
|
|
|
|
+ record.setAuthId(authId);
|
|
|
|
|
+ record.setOrgId(param.getAccountId());
|
|
|
|
|
+ record.setCreator(param.getTransactorAccountId());
|
|
|
|
|
+ record.setCustomeCode(param.getCustomeCode());
|
|
|
|
|
+ record.setStatus(1); // 1=进行中
|
|
|
|
|
+ esignCorpAuthSignRecordService.insertRecord(record);
|
|
|
|
|
+ log.info("[ESign] 签署状态记录已写入, authId={}, orgId={}, customeCode={}",
|
|
|
|
|
+ authId, param.getAccountId(), param.getCustomeCode());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.warn("[ESign] 发起成功但 data 中未找到 authId,跳过写入签署状态记录, data={}", dataJson);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 写入记录失败不影响主流程,仅记录日志
|
|
|
|
|
+ log.error("[ESign] 写入签署状态记录失败, accountId={}", param.getAccountId(), e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return ResultUtil.success(data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取授权流程签署URL
|
|
|
|
|
+ *
|
|
|
|
|
+ * <pre>
|
|
|
|
|
+ * POST /v1/signAuthApi/signUrl
|
|
|
|
|
+ * 请求参数:
|
|
|
|
|
+ * authId String 是 授权流程ID
|
|
|
|
|
+ * needLogin boolean 否 是否需要登录打开链接,默认 true
|
|
|
|
|
+ * clientType String 否 客户端类型:H5 / PC / ALL(默认 ALL)
|
|
|
|
|
+ * redirectUrl String 否 签署完成后跳转页面
|
|
|
|
|
+ * appScheme String 否 AppScheme,用于唤起 App
|
|
|
|
|
+ *
|
|
|
|
|
+ * 响应:
|
|
|
|
|
+ * code int 业务码,0 表示成功
|
|
|
|
|
+ * message String 业务信息
|
|
|
|
|
+ * data:
|
|
|
|
|
+ * shortUrl String 授权流程签署短链接(90天有效)
|
|
|
|
|
+ * longUrl String 授权流程签署长链接(90天有效)
|
|
|
|
|
+ * </pre>
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Result getSignUrl(String authId, Boolean needLogin, String clientType,
|
|
|
|
|
+ String redirectUrl, String appScheme) throws IOException {
|
|
|
|
|
+ if (StringUtils.isBlank(authId)) {
|
|
|
|
|
+ return ResultUtil.error(500, "授权流程ID(authId)不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 构建请求体
|
|
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
|
|
+ json.put("authId", authId);
|
|
|
|
|
+ if (needLogin != null) {
|
|
|
|
|
+ json.put("needLogin", needLogin);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(clientType)) {
|
|
|
|
|
+ json.put("clientType", clientType.toUpperCase());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(redirectUrl)) {
|
|
|
|
|
+ json.put("redirectUrl", redirectUrl);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(appScheme)) {
|
|
|
|
|
+ json.put("appScheme", appScheme);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("[ESign] 获取授权流程签署URL, authId={}", authId);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject responseJson = eSignHttpUtil.doPostGetJson(ESignUrl.getSignUrl, json);
|
|
|
|
|
+ log.info("[ESign] 获取授权流程签署URL响应, response={}", responseJson);
|
|
|
|
|
+
|
|
|
|
|
+ if (responseJson == null) {
|
|
|
|
|
+ return ResultUtil.error(500, "e签宝接口返回为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer code = responseJson.getInteger("code");
|
|
|
|
|
+ String message = responseJson.getString("message");
|
|
|
|
|
+
|
|
|
|
|
+ if (code == null || code != 0) {
|
|
|
|
|
+ log.warn("[ESign] 获取授权流程签署URL失败, code={}, message={}", code, message);
|
|
|
|
|
+ return ResultUtil.error(500, "获取授权流程签署URL失败:" + message);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Object data = responseJson.get("data");
|
|
|
|
|
+ return ResultUtil.success(data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询授权结果
|
|
|
|
|
+ *
|
|
|
|
|
+ * <pre>
|
|
|
|
|
+ * GET /v1/signAuthApi/queryAuthResult?authId={authId}
|
|
|
|
|
+ *
|
|
|
|
|
+ * 响应 data 字段:
|
|
|
|
|
+ * authId String 授权流程ID
|
|
|
|
|
+ * status int 授权状态:1=进行中 2=授权成功 3=授权失败 4=取消授权
|
|
|
|
|
+ * failReason String 授权说明(授权失败时返回原因)
|
|
|
|
|
+ * effectiveStartTime long 授权生效时间(格式 yyyyMMdd)
|
|
|
|
|
+ * effectiveEndTime long 授权失效时间(格式 yyyyMMdd)
|
|
|
|
|
+ * authDownloadUrl String 授权书下载链接(有效期60分钟,仅 status=2 时返回)
|
|
|
|
|
+ * </pre>
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Result queryAuthResult(String authId,String customeCode) throws IOException {
|
|
|
|
|
+ EsignCorpAuthSignRecord esignCorpAuthSignRecord =esignCorpAuthSignRecordService.selectByCustomeCode(customeCode);
|
|
|
|
|
+ if (esignCorpAuthSignRecord == null){
|
|
|
|
|
+ return ResultUtil.error(500, "e签宝暂未签署授权");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ if (StringUtils.isEmpty(authId)){
|
|
|
|
|
+ authId = esignCorpAuthSignRecord.getAuthId();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("[ESign] 查询授权结果, authId={}", authId);
|
|
|
|
|
+
|
|
|
|
|
+ // GET 请求,authId 作为 query 参数拼入 URL(枚举 URL 含 %s 占位符)
|
|
|
|
|
+ JSONObject responseJson = eSignHttpUtil.doGetGetJson(ESignUrl.queryAuthResult, new JSONObject(), authId);
|
|
|
|
|
+ log.info("[ESign] 查询授权结果响应, response={}", responseJson);
|
|
|
|
|
+
|
|
|
|
|
+ if (responseJson == null) {
|
|
|
|
|
+ return ResultUtil.error(500, "e签宝接口返回为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Integer code = responseJson.getInteger("code");
|
|
|
|
|
+ String message = responseJson.getString("message");
|
|
|
|
|
+
|
|
|
|
|
+ if (code == null || code != 0) {
|
|
|
|
|
+ log.warn("[ESign] 查询授权结果失败, code={}, message={}", code, message);
|
|
|
|
|
+ return ResultUtil.error(500, "查询授权结果失败:" + message);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Object data = responseJson.get("data");
|
|
|
|
|
+ return ResultUtil.success(data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|