From a6195fc2559e4bd7f734a9b747e617a4de337c65 Mon Sep 17 00:00:00 2001 From: wangqiong <1322446236@qq.com> Date: Mon, 15 Apr 2024 17:35:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9F=AD=E4=BF=A1=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sendrecord/ShortMessageController.java | 8 +-- .../src/main/resources/application.yml | 1 - .../com/ruoyi/common/constant/Constants.java | 22 +++--- .../entity/shortmessage/EncryptendInfo.java | 31 --------- .../entity/shortmessage/MeetingInfo.java | 60 ++++++++++++++++ .../shortmessage/EncryptendInfoMapper.java | 7 -- .../shortmessage/MeetingInfoMapper.java | 7 ++ .../domain/vo/secret/SecretInfo.java | 21 ------ .../domain/vo/shortmessage/MeetingInfoVO.java | 41 +++++++++++ .../shortmessage/ShortMessageService.java | 13 ++-- .../impl/ShortMessageServiceImpl.java | 68 +++++++++++-------- .../shortmessage/EncryptendInfoMapper.xml | 12 ---- .../mapper/shortmessage/MeetingInfoMapper.xml | 16 +++++ 13 files changed, 185 insertions(+), 122 deletions(-) delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/entity/shortmessage/EncryptendInfo.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/entity/shortmessage/MeetingInfo.java delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/shortmessage/EncryptendInfoMapper.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/shortmessage/MeetingInfoMapper.java delete mode 100644 ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/secret/SecretInfo.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/shortmessage/MeetingInfoVO.java delete mode 100644 ruoyi-system/src/main/resources/com/ruoyi/system/mapper/shortmessage/EncryptendInfoMapper.xml create mode 100644 ruoyi-system/src/main/resources/com/ruoyi/system/mapper/shortmessage/MeetingInfoMapper.xml diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/sendrecord/ShortMessageController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/sendrecord/ShortMessageController.java index 9eba364..905dbc6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/sendrecord/ShortMessageController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/sendrecord/ShortMessageController.java @@ -48,10 +48,10 @@ public class ShortMessageController { * 查询UID好的密钥 */ @Anonymous - @GetMapping("/getEncryptInfoByid") - public Object getEncryptInfoByUid(@RequestParam(name = "id",required = true) String id) { - if (id != null) { - Object result = shortMessageService.getEncryptInfoByUid(id); + @GetMapping("/getMeetingInfo") + public Object getEncryptInfoByUid(@RequestParam(name = "authId", required = true) String authId) { + if (authId != null) { + Object result = shortMessageService.getMeetingInfo(authId); return result; } return AjaxResult.error("查询失败"); diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 169b903..fa7d84e 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -218,4 +218,3 @@ BMConfig: beimingapihost: https://zj.odrcloud.cn beimingapiprefix: /onestop/sync beimingprivatekey: d7724e72c4be93196a35203e8379ded5 -shortMessageKey: 936df5fd9aba3b86adc3c1a1c52dcde1 \ No newline at end of file diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java index b1b5c79..a185090 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java @@ -4,11 +4,10 @@ import io.jsonwebtoken.Claims; /** * 通用常量信息 - * + * * @author ruoyi */ -public class Constants -{ +public class Constants { /** * UTF-8 字符集 */ @@ -71,7 +70,7 @@ public class Constants * 登录失败 */ public static final String LOGIN_FAIL = "Error"; - + /** * 验证码有效期(分钟) */ @@ -95,6 +94,10 @@ public class Constants * 令牌前缀 */ public static final String LOGIN_USER_KEY = "login_user_key"; + /** + * 会议主键Id + */ + public static final String MEETING_KEY = "meeting_key"; /** * 用户ID @@ -142,23 +145,22 @@ public class Constants public static final String LOOKUP_LDAPS = "ldaps:"; public static final String DEFAULT_PASSWORD = "123456"; // 英文逗号分隔符 - public static final String SPLIT_COMMA =","; + public static final String SPLIT_COMMA = ","; // 中文逗号分隔符 - public static final String CN_SPLIT_COMMA =","; + public static final String CN_SPLIT_COMMA = ","; /** * 自动识别json对象白名单配置(仅允许解析的包名,范围越小越安全) */ - public static final String[] JSON_WHITELIST_STR = { "org.springframework", "com.ruoyi" }; + public static final String[] JSON_WHITELIST_STR = {"org.springframework", "com.ruoyi"}; /** * 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加) */ - public static final String[] JOB_WHITELIST_STR = { "com.ruoyi" }; + public static final String[] JOB_WHITELIST_STR = {"com.ruoyi"}; /** * 定时任务违规的字符 */ - public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", - "org.springframework", "org.apache", "com.ruoyi.common.utils.file", "com.ruoyi.common.config" }; + public static final String[] JOB_ERROR_STR = {"java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", "org.springframework", "org.apache", "com.ruoyi.common.utils.file", "com.ruoyi.common.config"}; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/entity/shortmessage/EncryptendInfo.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/entity/shortmessage/EncryptendInfo.java deleted file mode 100644 index 89fc581..0000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/entity/shortmessage/EncryptendInfo.java +++ /dev/null @@ -1,31 +0,0 @@ -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; -} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/entity/shortmessage/MeetingInfo.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/entity/shortmessage/MeetingInfo.java new file mode 100644 index 0000000..3a3c1df --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/entity/shortmessage/MeetingInfo.java @@ -0,0 +1,60 @@ +package com.ruoyi.system.domain.entity.shortmessage; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.Table; +import java.util.Date; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "meeting_info") +public class MeetingInfo { + /** + * 主键Id + */ + @Id + private String uid; + + /** + * 案件Id + */ + @Column(name = "case_id") + private Long caseId; + + /** + * 用户Id + */ + @Column(name = "user_id") + private Long userId; + + /** + * 用户名称 + */ + @Column(name = "user_name") + private String userName; + + /** + * 房间Id + */ + @Column(name = "room_id") + private String roomId; + + /** + * 系统类型 + */ + @Column(name = "system_type") + private String systemType; + + /** + * 创建时间 + */ + @Column(name = "create_time") + private Date createTime; +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/shortmessage/EncryptendInfoMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/shortmessage/EncryptendInfoMapper.java deleted file mode 100644 index 13c656e..0000000 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/shortmessage/EncryptendInfoMapper.java +++ /dev/null @@ -1,7 +0,0 @@ -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 { -} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/shortmessage/MeetingInfoMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/shortmessage/MeetingInfoMapper.java new file mode 100644 index 0000000..19a4a9c --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/shortmessage/MeetingInfoMapper.java @@ -0,0 +1,7 @@ +package com.ruoyi.system.mapper.shortmessage; + +import com.ruoyi.system.domain.entity.shortmessage.MeetingInfo; +import tk.mybatis.mapper.common.Mapper; + +public interface MeetingInfoMapper extends Mapper { +} \ No newline at end of file diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/secret/SecretInfo.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/secret/SecretInfo.java deleted file mode 100644 index ecf3dd2..0000000 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/secret/SecretInfo.java +++ /dev/null @@ -1,21 +0,0 @@ -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; -} diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/shortmessage/MeetingInfoVO.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/shortmessage/MeetingInfoVO.java new file mode 100644 index 0000000..0f30ac8 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/shortmessage/MeetingInfoVO.java @@ -0,0 +1,41 @@ +package com.ruoyi.wisdomarbitrate.domain.vo.shortmessage; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class MeetingInfoVO { + /** + * 案件Id + */ + private Long caseId; + + /** + * 用户Id + */ + private Long userId; + + /** + * 用户名称 + */ + private String userName; + + /** + * 房间Id + */ + private String roomId; + + /** + * 系统类型 + */ + private String systemType; + /** + * 登录认证令牌 + */ + private String token; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/shortmessage/ShortMessageService.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/shortmessage/ShortMessageService.java index adfbd1c..ba91508 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/shortmessage/ShortMessageService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/shortmessage/ShortMessageService.java @@ -1,10 +1,8 @@ package com.ruoyi.wisdomarbitrate.service.shortmessage; import com.ruoyi.common.core.domain.AjaxResult; -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.domain.vo.secret.SecretInfo; +import com.ruoyi.wisdomarbitrate.domain.vo.shortmessage.MeetingInfoVO; public interface ShortMessageService { /** @@ -14,18 +12,21 @@ public interface ShortMessageService { /** * 重新发送短信 + * * @param smsSendRecord */ AjaxResult reSendShortMessage(SmsSendRecord smsSendRecord); /** * 根据信息生成加密信息记录 - * @param secretInfo + * + * @param meetingInfoVO * @return */ - String buildEncryptInfoRecord(SecretInfo secretInfo); + String buildMeetingInfoRecord(MeetingInfoVO meetingInfoVO); + /** * 通过UID查询加密信息并解密成明文对象 */ - Object getEncryptInfoByUid(String uid); + Object getMeetingInfo(String uid); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/shortmessage/impl/ShortMessageServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/shortmessage/impl/ShortMessageServiceImpl.java index 12b9ae0..05b891b 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/shortmessage/impl/ShortMessageServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/shortmessage/impl/ShortMessageServiceImpl.java @@ -1,36 +1,35 @@ 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.constant.Constants; 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.MeetingInfo; import com.ruoyi.system.domain.entity.shortmessage.MsSmsSendHistoryRecord; -import com.ruoyi.system.mapper.shortmessage.EncryptendInfoMapper; +import com.ruoyi.system.mapper.shortmessage.MeetingInfoMapper; 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.domain.vo.shortmessage.MeetingInfoVO; import com.ruoyi.wisdomarbitrate.service.shortmessage.ShortMessageService; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; 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.Date; +import java.util.HashMap; +import java.util.Map; 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; + MeetingInfoMapper meetingInfoMapper; /** * 新增发送历史记录 @@ -71,25 +70,15 @@ public class ShortMessageServiceImpl implements ShortMessageService { /** * 根据信息生成加密信息记录 * - * @param secretInfo + * @param meetingInfoVO * @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); + public String buildMeetingInfoRecord(MeetingInfoVO meetingInfoVO) { String uid = UUID.randomUUID().toString().replace("-", ""); - EncryptendInfo encryptendInfo = new EncryptendInfo(); - encryptendInfo.setUid(uid); - encryptendInfo.setEncryptedContent(encryptString); - encryptendInfoMapper.insertSelective(encryptendInfo); - System.out.println("加密后的字符串:" + encryptString); + MeetingInfo meetingInfo = MeetingInfo.builder().userId(meetingInfoVO.getUserId()).userName(meetingInfoVO.getUserName()).caseId(meetingInfoVO.getCaseId()).roomId(meetingInfoVO.getRoomId()).systemType(meetingInfoVO.getSystemType()).createTime(new Date()).uid(uid).build(); + meetingInfo.setUid(uid); + meetingInfoMapper.insertSelective(meetingInfo); return uid; } @@ -99,11 +88,30 @@ public class ShortMessageServiceImpl implements ShortMessageService { * @param uid */ @Override - public Object getEncryptInfoByUid(String uid) { - EncryptendInfo encryptendInfo = encryptendInfoMapper.selectByPrimaryKey(uid); - if (encryptendInfo != null) { - return sm4Decrypt(encryptendInfo.getEncryptedContent(), shortMessageKey); + public Object getMeetingInfo(String uid) { + MeetingInfoVO result = new MeetingInfoVO(); + MeetingInfo meetingInfo = meetingInfoMapper.selectByPrimaryKey(uid); + if (meetingInfo != null) { + BeanUtils.copyProperties(meetingInfo, result); + if (result != null) { + Map claims = new HashMap<>(); + claims.put("userName", meetingInfo.getUserName()); + claims.put("userId", meetingInfo.getUserId()); + claims.put(Constants.MEETING_KEY, uid); + String createToken = createToken(claims); + result.setToken(createToken); + } + return result; } return null; } + + // 令牌秘钥 + @Value("${token.secret}") + private String secret; + + private String createToken(Map claims) { + String token = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.HS512, secret).compact(); + return token; + } } diff --git a/ruoyi-system/src/main/resources/com/ruoyi/system/mapper/shortmessage/EncryptendInfoMapper.xml b/ruoyi-system/src/main/resources/com/ruoyi/system/mapper/shortmessage/EncryptendInfoMapper.xml deleted file mode 100644 index e7d32a8..0000000 --- a/ruoyi-system/src/main/resources/com/ruoyi/system/mapper/shortmessage/EncryptendInfoMapper.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/ruoyi-system/src/main/resources/com/ruoyi/system/mapper/shortmessage/MeetingInfoMapper.xml b/ruoyi-system/src/main/resources/com/ruoyi/system/mapper/shortmessage/MeetingInfoMapper.xml new file mode 100644 index 0000000..d3bdf9e --- /dev/null +++ b/ruoyi-system/src/main/resources/com/ruoyi/system/mapper/shortmessage/MeetingInfoMapper.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file