过期验证提交

This commit is contained in:
Yuxuecheng 2025-02-08 14:53:50 +08:00
parent 108066fab2
commit 03c7e2237c
3 changed files with 217 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package com.ruoyi.framework.AES;
import com.ruoyi.framework.constants.Constants;
import org.springframework.stereotype.Component;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
@Component
public class AESExample {
// 加密方法
public static String encrypt(String data) throws Exception {
SecretKeySpec keySpec = generateKey();
Cipher cipher = Cipher.getInstance(Constants.ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
byte[] encryptedBytes = cipher.doFinal(data.getBytes());
return Base64.getEncoder().encodeToString(encryptedBytes);
}
// 解密方法
public String decrypt(String encryptedData) throws Exception {
byte[] decryptedBytes = null;
SecretKeySpec keySpec = generateKey();
Cipher cipher = Cipher.getInstance(Constants.ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, keySpec);
decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encryptedData));
return new String(decryptedBytes);
}
// 生成密钥
private static SecretKeySpec generateKey() throws Exception {
byte[] keyBytes = Constants.SECRET_KEY.getBytes();
return new SecretKeySpec(keyBytes, Constants.ALGORITHM);
}
}

View File

@ -0,0 +1,65 @@
package com.ruoyi.framework.task;
import cn.hutool.core.date.DateTime;
import com.ruoyi.framework.AES.AESExample;
import com.ruoyi.framework.constants.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;
@Component
public class OverdueTask {
private static final Logger log = LoggerFactory.getLogger(OverdueTask.class);
@Resource
private RedisTemplate<String,String> redisTemplate;
@Resource
private AESExample aesExample;
// 每半小时执行一次
@Scheduled(cron = "0 0/30 * * * ?")
public void updateOverdueFromFile() {
String filePath = Constants.KEY_FILE_PATH;
File file = new File(filePath);
// 判断文件是否存在
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
System.err.println("创建文件失败");
e.printStackTrace();
}
}
StringBuilder content = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = reader.readLine()) != null) {
content.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
String decrypt = null;
try {
decrypt = aesExample.decrypt(content.toString());
} catch (Exception e) {
System.err.println("验证程序错误,请检查");
}
redisTemplate.opsForValue().set("overdue", decrypt);
log.info("更新过期时间成功 {} {}", decrypt, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
}
}

View File

@ -0,0 +1,116 @@
<template>
<div class="overdue-page">
<h1>程序已过期</h1>
<p>请输入激活码以继续访问</p>
<input v-model="activationCode" placeholder="请输入激活码"/>
<button @click="submitActivationCode">提交</button>
<p v-if="errorMessage" class="error-message">{{ errorMessage }}</p>
</div>
</template>
<script>
import request from "@/utils/request";
export default {
data() {
return {
activationCode: '', //
errorMessage: '', //
};
},
methods: {
submitActivationCode() {
//
if (!this.activationCode.trim()) {
this.errorMessage = '激活码不能为空,请输入激活码!';
return; //
}
//
this.errorMessage = '';
//
request({
url: '/overdue',
method: 'get',
params: { activationCode: this.activationCode }
}).then((response) => {
// code
if (response.code === 200) {
//
this.$alert('激活成功!!!', '提示', {
confirmButtonText: '确定',
callback: action => {
this.$message({
type: 'success',
message: `激活成功!!!`,
});
this.$router.push('/');
}
});
} else {
//
this.$alert('激活失败,请重新输入', '提示', {
confirmButtonText: '确定',
callback: action => {
this.$message({
type: 'error',
});
}
});
}
})
}
},
};
</script>
<style scoped>
.overdue-page {
text-align: center;
margin-top: 50px;
}
.error-message {
color: red;
margin-top: 10px;
}
</style>
<style scoped>
.overdue-page {
max-width: 400px;
margin: 50px auto;
padding: 20px;
text-align: center;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
input {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.error-message {
color: red;
margin-top: 10px;
}
</style>