1.IM通讯 OTP生成

This commit is contained in:
2025-08-14 21:06:31 +08:00
parent 43302a00b8
commit 6429606fda
6 changed files with 101 additions and 2 deletions

View File

@@ -0,0 +1,12 @@
package vvpkassistant.OTP.model;
import lombok.Data;
/*
* @author: ziin
* @date: 2025/8/14 20:53
*/
@Data
public class OTPDTO {
private String secretKey;
}

View File

@@ -0,0 +1,11 @@
package vvpkassistant.OTP.service;
import vvpkassistant.OTP.model.OTPDTO;
/*
* @author: ziin
* @date: 2025/8/14 20:51
*/
public interface OTPService {
Object getOPT();
}

View File

@@ -0,0 +1,41 @@
package vvpkassistant.OTP.service;
import cn.hutool.core.codec.Base64;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import vvpkassistant.OTP.model.OTPDTO;
import vvpkassistant.common.ErrorCode;
import vvpkassistant.exception.BusinessException;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
/*
* @author: ziin
* @date: 2025/8/14 20:51
*/
@Slf4j
@Service
public class OTPServiceImpl implements OTPService {
@Value("${IM-secretKey}")
private String IM_SecretKey;
@Override
public Object getOPT() {
try {
String otp = "000" + System.currentTimeMillis();
SecretKeySpec key = new SecretKeySpec(IM_SecretKey.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
byte[] otpBytes = otp.getBytes();
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptedOTP = cipher.doFinal(otpBytes);
otp = Base64.encode(encryptedOTP);
return otp;
} catch (Exception e) {
log.error("Failed to generate GoEasy-OTP.", e);
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"Failed to generate GoEasy-OTP.");
}
}
}

View File

@@ -133,10 +133,15 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserModel> implements
@Override
public UserModelVO addUserWithMail(UserModelDTO userModelDTO) {
LambdaQueryWrapper<UserModel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
LambdaQueryWrapper<UserModel> usernameWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UserModel::getEmail,userModelDTO.getEmail());
UserModel userModel = userDao.selectOne(lambdaQueryWrapper);
UserModel usernameModel = userDao.selectOne(lambdaQueryWrapper
UserModel usernameModel = userDao.selectOne(usernameWrapper
.eq(UserModel::getUserName, userModelDTO.getUserName()));
if (userModel != null) {
@@ -341,9 +346,12 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserModel> implements
if (mail != null && mail.isEmpty()) {
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"验证码过期或验证码错误");
}
LambdaQueryWrapper<UserModel> duplicateMailUserWrapper = new LambdaQueryWrapper<>();
LambdaQueryWrapper<UserModel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
UserModel duplicateMailUser = userDao.selectOne(lambdaQueryWrapper.eq(UserModel::getEmail, mailModel.getMailAddress()));
UserModel duplicateMailUser = userDao.selectOne(duplicateMailUserWrapper
.eq(UserModel::getEmail, mailModel.getMailAddress()));
if (duplicateMailUser != null) {
throw new BusinessException(ErrorCode.SYSTEM_ERROR,"邮箱地址已被使用");
}

View File

@@ -0,0 +1,26 @@
package vvpkassistant.controller;
import org.springframework.web.bind.annotation.*;
import vvpkassistant.Data.ResponseData;
import vvpkassistant.OTP.model.OTPDTO;
import vvpkassistant.OTP.service.OTPService;
import javax.annotation.Resource;
/*
* @author: ziin
* @date: 2025/8/14 20:50
*/
@RestController
@RequestMapping("otp")
public class OTPController {
@Resource
private OTPService otpService;
@GetMapping("/getopt")
public ResponseData<Object> getOTP() {
return ResponseData.success(otpService.getOPT());
}
}

View File

@@ -60,3 +60,4 @@ dromara:
domain: https://vv-1317974657.cos.ap-shanghai.myqcloud.com # 访问域名,注意“/”结尾例如https://abc.cos.ap-nanjing.myqcloud.com/
base-path: /headerIcon/ # 基础路径
IM-secretKey: 04452c3231ae4fe5