过期验证提交
This commit is contained in:
parent
108066fab2
commit
03c7e2237c
@ -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);
|
||||
}
|
||||
}
|
@ -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()));
|
||||
}
|
||||
}
|
116
ruoyi-ui/src/views/overdue/index.vue
Normal file
116
ruoyi-ui/src/views/overdue/index.vue
Normal 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>
|
Loading…
Reference in New Issue
Block a user