package com.lxzn.auth.security; import com.alibaba.fastjson.JSON; import com.lxzn.auth.LicenseModel; import com.lxzn.framework.model.response.CommonCode; import com.lxzn.framework.model.response.ResponseResult; import com.lxzn.framework.utils.LicenseUtil; import com.lxzn.framework.utils.ValidateUtil; import com.lxzn.framework.utils.date.DateUtil; import com.lxzn.websocket.LicenseWebSocket; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import java.util.Date; /** * @Description: * @Author: zhangherong * @Date: Created in 2021/6/22 17:37 * @Version: 1.0 * @Modified By: */ @Service public class LicenseService { @Value("${license.tip_days}") private Integer expiredTip; @Value("${license.path}") private String licensePath; @Autowired private LicenseWebSocket webSocket; @Scheduled(cron = "0/10 * * * * ?") public void checkLicense(){ String licenseTmp = "EFcAB7+J2pScncHlrSqf/8GfGGIV2nn/o1+cN9rB0i2M/KyVNZ5FG8G9TYh3Y7A1"; if(!ValidateUtil.validateString(licenseTmp)) { String s = JSON.toJSONString(new ResponseResult(CommonCode.LICENSE_ERROR)); webSocket.sendMessage(s); return; } if(!licenseTmp.equals(LicenseModel.getLicense())) { LicenseModel.init(licenseTmp); } if(LicenseModel.CPU_SERIAL_NUMBER == null || LicenseModel.getCpuSerialNumber() == null || LicenseModel.getDncDeviceNumber() == null || LicenseModel.getMdcDeviceNumber() == null || LicenseModel.getExpiredDate() == null || !LicenseModel.CPU_SERIAL_NUMBER.contains(LicenseModel.getCpuSerialNumber())){ String s = JSON.toJSONString(new ResponseResult(CommonCode.LICENSE_ERROR)); webSocket.sendMessage(s); return; } Date now = DateUtil.getNow(); Date expire = DateUtil.toDate(LicenseModel.getExpiredDate(), DateUtil.STR_DATE); if(now.getTime() >= expire.getTime()){ String s = JSON.toJSONString(new ResponseResult(CommonCode.LICENSE_EXPIRED)); webSocket.sendMessage(s); return; } Date willExpire = DateUtil.addDay(expire, expiredTip * -1); if(now.getTime() >= willExpire.getTime()) { String s = JSON.toJSONString(new ResponseResult(CommonCode.LICENSE_WILL_EXPIRED)); webSocket.sendMessage(s); return; } } }