|
|
@ -5,7 +5,6 @@ import cn.hutool.crypto.digest.MD5; |
|
|
|
import cn.hutool.extra.qrcode.QrCodeUtil; |
|
|
|
import cn.hutool.extra.qrcode.QrConfig; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import com.win.framework.web.core.filter.ModuleAuthenInterceptor; |
|
|
|
import com.win.framework.web.core.util.ModuleAuthenUtils; |
|
|
|
import com.win.module.eam.controller.licences.vo.GenerateLicenceReqVO; |
|
|
|
import com.win.module.eam.mq.message.LicencesMessage; |
|
|
@ -16,13 +15,9 @@ import org.springframework.validation.annotation.Validated; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.crypto.Cipher; |
|
|
|
import javax.crypto.KeyGenerator; |
|
|
|
import javax.crypto.SecretKey; |
|
|
|
import javax.crypto.spec.SecretKeySpec; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
|
import static com.win.module.eam.enums.ErrorCodeConstants.ENCRYPTION_STR_FORMAT_IS_ERROR; |
|
|
@ -30,10 +25,9 @@ import static com.win.module.eam.enums.ErrorCodeConstants.ENCRYPTION_STR_FORMAT_ |
|
|
|
@Service |
|
|
|
@Validated |
|
|
|
public class LicencesServiceImpl implements LicencesService { |
|
|
|
public static final String LICENCES_UPDATE = "system.licences"; |
|
|
|
@Resource |
|
|
|
private RedisTemplate<String, String> redisTemplate; |
|
|
|
|
|
|
|
private static final int KEY_SIZE = 128; |
|
|
|
@Override |
|
|
|
public void licencesDiscernByCodeImage(MultipartFile file) throws IOException { |
|
|
|
licenceDiscernByCodeStr(QrCodeUtil.decode(file.getInputStream())); |
|
|
@ -51,20 +45,22 @@ public class LicencesServiceImpl implements LicencesService { |
|
|
|
if (Util.isNullOrEmpty(tmpSecretKey)) { |
|
|
|
throw exception(ENCRYPTION_STR_FORMAT_IS_ERROR); |
|
|
|
} |
|
|
|
ModuleAuthenUtils.secretKey = tmpSecretKey; |
|
|
|
String dataStr = codeJson.getStr("data"); |
|
|
|
if (Util.isNullOrEmpty(dataStr)) { |
|
|
|
throw exception(ENCRYPTION_STR_FORMAT_IS_ERROR); |
|
|
|
} |
|
|
|
//todo 需迁移至mq订阅逻辑中
|
|
|
|
JSONObject tmpJson = new JSONObject(ModuleAuthenUtils.decrypt(dataStr)); |
|
|
|
|
|
|
|
JSONObject tmpJson = new JSONObject(ModuleAuthenUtils.decrypt(dataStr,tmpSecretKey)); |
|
|
|
if (tmpJson.isEmpty()) { |
|
|
|
throw exception(ENCRYPTION_STR_FORMAT_IS_ERROR); |
|
|
|
} |
|
|
|
ModuleAuthenUtils.moduleExpire = tmpJson; |
|
|
|
ModuleAuthenUtils.module = tmpJson; |
|
|
|
|
|
|
|
redisTemplate.opsForValue().set(ModuleAuthenUtils.LICENCES_MODULES, ModuleAuthenUtils.module.toString()); |
|
|
|
redisTemplate.opsForValue().set(ModuleAuthenUtils.LICENCES_SECRET_KEY, tmpSecretKey); |
|
|
|
//todo 更新到redis并使用发布订阅通知其他pods拉取过滤路径
|
|
|
|
redisTemplate.opsForValue().set(LICENCES_UPDATE, ModuleAuthenUtils.moduleExpire.toString()); |
|
|
|
redisTemplate.convertAndSend(LICENCES_UPDATE, ModuleAuthenUtils.moduleExpire.toString()); |
|
|
|
redisTemplate.convertAndSend(ModuleAuthenUtils.LICENCES_UPDATE_MESSAGE, ModuleAuthenUtils.module.toString()); |
|
|
|
} catch (Exception e) { |
|
|
|
throw exception(500, e); |
|
|
|
} |
|
|
@ -74,14 +70,16 @@ public class LicencesServiceImpl implements LicencesService { |
|
|
|
public void generateLicence(GenerateLicenceReqVO req, HttpServletResponse response) throws Exception { |
|
|
|
//todo 数据准备
|
|
|
|
LicencesMessage licencesMessage = new LicencesMessage() {{ |
|
|
|
String secretKey = ModuleAuthenUtils.generateKey(); |
|
|
|
KeyGenerator keyGenerator = KeyGenerator.getInstance(ModuleAuthenUtils.ALGORITHM); |
|
|
|
keyGenerator.init(KEY_SIZE); |
|
|
|
String secretKey = Base64.encode(keyGenerator.generateKey().getEncoded()); |
|
|
|
setSecretKey(secretKey); |
|
|
|
MD5 md5 = MD5.create(); |
|
|
|
JSONObject modules = new JSONObject(){{ |
|
|
|
put(md5.digestHex("/MES"),ModuleAuthenUtils.encrypt("2025-10-10 00:00:00")); |
|
|
|
put(md5.digestHex("/WMS"),ModuleAuthenUtils.encrypt("2025-10-10 00:00:00")); |
|
|
|
put(md5.digestHex("admin-api"),ModuleAuthenUtils.encrypt("2025-10-10 00:00:00", secretKey)); |
|
|
|
put(md5.digestHex("mes"),ModuleAuthenUtils.encrypt("2025-10-10 00:00:00", secretKey)); |
|
|
|
}}; |
|
|
|
setData(ModuleAuthenUtils.encrypt(modules.toString())); |
|
|
|
setData(ModuleAuthenUtils.encrypt(modules.toString(), secretKey)); |
|
|
|
}}; |
|
|
|
//todo 生成二维码
|
|
|
|
QrConfig config = new QrConfig(300, 300); |
|
|
|