|
|
@@ -1,37 +1,88 @@
|
|
|
-package com.ruoyi.tool.controller;
|
|
|
+package com.ruoyi.tool.service;
|
|
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
import com.junziqian.sdk.bean.ResultInfo;
|
|
|
import com.junziqian.sdk.util.RequestUtils;
|
|
|
-import com.ruoyi.common.core.domain.R;
|
|
|
import com.ruoyi.tool.config.JzqProperties;
|
|
|
import com.ruoyi.tool.request.OcrRequest;
|
|
|
import com.ruoyi.tool.response.OcrBankResponse;
|
|
|
import com.ruoyi.tool.response.OcrBusinessLicResponse;
|
|
|
import com.ruoyi.tool.response.OcrIdentityResponse;
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.http.entity.mime.content.FileBody;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.util.Base64;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
-@Api("君子签")
|
|
|
-@RestController
|
|
|
-@RequestMapping("/jzq/ocr")
|
|
|
-@AllArgsConstructor
|
|
|
-public class JzqOcrController {
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class JzqService {
|
|
|
|
|
|
- private final JzqProperties jzqProperties;
|
|
|
+ @Resource
|
|
|
+ private JzqProperties jzqProperties;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传个人自定义印章图片
|
|
|
+ */
|
|
|
+ public Boolean uploadPersSign(String identityCard, String signImgFile) {
|
|
|
+ RequestUtils requestUtils = RequestUtils.init(jzqProperties.getBaseUrl(), jzqProperties.getAppKey(), jzqProperties.getAppSecret());
|
|
|
+ //构建请求参数
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("identityCard", identityCard);
|
|
|
+ // 解码Base64
|
|
|
+ String base64Data = signImgFile.split(",", 2)[1];
|
|
|
+ byte[] imageBytes = Base64.getDecoder().decode(base64Data);
|
|
|
+ Path tempFile = null;
|
|
|
+ try {
|
|
|
+ tempFile = Files.createTempFile("sign", ".png");
|
|
|
+ Files.write(tempFile, imageBytes);
|
|
|
+ params.put("signImgFile", new FileBody(tempFile.toFile()));
|
|
|
+ ResultInfo<Void> ri = requestUtils.doPost(jzqProperties.getUploadPersSign(), params);
|
|
|
+ log.info("上传个人自定义印章图片:{}", ri.getMsg());
|
|
|
+ return ri.isSuccess();
|
|
|
+ } catch (Exception e) {
|
|
|
+ //不处理
|
|
|
+ } finally {
|
|
|
+ // 使用后删除临时文件(重要!)
|
|
|
+ if (tempFile != null) {
|
|
|
+ tempFile.toFile().deleteOnExit();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 签约发起-模板类API TODO 待完善
|
|
|
+ */
|
|
|
+ public String applySign(JSONArray signatories) {
|
|
|
+ RequestUtils requestUtils = RequestUtils.init(jzqProperties.getBaseUrl(), jzqProperties.getAppKey(), jzqProperties.getAppSecret());
|
|
|
+ //构建请求参数
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("contractName", "合同名称"); //合同名称
|
|
|
+ params.put("serverCa", 1); //使用云证书
|
|
|
+ params.put("fileType", 2);
|
|
|
+ params.put("templateNo", "00154");
|
|
|
+ params.put("templateParams", "{xx:xxx}");//可以传json_string:{xx:xxx}
|
|
|
+ params.put("positionType", 0); //指定签字位置类型(0签字坐标,1表单域,2关键字)
|
|
|
+ params.put("signatories", signatories.toString());
|
|
|
+
|
|
|
+ ResultInfo<String> ri = requestUtils.doPost(jzqProperties.getApplySign(), params);
|
|
|
+ log.info("签约发起-模板类API:{}", ri.getMsg());
|
|
|
+ if (ri.isSuccess()) {
|
|
|
+ return ri.getData();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 身份证识别
|
|
|
*/
|
|
|
- @ApiOperation("身份证识别")
|
|
|
- @GetMapping("/idcard")
|
|
|
- public R<OcrIdentityResponse> idcard(OcrRequest request) {
|
|
|
+ public OcrIdentityResponse idcard(OcrRequest request) {
|
|
|
RequestUtils requestUtils = RequestUtils.init(jzqProperties.getBaseUrl(), jzqProperties.getAppKey(), jzqProperties.getAppSecret());
|
|
|
//构建请求参数
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
@@ -54,15 +105,13 @@ public class JzqOcrController {
|
|
|
response.setOverdueTime(data.get("overdueTime") != null ? data.get("overdueTime").toString() : null);
|
|
|
response.setOrderNo(data.get("orderNo") != null ? data.get("orderNo").toString() : null);
|
|
|
}
|
|
|
- return R.ok(response);
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 银行卡识别
|
|
|
*/
|
|
|
- @ApiOperation("银行卡识别")
|
|
|
- @GetMapping("/bank")
|
|
|
- public R<OcrBankResponse> bank(OcrRequest request) {
|
|
|
+ public OcrBankResponse bank(OcrRequest request) {
|
|
|
RequestUtils requestUtils = RequestUtils.init(jzqProperties.getBaseUrl(), jzqProperties.getAppKey(), jzqProperties.getAppSecret());
|
|
|
//构建请求参数
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
@@ -78,15 +127,13 @@ public class JzqOcrController {
|
|
|
response.setOrderNo(data.get("orderNo") != null ? data.get("orderNo").toString() : null);
|
|
|
response.setValidDate(data.get("validDate") != null ? data.get("validDate").toString() : null);
|
|
|
}
|
|
|
- return R.ok(response);
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 营业执照识别
|
|
|
*/
|
|
|
- @ApiOperation("营业执照识别")
|
|
|
- @GetMapping("/businessLic")
|
|
|
- public R<OcrBusinessLicResponse> businessLic(OcrRequest request) {
|
|
|
+ public OcrBusinessLicResponse businessLic(OcrRequest request) {
|
|
|
RequestUtils requestUtils = RequestUtils.init(jzqProperties.getBaseUrl(), jzqProperties.getAppKey(), jzqProperties.getAppSecret());
|
|
|
//构建请求参数
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
@@ -104,8 +151,6 @@ public class JzqOcrController {
|
|
|
response.setName(data.get("name") != null ? data.get("name").toString() : null);
|
|
|
response.setValidity(data.get("validity") != null ? data.get("validity").toString() : null);
|
|
|
}
|
|
|
- return R.ok(response);
|
|
|
+ return response;
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|