From ada6760e4d8594ce0daceab156ef64157f66054c Mon Sep 17 00:00:00 2001 From: whyclxw <http://whyclxw@118.89.139.230:10101/r/~whyclxw/IdeaTest.git> Date: 星期三, 15 十二月 2021 10:35:13 +0800 Subject: [PATCH] Merge branch 'master' of http://118.89.139.230:10101/r/fg_v2.0 --- src/main/java/com/whyc/controller/LicenseController.java | 117 ++++++++++++++++++++++++++++------------------------------ 1 files changed, 56 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/whyc/controller/LicenseController.java b/src/main/java/com/whyc/controller/LicenseController.java index 049ba4f..30983ff 100644 --- a/src/main/java/com/whyc/controller/LicenseController.java +++ b/src/main/java/com/whyc/controller/LicenseController.java @@ -84,72 +84,67 @@ @ApiOperation(value = "鏍¢獙license") public Response checkSerialNumberLicense(@RequestParam String license){ Response model = new Response(); - try { - //鑾峰彇macid鏄惁涓�鑷� - boolean res = false; - //鍒濆鍖杝m2鍙傛暟x - SM2 x = new SM2(); - String realPath = ClassUtils.getDefaultClassLoader().getResource("").getPath(); - BigInteger privKey = x.importPrivateKey(realPath + "config/pri_key.ksm"); - ECPoint pubKey = x.importPublicKey(realPath + "config/pub_key.ksm"); - String origin = "Company: Fuguang Electronic\n" - + "Project:BTS monitor platform\n" - + "Licence duration:"; - //鑾峰彇瑙e瘑鍚巐icense,闄勫甫鏍¢獙license缂栫爜鏍煎紡 - String decryptResult = null; - try { - byte[] bytes = ByteConvertUtil.hexToByteArray(license); - decryptResult = x.decrypt(bytes, privKey); - } catch (Exception e) { - e.printStackTrace(); - model.setMsg("lincense閿欒"); - return model; - } - //鐢ㄦ埛鍙兘寰�灏忚皟鏃堕棿 - String[] split1 = decryptResult.split("machineCode:"); - Long registerCodeTime = Long.valueOf(split1[0]); - Long machineCodeCreateTime = Long.valueOf(split1[1].split("createTime")[0]); - //妫�楠岃В鐮佸悗license鐨勫�兼槸鍚︽纭� - String serialNumberStr = SerialNumberUtil.getSerialNumber() + "@@" + origin; - res = decryptResult.contains(serialNumberStr); - if (res) { - //鏍¢獙license杈撳叆鏃堕棿鏄惁瓒呰繃5鍒嗛挓,5鍒嗛挓鍐呭垯瀛樺偍鍒版暟鎹簱涓� - long currentTimeMillis = System.currentTimeMillis(); - //long serialNumberLicenseTime = (long) getApplication().getAttribute("serialNumberLicenseTime"); - //if(currentTimeMillis-serialNumberLicenseTime>=5*60*1000){ - if (currentTimeMillis - machineCodeCreateTime >= 5 * 60 * 1000) { - model.setCode(0); - model.setMsg("娉ㄥ唽鐮佽幏鍙栧強杈撳叆瓒呰繃5鍒嗛挓,璇烽噸鏂拌幏鍙栨敞鍐岀爜"); - } else if (registerCodeTime > currentTimeMillis) { - model.setCode(0); - model.setMsg("绯荤粺鏃堕棿涓嶆甯�,璇锋鏌�"); - } else { - model.setCode(1); - model.setMsg("娉ㄥ唽鐮佹牎楠屾垚鍔�"); - } - //model.setData(decryptResult); - //model.setMsgN(serialNumberStr); - double duration = Integer.parseInt(decryptResult.split("duration:")[1]); - License data = new License(); - data.setSerialNumber(SerialNumberUtil.getSerialNumber()); - //duration鍜孴imeInUse鍔犲瘑瀛樺叆鏁版嵁搴� - String durationEncrypt = AESUtil.aesEncrypt(String.valueOf(duration)); - data.setDuration(durationEncrypt); - String timeInUseEncrypt = AESUtil.aesEncrypt(String.valueOf(0)); - data.setTimeInUse(timeInUseEncrypt); - //灏嗗簭鍒楀彿,鏈夋晥鏈� 娣诲姞鍏icense琛� - service.add(data); + //鑾峰彇macid鏄惁涓�鑷� + boolean res = false; + //鍒濆鍖杝m2鍙傛暟x + SM2 x = new SM2(); + String realPath = ClassUtils.getDefaultClassLoader().getResource("").getPath(); + BigInteger privKey = x.importPrivateKey(realPath + "config/pri_key.ksm"); + ECPoint pubKey = x.importPublicKey(realPath + "config/pub_key.ksm"); + String origin = "Company: Fuguang Electronic\n" + + "Project:BTS monitor platform\n" + + "Licence duration:"; + //鑾峰彇瑙e瘑鍚巐icense,闄勫甫鏍¢獙license缂栫爜鏍煎紡 + String decryptResult = null; + byte[] bytes = ByteConvertUtil.hexToByteArray(license); + decryptResult = x.decrypt(bytes, privKey); + //鐢ㄦ埛鍙兘寰�灏忚皟鏃堕棿 + String[] split1 = decryptResult.split("machineCode:"); + Long registerCodeTime = Long.valueOf(split1[0]); + Long machineCodeCreateTime = Long.valueOf(split1[1].split("createTime")[0]); + //妫�楠岃В鐮佸悗license鐨勫�兼槸鍚︽纭� + String serialNumberStr = SerialNumberUtil.getSerialNumber() + "@@" + origin; + res = decryptResult.contains(serialNumberStr); + if (res) { + //鏍¢獙license杈撳叆鏃堕棿鏄惁瓒呰繃5鍒嗛挓,5鍒嗛挓鍐呭垯瀛樺偍鍒版暟鎹簱涓� + long currentTimeMillis = System.currentTimeMillis(); + //long serialNumberLicenseTime = (long) getApplication().getAttribute("serialNumberLicenseTime"); + //if(currentTimeMillis-serialNumberLicenseTime>=5*60*1000){ + if (currentTimeMillis - machineCodeCreateTime >= 5 * 60 * 1000) { + model.setCode(1); + model.setData(false); + model.setMsg("娉ㄥ唽鐮佽幏鍙栧強杈撳叆瓒呰繃5鍒嗛挓,璇烽噸鏂拌幏鍙栨敞鍐岀爜"); + } else if (registerCodeTime > currentTimeMillis) { + model.setCode(1); + model.setData(false); + model.setMsg("绯荤粺鏃堕棿涓嶆甯�,璇锋鏌�"); } else { - model.setCode(0); - model.setMsg("楠岃瘉澶辫触"); - //model.setData(decryptResult); - //model.setMsgN(serialNumberStr); + model.setCode(1); + model.setData(true); + model.setMsg("娉ㄥ唽鐮佹牎楠屾垚鍔�"); } - }catch (Exception e){ - model.setCode(0); + //model.setData(decryptResult); + //model.setMsgN(serialNumberStr); + double duration = Integer.parseInt(decryptResult.split("duration:")[1]); + License data = new License(); + data.setSerialNumber(SerialNumberUtil.getSerialNumber()); + //duration鍜孴imeInUse鍔犲瘑瀛樺叆鏁版嵁搴� + String durationEncrypt = AESUtil.aesEncrypt(String.valueOf(duration)); + data.setDuration(durationEncrypt); + + String timeInUseEncrypt = AESUtil.aesEncrypt(String.valueOf(0)); + data.setTimeInUse(timeInUseEncrypt); + //灏嗗簭鍒楀彿,鏈夋晥鏈� 娣诲姞鍏icense琛� + service.add(data); + } else { + model.setCode(1); + model.setData(false); model.setMsg("楠岃瘉澶辫触"); + //model.setData(decryptResult); + //model.setMsgN(serialNumberStr); } + return model; } -- Gitblit v1.9.1