新增查询加密后的明文信息接口,新增加密视频会议相关信息方法

This commit is contained in:
wangqiong
2024-04-12 17:42:14 +08:00
parent a851d66423
commit b56288cc8c
10 changed files with 218 additions and 62 deletions
@@ -4,12 +4,9 @@ import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wisdomarbitrate.domain.dto.sendrecord.SmsSendRecord; import com.ruoyi.wisdomarbitrate.domain.dto.sendrecord.SmsSendRecord;
import com.ruoyi.wisdomarbitrate.mapper.sendrecord.SmsRecordMapper; import com.ruoyi.wisdomarbitrate.mapper.sendrecord.SmsRecordMapper;
import com.ruoyi.wisdomarbitrate.service.sendrecord.ShortMessageService; import com.ruoyi.wisdomarbitrate.service.shortmessage.ShortMessageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date; import java.util.Date;
@@ -46,4 +43,17 @@ public class ShortMessageController {
} }
return AjaxResult.error("发送失败"); return AjaxResult.error("发送失败");
} }
/**
* 查询UID好的密钥
*/
@Anonymous
@GetMapping("/getEncryptInfoByid")
public Object getEncryptInfoByUid(@RequestParam(name = "id",required = true) String id) {
if (id != null) {
Object result = shortMessageService.getEncryptInfoByUid(id);
return result;
}
return AjaxResult.error("查询失败");
}
} }
@@ -218,3 +218,4 @@ BMConfig:
beimingapihost: https://zj.odrcloud.cn beimingapihost: https://zj.odrcloud.cn
beimingapiprefix: /onestop/sync beimingapiprefix: /onestop/sync
beimingprivatekey: d7724e72c4be93196a35203e8379ded5 beimingprivatekey: d7724e72c4be93196a35203e8379ded5
shortMessageKey: 936df5fd9aba3b86adc3c1a1c52dcde1
@@ -112,10 +112,17 @@ public class EncryptUtils {
public static void main(String[] args) { public static void main(String[] args) {
String privateKey = "936df5fd9aba3b86adc3c1a1c52dcde1"; String privateKey = "936df5fd9aba3b86adc3c1a1c52dcde1";
ObjectNode param = new ObjectMapper().createObjectNode(); ObjectNode param = new ObjectMapper().createObjectNode();
param.put("name", "姓名"); param.put("userName", "张三");
param.put("caseNo", "ZC1234125");
param.put("userId", "124124");
param.put("roomId", "124125");
param.put("systemType", "tiaojiexitong");
String encryptString = sm4Encrypt(param.toString(), privateKey); String encryptString = sm4Encrypt(param.toString(), privateKey);
System.out.println("加密后的字符串:" + encryptString); System.out.println("加密后的字符串:" + encryptString);
String uid = UUID.randomUUID().toString().replace("-", "");
System.out.println("uid:" + uid);
System.out.println("解密后的字符串:" + sm4Decrypt(encryptString, privateKey)); System.out.println("解密后的字符串:" + sm4Decrypt(encryptString, privateKey));
} }
} }
@@ -0,0 +1,31 @@
package com.ruoyi.system.domain.entity.shortmessage;
import java.util.Date;
import javax.persistence.*;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@Table(name = "encryptend_info")
public class EncryptendInfo {
/**
* 主键
*/
@Id
private String uid;
/**
* 加密后的内容
*/
@Column(name = "encrypted_content")
private String encryptedContent;
/**
* 创建时间
*/
@Column(name = "create_time")
private Date createTime;
}
@@ -0,0 +1,7 @@
package com.ruoyi.system.mapper.shortmessage;
import com.ruoyi.system.domain.entity.shortmessage.EncryptendInfo;
import tk.mybatis.mapper.common.Mapper;
public interface EncryptendInfoMapper extends Mapper<EncryptendInfo> {
}
@@ -0,0 +1,21 @@
package com.ruoyi.wisdomarbitrate.domain.vo.secret;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SecretInfo {
/**
* 用户登录名、案件编号、用户id、房间号、跳转系统类型(tiaojie、zhongcai)
*/
private String userName;
private String caseNo;
private String userId;
private Integer roomId;
private String systemType;
}
@@ -1,54 +0,0 @@
package com.ruoyi.wisdomarbitrate.service.sendrecord.impl;
import cn.hutool.json.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.SMSStatusEnum;
import com.ruoyi.common.utils.SmsUtils;
import com.ruoyi.system.domain.entity.shortmessage.MsSmsSendHistoryRecord;
import com.ruoyi.system.mapper.shortmessage.MsSmsSendHistoryRecordMapper;
import com.ruoyi.wisdomarbitrate.domain.dto.sendrecord.SmsSendRecord;
import com.ruoyi.wisdomarbitrate.service.sendrecord.ShortMessageService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ShortMessageServiceImpl implements ShortMessageService {
@Autowired
MsSmsSendHistoryRecordMapper msSmsSendHistoryRecordMapper;
/**
* 新增发送历史记录
*
* @param smsSendRecord
*/
@Override
public void insertShortMessageHistoryRecord(SmsSendRecord smsSendRecord) {
if(smsSendRecord!=null){
MsSmsSendHistoryRecord historyRecord=new MsSmsSendHistoryRecord();
BeanUtils.copyProperties(smsSendRecord,historyRecord);
historyRecord.setId(null);
historyRecord.setParentId(smsSendRecord.getId());
msSmsSendHistoryRecordMapper.insert(historyRecord);
}
}
/**
* 重新发送短信
*
* @param smsSendRecord
*/
@Override
public AjaxResult reSendShortMessage(SmsSendRecord smsSendRecord) {
SmsUtils.SendSmsRequest request = new SmsUtils.SendSmsRequest();
//TODO 模版id待替换
request.setTemplateId("1955047");
request.setPhone(smsSendRecord.getPhone());
request.setTemplateParamSet(new String[]{ smsSendRecord.getSendContent()});
JSONObject resultObj = SmsUtils.sendSms(request);
if(resultObj.get("status")!=null && !resultObj.get("status").equals(SMSStatusEnum.FAIL.getCode())){
return AjaxResult.success("短信发送成功");
}else {
return AjaxResult.warn("短信发送失败");
}
}
}
@@ -1,9 +1,10 @@
package com.ruoyi.wisdomarbitrate.service.sendrecord; package com.ruoyi.wisdomarbitrate.service.shortmessage;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.entity.shortmessage.MsSmsSendHistoryRecord; import com.ruoyi.system.domain.entity.shortmessage.MsSmsSendHistoryRecord;
import com.ruoyi.system.mapper.shortmessage.MsSmsSendHistoryRecordMapper; import com.ruoyi.system.mapper.shortmessage.MsSmsSendHistoryRecordMapper;
import com.ruoyi.wisdomarbitrate.domain.dto.sendrecord.SmsSendRecord; import com.ruoyi.wisdomarbitrate.domain.dto.sendrecord.SmsSendRecord;
import com.ruoyi.wisdomarbitrate.domain.vo.secret.SecretInfo;
public interface ShortMessageService { public interface ShortMessageService {
/** /**
@@ -16,4 +17,15 @@ public interface ShortMessageService {
* @param smsSendRecord * @param smsSendRecord
*/ */
AjaxResult reSendShortMessage(SmsSendRecord smsSendRecord); AjaxResult reSendShortMessage(SmsSendRecord smsSendRecord);
/**
* 根据信息生成加密信息记录
* @param secretInfo
* @return
*/
String buildEncryptInfoRecord(SecretInfo secretInfo);
/**
* 通过UID查询加密信息并解密成明文对象
*/
Object getEncryptInfoByUid(String uid);
} }
@@ -0,0 +1,109 @@
package com.ruoyi.wisdomarbitrate.service.shortmessage.impl;
import cn.hutool.json.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.SMSStatusEnum;
import com.ruoyi.common.utils.SmsUtils;
import com.ruoyi.system.domain.entity.shortmessage.EncryptendInfo;
import com.ruoyi.system.domain.entity.shortmessage.MsSmsSendHistoryRecord;
import com.ruoyi.system.mapper.shortmessage.EncryptendInfoMapper;
import com.ruoyi.system.mapper.shortmessage.MsSmsSendHistoryRecordMapper;
import com.ruoyi.wisdomarbitrate.domain.dto.sendrecord.SmsSendRecord;
import com.ruoyi.wisdomarbitrate.domain.vo.secret.SecretInfo;
import com.ruoyi.wisdomarbitrate.service.shortmessage.ShortMessageService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.UUID;
import static com.ruoyi.common.utils.EncryptUtils.sm4Decrypt;
import static com.ruoyi.common.utils.EncryptUtils.sm4Encrypt;
@Service
public class ShortMessageServiceImpl implements ShortMessageService {
@Value("${shortMessageKey}")
private String shortMessageKey;
@Autowired
MsSmsSendHistoryRecordMapper msSmsSendHistoryRecordMapper;
@Autowired
EncryptendInfoMapper encryptendInfoMapper;
/**
* 新增发送历史记录
*
* @param smsSendRecord
*/
@Override
public void insertShortMessageHistoryRecord(SmsSendRecord smsSendRecord) {
if (smsSendRecord != null) {
MsSmsSendHistoryRecord historyRecord = new MsSmsSendHistoryRecord();
BeanUtils.copyProperties(smsSendRecord, historyRecord);
historyRecord.setId(null);
historyRecord.setParentId(smsSendRecord.getId());
msSmsSendHistoryRecordMapper.insert(historyRecord);
}
}
/**
* 重新发送短信
*
* @param smsSendRecord
*/
@Override
public AjaxResult reSendShortMessage(SmsSendRecord smsSendRecord) {
SmsUtils.SendSmsRequest request = new SmsUtils.SendSmsRequest();
//TODO 模版id待替换
request.setTemplateId("1955047");
request.setPhone(smsSendRecord.getPhone());
request.setTemplateParamSet(new String[]{smsSendRecord.getSendContent()});
JSONObject resultObj = SmsUtils.sendSms(request);
if (resultObj.get("status") != null && !resultObj.get("status").equals(SMSStatusEnum.FAIL.getCode())) {
return AjaxResult.success("短信发送成功");
} else {
return AjaxResult.warn("短信发送失败");
}
}
/**
* 根据信息生成加密信息记录
*
* @param secretInfo
* @return
*/
@Override
public String buildEncryptInfoRecord(SecretInfo secretInfo) {
String privateKey = shortMessageKey;
ObjectNode param = new ObjectMapper().createObjectNode();
param.put("userName", secretInfo.getUserName());
param.put("caseNo", secretInfo.getCaseNo());
param.put("userId", secretInfo.getUserId());
param.put("roomId", secretInfo.getRoomId());
param.put("systemType", secretInfo.getSystemType());
String encryptString = sm4Encrypt(param.toString(), privateKey);
String uid = UUID.randomUUID().toString().replace("-", "");
EncryptendInfo encryptendInfo = new EncryptendInfo();
encryptendInfo.setUid(uid);
encryptendInfo.setEncryptedContent(encryptString);
encryptendInfoMapper.insertSelective(encryptendInfo);
System.out.println("加密后的字符串:" + encryptString);
return uid;
}
/**
* 通过UID查询加密信息并解密成明文对象
*
* @param uid
*/
@Override
public Object getEncryptInfoByUid(String uid) {
EncryptendInfo encryptendInfo = encryptendInfoMapper.selectByPrimaryKey(uid);
if (encryptendInfo != null) {
return sm4Decrypt(encryptendInfo.getEncryptedContent(), shortMessageKey);
}
return null;
}
}
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.shortmessage.EncryptendInfoMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.system.domain.entity.shortmessage.EncryptendInfo">
<!--
WARNING - @mbg.generated
-->
<id column="uid" jdbcType="VARCHAR" property="uid" />
<result column="encrypted_content" jdbcType="VARCHAR" property="encryptedContent" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
</mapper>