对接接口方法:1.获取token2.更新案件状态3.上传文件4.推送案件附件信息

This commit is contained in:
wangqiong
2024-03-28 18:54:08 +08:00
parent b0f71c6e3a
commit 08f4aca27c
11 changed files with 781 additions and 11 deletions
@@ -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));
}
}