对接接口方法:1.获取token2.更新案件状态3.上传文件4.推送案件附件信息
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package com.ruoyi.web.controller.tool;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.PushCaseStatusEnum;
|
||||
import com.ruoyi.system.service.impl.BeiMingInterfaceService;
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseStatusInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static com.ruoyi.common.utils.EncryptUtils.sm4Decrypt;
|
||||
import static com.ruoyi.common.utils.EncryptUtils.sm4Encrypt;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/beiming/api")
|
||||
public class TestApiController {
|
||||
@Autowired
|
||||
BeiMingInterfaceService beiMingInterfaceService;
|
||||
@Value("${beimingprivatekey}")
|
||||
public String privateKey;
|
||||
|
||||
@GetMapping("/test")
|
||||
@Anonymous
|
||||
public AjaxResult selectCaseFlow() {
|
||||
String token = beiMingInterfaceService.getApiToken("BWT_MEDIATION", "86251b190e3a40f3942v215d1762c663", System.currentTimeMillis());
|
||||
// token = "f910e1441fc56e49d3f31396e8d9aa04228045815ee986a9587d7a5cb7312f9d11c7f80041745f38ec686ea1f819c8b8227f9c03196c6dd004f89215c4805c24355be4b57abeddb7b9d2cbda45fae74c49f4a83fb6496d84302ca8c07245786d682ecb68aed966fcbda3188b9c4d4376089471bb5aee371a62073b0ce15d72dccd6fbc8fd13957e2fb7aa018cb5937938bfc9773e570ac06ac633617cea8405759cf609c832074aaa03f972c0a6a93cde531da0d91d07770c037fdea1368ee5772941ba2a55ef155979d1ed8222faad92ed342530ef04f3746aa96499dee6ea4869ce46bd0dcfe7a69e7db49eb2aec388c47824c201b49825f24ffe82dde41b5";
|
||||
System.out.println("toke:" + token);
|
||||
//解密
|
||||
if (token != null && !token.isEmpty()) {
|
||||
JSONObject jsonObject = JSON.parseObject(token);
|
||||
String tokenString = jsonObject.getString("data");
|
||||
System.out.println("data信息:" + tokenString);
|
||||
String tokenstr = sm4Decrypt(tokenString, privateKey);
|
||||
System.out.println("解密后的字符串:" + tokenstr);
|
||||
if (tokenstr != null && !tokenstr.isEmpty()) {
|
||||
JSONObject tokenObject = JSON.parseObject(tokenstr);
|
||||
String resultToken = tokenObject.getString("token");
|
||||
MsCaseStatusInfo info = MsCaseStatusInfo.builder().caseNo("zc2024032700012").statusCode(PushCaseStatusEnum.MEDIATE.getCode()).caseClosureExplanation(PushCaseStatusEnum.MEDIATE.getName()).build();
|
||||
JSONObject result = beiMingInterfaceService.submitCaseStatusInfo(resultToken, "zc2024032700012", "BWT_MEDIATION", info);
|
||||
System.out.println("jieguo:" + result.toString());
|
||||
if (result != null) {
|
||||
String data = result.getString("data");
|
||||
String datastr = sm4Decrypt(data, privateKey);
|
||||
System.out.println("最终解密后的字符串:" + datastr);
|
||||
}
|
||||
}
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@GetMapping("/testfile")
|
||||
@Anonymous
|
||||
public AjaxResult testfile() {
|
||||
// File file = new File("D:/WorkDoc/TJ/File/证据1.png");
|
||||
File file = new File("D:/WorkDoc/TJ/File/证据3.png");
|
||||
JSONObject jsonObject1 = beiMingInterfaceService.pushAttachmentInfo("BWT_MEDIATION", "86251b190e3a40f3942v215d1762c663", file, "123abc", "BWT_MEDIATION", "zc2024032700012");
|
||||
System.out.println("fanhui:" + jsonObject1.toString());
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ spring:
|
||||
max-wait: -1ms
|
||||
web:
|
||||
resources:
|
||||
static-locations: file:/home/ruoyi/
|
||||
static-locations: file:/home/ruoyi/
|
||||
mail:
|
||||
host: smtp.163.com
|
||||
port: 25
|
||||
@@ -196,17 +196,20 @@ signSealCallbackConfig:
|
||||
url: http://121.40.189.20:7001/mssignSeal/signSeaalCaseApplicaCallback
|
||||
# onlyOffice系统url配置
|
||||
onlyOfficeConfig:
|
||||
# url: http://172.16.0.254:9090/files/upload
|
||||
# url: http://172.16.0.254:9090/files/upload
|
||||
url: http://121.40.189.20:9090/files/upload
|
||||
#jodconverter:
|
||||
# local:
|
||||
# host: 121.40.189.20
|
||||
#jodconverter:
|
||||
# local:
|
||||
# host: 121.40.189.20
|
||||
#暂时关闭预览,启动时会有点慢
|
||||
# enabled: true
|
||||
# enabled: true
|
||||
#设置libreoffice主目录 linux地址如:/usr/lib64/libreoffice
|
||||
# office-home: /usr/lib64/libreoffice/
|
||||
# office-home: D:\app\libreOffice\
|
||||
#开启多个libreoffice进程,每个端口对应一个进程
|
||||
# port-numbers: 8100
|
||||
#libreoffice进程重启前的最大进程数
|
||||
# office-home: /usr/lib64/libreoffice/
|
||||
# office-home: D:\app\libreOffice\
|
||||
#开启多个libreoffice进程,每个端口对应一个进程
|
||||
# port-numbers: 8100
|
||||
#libreoffice进程重启前的最大进程数
|
||||
# max-tasks-per-process: 100
|
||||
beimingapihost: https://zj.odrcloud.cn
|
||||
beimingapiprefix: /onestop/sync
|
||||
beimingprivatekey: d7724e72c4be93196a35203e8379ded5
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ruoyi.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate(ClientHttpRequestFactory factory){
|
||||
return new RestTemplate(factory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
|
||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||
factory.setReadTimeout(5000);//单位为ms
|
||||
factory.setConnectTimeout(5000);//单位为ms
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.ruoyi.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 案件附件操作类型
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum AttachmentOperateTypeEnum {
|
||||
ADD("ADD", "新增"), DEL("DEL", "删除"), UPD("UPD", "修改");
|
||||
private String code;
|
||||
private String name;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.ruoyi.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum PushCaseStatusEnum {
|
||||
MEDIATE("MEDIATE", "调解中", 1), SUCCESS("SUCCESS", "调解成功", 2), FAIL("FAIL", "调解失败", 3);
|
||||
private String code;
|
||||
private String name;
|
||||
private Integer value;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.Key;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.Security;
|
||||
import java.util.UUID;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.pqc.math.linearalgebra.ByteUtils;
|
||||
|
||||
@Slf4j
|
||||
public class EncryptUtils {
|
||||
static {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
||||
/**
|
||||
* sm4加密
|
||||
* @explain 加密模式:ECB 密文长度不固定,会随着被加密字符串长度的变化而变化
|
||||
* @param paramStr 待加密字符串
|
||||
* @return 返回16进制的加密字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String sm4Encrypt(String paramStr, String secretKey) {
|
||||
if (StringUtils.isBlank(paramStr)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// 16进制字符串-->byte[]
|
||||
byte[] keyData = ByteUtils.fromHexString(secretKey);
|
||||
// String-->byte[]
|
||||
byte[] srcData = paramStr.getBytes(StandardCharsets.UTF_8);
|
||||
// 加密后的数组
|
||||
Cipher cipher = Cipher.getInstance("SM4/ECB/PKCS5Padding", BouncyCastleProvider.PROVIDER_NAME);
|
||||
Key sm4Key = new SecretKeySpec(keyData, "SM4");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, sm4Key);
|
||||
byte[] cipherArray = cipher.doFinal(srcData);
|
||||
// byte[]-->hexString
|
||||
return ByteUtils.toHexString(cipherArray);
|
||||
} catch (Exception e) {
|
||||
log.error("sm4加密失败:{}", paramStr, e);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* sm4解密
|
||||
* @explain 解密模式:采用ECB
|
||||
* @param cipherText 16进制的加密字符串(忽略大小写)
|
||||
* @return 解密后的字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String sm4Decrypt(String cipherText, String secretKey) {
|
||||
if (StringUtils.isBlank(cipherText)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
// hexString-->byte[]
|
||||
byte[] keyData = ByteUtils.fromHexString(secretKey);
|
||||
// hexString-->byte[]
|
||||
byte[] cipherData = ByteUtils.fromHexString(cipherText);
|
||||
// 解密
|
||||
Cipher cipher = Cipher.getInstance("SM4/ECB/PKCS5Padding", BouncyCastleProvider.PROVIDER_NAME);
|
||||
Key sm4Key = new SecretKeySpec(keyData, "SM4");
|
||||
cipher.init(Cipher.DECRYPT_MODE, sm4Key);
|
||||
byte[] cipherArray = cipher.doFinal(cipherData);
|
||||
// byte[]-->String
|
||||
return new String(cipherArray, StandardCharsets.UTF_8);
|
||||
} catch (Exception e) {
|
||||
log.error("sm4解密失败:{}", cipherText, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 初始化 HmacMD5 密钥
|
||||
*/
|
||||
public static String initHmacMD5Key() throws NoSuchAlgorithmException {
|
||||
//Init KeyGenerator.
|
||||
KeyGenerator generator = KeyGenerator.getInstance("HmacSHA224");
|
||||
//Generate key.
|
||||
SecretKey secretKey = generator.generateKey();
|
||||
return ByteUtils.toHexString(secretKey.getEncoded());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: HmacMD5 消息摘要
|
||||
*/
|
||||
public static String encodeHmacMD5(String data, String key) throws NoSuchAlgorithmException, InvalidKeyException {
|
||||
//Restore key.
|
||||
SecretKey secretKey = new SecretKeySpec(ByteUtils.fromHexString(key), "HmacSHA224");
|
||||
//Instantiate Mac.
|
||||
Mac mac = Mac.getInstance(secretKey.getAlgorithm());
|
||||
//Init Mac.
|
||||
mac.init(secretKey);
|
||||
//Execute.
|
||||
return ByteUtils.toHexString(mac.doFinal(ByteUtils.fromHexString(data)));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String privateKey = "936df5fd9aba3b86adc3c1a1c52dcde1";
|
||||
ObjectNode param = new ObjectMapper().createObjectNode();
|
||||
param.put("name", "姓名");
|
||||
String encryptString = sm4Encrypt(param.toString(), privateKey);
|
||||
System.out.println("加密后的字符串:" + encryptString);
|
||||
System.out.println("解密后的字符串:" + sm4Decrypt(encryptString, privateKey));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.wisdomarbitrate.domain.entity.casestatus.MsCaseStatus;
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseFileInfo;
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseStatusInfo;
|
||||
import org.apache.ibatis.annotations.Case;
|
||||
import org.apache.poi.hmef.Attachment;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public interface BeiMingInterface {
|
||||
/**
|
||||
* 1.获取北明接口令牌token
|
||||
*
|
||||
* @param userName
|
||||
* @param password
|
||||
* @param times
|
||||
* @return
|
||||
*/
|
||||
String getApiToken(String userName, String password, Long times);
|
||||
|
||||
|
||||
/**
|
||||
* 2.提交案件状态信息
|
||||
*
|
||||
* @param token 令牌
|
||||
* @param abutmentId 第三方平台案件唯一标识
|
||||
* @param msCaseStatusInfo 案件状态信息
|
||||
* @return
|
||||
*/
|
||||
JSONObject submitCaseStatusInfo(String token, String abutmentId, String syncSource, MsCaseStatusInfo msCaseStatusInfo);
|
||||
|
||||
/**
|
||||
* 3.上传附件
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
JSONObject uploadFile(File file, String token, String syncSource);
|
||||
|
||||
/**
|
||||
* 4.同步附件信息
|
||||
*
|
||||
* @param action
|
||||
* @param caseNo
|
||||
* @param msCaseFileInfo
|
||||
* @return
|
||||
*/
|
||||
JSONObject syncAttachmentInfo(String token, String syncSource, String action, String caseNo, MsCaseFileInfo msCaseFileInfo);
|
||||
|
||||
/**
|
||||
* 推送案件状态信息(调解系统推送案件状态时调用)
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @param caseNo 案件编号
|
||||
* @param statusCode 案件状态编码
|
||||
* @param caseClosureExplanation 案件状态描述(或结案信息)
|
||||
* @return
|
||||
*/
|
||||
JSONObject pushCaseStatusInfo(String username, String password, String caseNo, String statusCode, String caseClosureExplanation);
|
||||
|
||||
/**
|
||||
* 推送案件附件信息(调解系统推送案件附件信息时调用)
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @param file 文件
|
||||
* @param abutmentId 调解系统文件Id
|
||||
* @param syncSource 用户名
|
||||
* @param caseNo 案件编号
|
||||
* @return
|
||||
*/
|
||||
JSONObject pushAttachmentInfo(String username, String password, File file, String abutmentId, String syncSource, String caseNo);
|
||||
}
|
||||
+316
@@ -0,0 +1,316 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.ruoyi.common.enums.AttachmentOperateTypeEnum;
|
||||
import com.ruoyi.system.service.BeiMingInterface;
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseFileInfo;
|
||||
import com.ruoyi.wisdomarbitrate.domain.vo.mscase.MsCaseStatusInfo;
|
||||
import com.ruoyi.wisdomarbitrate.utils.CommonInputStreamResource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import static com.ruoyi.common.utils.EncryptUtils.sm4Decrypt;
|
||||
import static com.ruoyi.common.utils.EncryptUtils.sm4Encrypt;
|
||||
|
||||
/**
|
||||
* @author ym
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class BeiMingInterfaceService implements BeiMingInterface {
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
/**
|
||||
* 接口地址
|
||||
*/
|
||||
@Value("${beimingapihost}")
|
||||
public String apihost;
|
||||
/**
|
||||
* 接口路径前缀
|
||||
*/
|
||||
@Value("${beimingapiprefix}")
|
||||
public String apiprefix;
|
||||
@Value("${beimingprivatekey}")
|
||||
public String privateKey;
|
||||
|
||||
/**
|
||||
* 1.获取北明接口令牌token
|
||||
*
|
||||
* @param userName
|
||||
* @param password
|
||||
* @param times
|
||||
*/
|
||||
@Override
|
||||
public String getApiToken(String userName, String password, Long times) {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
//设置请求头
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
//传递请求体时必须设置传递参数的格式,为Content-Type : application/json
|
||||
httpHeaders.add("Content-Type", "application/json;charset=UTF-8");
|
||||
httpHeaders.add("syncSource", userName);
|
||||
// 2.请求头 & 请求体
|
||||
HttpEntity<JSON> fromEntity = new HttpEntity(httpHeaders);
|
||||
JSONObject body = new JSONObject();
|
||||
// body.put("account", userName);
|
||||
// body.put("password", password);
|
||||
// body.put("timestamp", times);
|
||||
//对整体请求进行加密
|
||||
ObjectNode param = new ObjectMapper().createObjectNode();
|
||||
param.put("account", userName);
|
||||
param.put("password", password);
|
||||
param.put("timestamp", times);
|
||||
String encryptString = sm4Encrypt(param.toString(), privateKey);
|
||||
body.put("encryptString", encryptString);
|
||||
System.out.println("encryptString:" + encryptString);
|
||||
fromEntity = new HttpEntity(body, httpHeaders);
|
||||
String url = apihost + apiprefix + "/getToken";
|
||||
result = restTemplate.postForObject(url, fromEntity, JSONObject.class);
|
||||
} catch (RestClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析加密后端token
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
public String analysisResultToken(String token) {
|
||||
String resultToken = null;
|
||||
if (token != null && !token.isEmpty()) {
|
||||
JSONObject jsonObject = JSON.parseObject(token);
|
||||
String tokenString = jsonObject.getString("data");
|
||||
System.out.println("data信息:" + tokenString);
|
||||
String tokenstr = sm4Decrypt(tokenString, privateKey);
|
||||
System.out.println("解密后的字符串:" + tokenstr);
|
||||
if (tokenstr != null && !tokenstr.isEmpty()) {
|
||||
JSONObject tokenObject = JSON.parseObject(tokenstr);
|
||||
resultToken = tokenObject.getString("token");
|
||||
}
|
||||
}
|
||||
return resultToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* 2.推送案件状态信息
|
||||
*
|
||||
* @param token 令牌
|
||||
* @param abutmentId 第三方平台案件唯一标识
|
||||
* @param msCaseStatusInfo 案件状态信息
|
||||
* @param syncSource 同步来源(账户名)
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JSONObject submitCaseStatusInfo(String token, String abutmentId, String syncSource, MsCaseStatusInfo msCaseStatusInfo) {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
//设置请求头
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
//传递请求体时必须设置传递参数的格式,为Content-Type : application/json
|
||||
httpHeaders.add("Content-Type", "application/json;charset=UTF-8");
|
||||
httpHeaders.add("token", token);
|
||||
httpHeaders.add("syncSource", syncSource);
|
||||
//对整体请求进行加密
|
||||
ObjectNode param = new ObjectMapper().createObjectNode();
|
||||
param.put("abutmentId", abutmentId);
|
||||
param.put("caseNo", msCaseStatusInfo.getCaseNo());
|
||||
param.put("statusCode", msCaseStatusInfo.getStatusCode());
|
||||
param.put("caseClosureExplanation", msCaseStatusInfo.getCaseClosureExplanation());
|
||||
String encryptString = sm4Encrypt(param.toString(), privateKey);
|
||||
// 2.请求头 & 请求体
|
||||
HttpEntity<JSON> fromEntity = new HttpEntity(httpHeaders);
|
||||
JSONObject body = new JSONObject();
|
||||
// body.put("abutmentId", Encrypt("abutmentId",abutmentId));
|
||||
// body.put("caseNo", Encrypt("caseNo", msCaseStatusInfo.getCaseNo()));
|
||||
// body.put("statusCode", Encrypt("statusCode",msCaseStatusInfo.getStatusCode()));
|
||||
// body.put("caseClosureExplanation", Encrypt("caseClosureExplanation", msCaseStatusInfo.getCaseClosureExplanation()));
|
||||
//对整体请求进行加密
|
||||
body.put("encryptString", encryptString);
|
||||
fromEntity = new HttpEntity(body, httpHeaders);
|
||||
|
||||
String url = apihost + apiprefix + "/caseMediation/status";
|
||||
result = restTemplate.postForObject(url, fromEntity, JSONObject.class);
|
||||
} catch (RestClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 3.上传附件
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JSONObject uploadFile(File file, String token, String syncSource) {
|
||||
System.out.println("文件:" + file.getName());
|
||||
System.out.println("文件:" + file.toString());
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
//设置请求头
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
//传递请求体时必须设置传递参数的格式,为Content-Type : application/json
|
||||
httpHeaders.add("Content-Type", "multipart/form-data");
|
||||
httpHeaders.add("token", token);
|
||||
httpHeaders.add("syncSource", syncSource);
|
||||
// 构建请求体
|
||||
MultiValueMap<String, Object> requestBody = new LinkedMultiValueMap<>();
|
||||
CommonInputStreamResource commonInputStreamResource = null;
|
||||
try {
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
commonInputStreamResource = new CommonInputStreamResource(fileInputStream, file.length(), file.getName());
|
||||
} catch (Exception e) {
|
||||
log.error("文件输入流转换错误", e);
|
||||
}
|
||||
requestBody.add("file", commonInputStreamResource);
|
||||
HttpEntity<MultiValueMap> fromEntity = new HttpEntity<MultiValueMap>(requestBody, httpHeaders);
|
||||
String url = apihost + apiprefix + "/uploadFile";
|
||||
result = restTemplate.postForObject(url, fromEntity, JSONObject.class);
|
||||
} catch (RestClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 4.同步附件信息
|
||||
*
|
||||
* @param token
|
||||
* @param syncSource 用户名
|
||||
* @param action 附件操作类型
|
||||
* @param caseNo 案件编号
|
||||
* @param msCaseFileInfo 案件附件信息
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JSONObject syncAttachmentInfo(String token, String syncSource, String action, String caseNo, MsCaseFileInfo msCaseFileInfo) {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
//设置请求头
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
//传递请求体时必须设置传递参数的格式,为Content-Type : application/json
|
||||
httpHeaders.add("Content-Type", "application/json;charset=UTF-8");
|
||||
httpHeaders.add("token", token);
|
||||
httpHeaders.add("syncSource", syncSource);
|
||||
//对整体请求进行加密
|
||||
ObjectNode param = new ObjectMapper().createObjectNode();
|
||||
param.put("caseNo", caseNo);
|
||||
param.put("action", action);
|
||||
param.put("abutmentId", msCaseFileInfo.getAbutmentId());
|
||||
param.put("abutmentCaseId", msCaseFileInfo.getAbutmentCaseId());
|
||||
param.put("documentSubject", msCaseFileInfo.getDocumentSubject());
|
||||
param.put("documentType", msCaseFileInfo.getDocumentType());
|
||||
param.put("fileName", msCaseFileInfo.getFileName());
|
||||
param.put("fileId", msCaseFileInfo.getFileId());
|
||||
if (msCaseFileInfo.getOwnerType() != null) {
|
||||
param.put("ownerType", msCaseFileInfo.getOwnerType());
|
||||
}
|
||||
if (msCaseFileInfo.getOwnerId() != null) {
|
||||
param.put("ownerId", msCaseFileInfo.getOwnerId());
|
||||
}
|
||||
if (msCaseFileInfo.getOwnerName() != null) {
|
||||
param.put("ownerName", msCaseFileInfo.getOwnerName());
|
||||
}
|
||||
String encryptString = sm4Encrypt(param.toString(), privateKey);
|
||||
// 2.请求体
|
||||
HttpEntity<JSON> fromEntity = new HttpEntity(httpHeaders);
|
||||
JSONObject body = new JSONObject();
|
||||
//对整体请求进行加密
|
||||
body.put("encryptString", encryptString);
|
||||
fromEntity = new HttpEntity(body, httpHeaders);
|
||||
String url = apihost + apiprefix + "/caseMediation/attachment/accept";
|
||||
result = restTemplate.postForObject(url, fromEntity, JSONObject.class);
|
||||
} catch (RestClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送案件状态信息
|
||||
*/
|
||||
@Override
|
||||
public JSONObject pushCaseStatusInfo(String username, String password, String caseNo, String statusCode, String caseClosureExplanation) {
|
||||
JSONObject result = new JSONObject();
|
||||
String token = getApiToken(username, password, System.currentTimeMillis());
|
||||
token = analysisResultToken(token);
|
||||
if (token != null && !token.isEmpty()) {
|
||||
MsCaseStatusInfo info = MsCaseStatusInfo.builder().caseNo(caseNo).statusCode(statusCode).caseClosureExplanation(caseClosureExplanation).build();
|
||||
result = submitCaseStatusInfo(token, caseNo, username, info);
|
||||
System.out.println("jieguo:" + result.toString());
|
||||
if (result != null) {
|
||||
String data = result.getString("data");
|
||||
String datastr = sm4Decrypt(data, privateKey);
|
||||
System.out.println("最终解密后的字符串:" + datastr);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送案件附件信息
|
||||
*/
|
||||
@Override
|
||||
public JSONObject pushAttachmentInfo(String username, String password, File file, String abutmentId, String syncSource, String caseNo) {
|
||||
JSONObject result = new JSONObject();
|
||||
//1.获取token
|
||||
String token = getApiToken(username, password, System.currentTimeMillis());
|
||||
token = analysisResultToken(token);
|
||||
if (token != null && !token.isEmpty()) {
|
||||
//2.上传文件
|
||||
JSONObject fileResult = uploadFile(file, token, syncSource);
|
||||
if (fileResult != null) {
|
||||
String data = fileResult.getString("data");
|
||||
String datastr = sm4Decrypt(data, privateKey);
|
||||
System.out.println("最终解密后的字符串:" + datastr);
|
||||
if (datastr != null) {
|
||||
JSONObject parse = JSON.parseObject(datastr);
|
||||
if (parse != null) {
|
||||
String fileId = parse.getString("fileId");
|
||||
System.out.println("fileId====:" + fileId);
|
||||
if (fileId != null) {
|
||||
//3.同步附件更新信息
|
||||
MsCaseFileInfo fileInfo = MsCaseFileInfo.builder().fileId(fileId).fileName(file.getName()).abutmentId(abutmentId).abutmentCaseId(caseNo).documentSubject("EVEDENT").documentType("EVEDENT_METERIAL").build();
|
||||
result = syncAttachmentInfo(token, username, AttachmentOperateTypeEnum.ADD.getCode(), caseNo, fileInfo);
|
||||
result = syncAttachmentInfo(token, username, AttachmentOperateTypeEnum.UPD.getCode(), caseNo, fileInfo);
|
||||
result = syncAttachmentInfo(token, username, AttachmentOperateTypeEnum.DEL.getCode(), caseNo, fileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对字段值进行加密
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String Encrypt(String filed, String filedValue) {
|
||||
ObjectNode param = new ObjectMapper().createObjectNode();
|
||||
param.put(filed, filedValue);
|
||||
String encryptString = sm4Encrypt(param.toString(), privateKey);
|
||||
return encryptString;
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.ruoyi.wisdomarbitrate.domain.vo.mscase;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 北明接口案件附件信息入参
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class MsCaseFileInfo {
|
||||
|
||||
/**
|
||||
* 第三方文件唯一标识
|
||||
*/
|
||||
private String abutmentId;
|
||||
/**
|
||||
* 第三方平台案件唯一标识
|
||||
*/
|
||||
private String abutmentCaseId;
|
||||
/**
|
||||
* 第一级文件类型
|
||||
*/
|
||||
private String documentSubject;
|
||||
/**
|
||||
* 第二级文件类型
|
||||
*/
|
||||
private String documentType;
|
||||
/**
|
||||
* 所属人类型(可不传)
|
||||
*/
|
||||
private String ownerType;
|
||||
/**
|
||||
* 文件所属人第三方平台对应的人员唯一标识(可不传)
|
||||
*/
|
||||
private String ownerId;
|
||||
/**
|
||||
* 文件所属人名称(可不传)
|
||||
*/
|
||||
private String ownerName;
|
||||
/**
|
||||
* 文件名称
|
||||
*/
|
||||
private String fileName;
|
||||
/**
|
||||
* 一站式平台返回的文件ID
|
||||
*/
|
||||
private String fileId;
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.ruoyi.wisdomarbitrate.domain.vo.mscase;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* 北明接口案件状态入参
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class MsCaseStatusInfo {
|
||||
/**
|
||||
* 案号
|
||||
* 案件状态编码
|
||||
* 结案说明
|
||||
*/
|
||||
private String caseNo;
|
||||
|
||||
/**
|
||||
* 案件状态编码
|
||||
*/
|
||||
private String statusCode;
|
||||
|
||||
/**
|
||||
* 结案说明
|
||||
*/
|
||||
private String caseClosureExplanation;
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.ruoyi.wisdomarbitrate.utils;
|
||||
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import java.io.InputStream;
|
||||
public class CommonInputStreamResource extends InputStreamResource {
|
||||
private long length;
|
||||
private String fileName;
|
||||
public CommonInputStreamResource(InputStream inputStream, long length, String fileName) {
|
||||
super(inputStream);
|
||||
this.length = length;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆写父类方法
|
||||
* 如果不重写这个方法,并且文件有一定大小,那么服务端会出现异常
|
||||
* {@code The multi-part request contained parameter data (excluding uploaded files) that exceeded}
|
||||
*/
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆写父类 contentLength 方法
|
||||
* 因为 {@link org.springframework.core.io.AbstractResource#contentLength()}方法会重新读取一遍文件,
|
||||
* 而上传文件时,restTemplate 会通过这个方法获取大小。然后当真正需要读取内容的时候,发现已经读完,会报如下错误。
|
||||
*/
|
||||
@Override
|
||||
public long contentLength() {
|
||||
long estimate = length;
|
||||
return estimate == 0 ? 1 : estimate;
|
||||
}
|
||||
|
||||
public void setLength(long length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user