|
@@ -10,6 +10,7 @@ import cn.kdan.pdf.tech.core.service.VppDeviceService;
|
|
|
import cn.kdan.pdf.tech.core.service.VppLicenseCodeService;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
@@ -19,20 +20,21 @@ import org.springframework.util.StringUtils;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Component
|
|
|
@RequiredArgsConstructor
|
|
|
public class LicenseTask {
|
|
|
private final VppLicenseCodeService licenseCodeService;
|
|
|
private final VppDeviceService vppDeviceService;
|
|
|
private final SubscriptionService subscriptionService;
|
|
|
- @Scheduled(fixedRate = 3 * 60 * 60 * 1000) // 每3小时执行一次
|
|
|
+ @Scheduled(fixedRate = 3 * 60 * 1000) // 每3小时执行一次
|
|
|
public void handleLicenseCode() {
|
|
|
List<LicenseCodes> licenseCodes = licenseCodeService.listActive();
|
|
|
//已处理过过期的订阅id
|
|
|
List<String> list = new ArrayList<>();
|
|
|
//验证序列码有效性
|
|
|
//如果过期时间小于当前时间,则置为过期,并且修改订阅状态,序列码状态,设备状态
|
|
|
- licenseCodes.stream().filter(licenseCode -> licenseCode.getAssignedDate() != null).forEach(licenseCode -> {
|
|
|
+ licenseCodes.stream().filter(licenseCode -> licenseCode.getEndUpAt() != null).forEach(licenseCode -> {
|
|
|
verifySign(licenseCode);
|
|
|
if (licenseCode.getEndUpAt().getTime() < System.currentTimeMillis()) {
|
|
|
//过期序列码置为过期
|
|
@@ -40,6 +42,7 @@ public class LicenseTask {
|
|
|
expiredLicenseCode.setId(licenseCode.getId());
|
|
|
expiredLicenseCode.setValidFlag(LicenseCodeStatusEnum.EXPIRED.code());
|
|
|
licenseCodeService.update(expiredLicenseCode);
|
|
|
+ log.error("序列码证时间过期,序列码id:{},过期", licenseCode.getId());
|
|
|
if (!StringUtils.isEmpty(licenseCode.getSubscriptionId()) && !list.contains(licenseCode.getSubscriptionId())) {
|
|
|
Subscriptions subscriptions = new Subscriptions();
|
|
|
subscriptions.setId(licenseCode.getSubscriptionId());
|
|
@@ -59,15 +62,24 @@ public class LicenseTask {
|
|
|
String sign = licenseCode.getSign();
|
|
|
VppPrivateDeployment deployment = new VppPrivateDeployment();
|
|
|
BeanUtils.copyProperties(licenseCode, deployment);
|
|
|
- //将对象转化为json
|
|
|
- String deploymentJson = JSON.toJSONString(deployment) + "vpp_private_deployment";
|
|
|
+ String deploymentJson = deployment.toJSON() + "vpp_private_deployment";
|
|
|
//对上述json进行MD5加密并且和sign对比
|
|
|
String signOriginal = DigestUtils.md5Hex(deploymentJson);
|
|
|
if (!signOriginal.equals(sign)) {
|
|
|
+ log.error("序列码验证失败,序列码id:{},过期,json {}", licenseCode.getId(),deploymentJson);
|
|
|
LicenseCodes expiredLicenseCode = new LicenseCodes();
|
|
|
expiredLicenseCode.setId(licenseCode.getId());
|
|
|
expiredLicenseCode.setValidFlag(LicenseCodeStatusEnum.EXPIRED.code());
|
|
|
licenseCodeService.update(expiredLicenseCode);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String json = " {\"subscription_id\":\"25a14781-e096-3b04-95a5-558b90ed5d6c\",\"cdkey\":\"3AD4-C1BB-79FD-DED8\",\"times\":1,\"product_id\":15,\"end_up_at\":\"2024-01-26 03:12:29\"}vpp_private_deployment";
|
|
|
+ String signOriginal = DigestUtils.md5Hex(json);
|
|
|
+ String sign = "435fa3fb33eb0c24b433b51fcc072ead";
|
|
|
+ if (!signOriginal.equals(sign)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|