| | |
| | | @ApiOperation(value = "校验license") |
| | | public Response checkSerialNumberLicense(@RequestParam String license){ |
| | | Response model = new Response(); |
| | | try { |
| | | //获取macid是否一致 |
| | | boolean res = false; |
| | | //初始化sm2参数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:"; |
| | | //获取解密后license,附带校验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和TimeInUse加密存入数据库 |
| | | String durationEncrypt = AESUtil.aesEncrypt(String.valueOf(duration)); |
| | | data.setDuration(durationEncrypt); |
| | | |
| | | String timeInUseEncrypt = AESUtil.aesEncrypt(String.valueOf(0)); |
| | | data.setTimeInUse(timeInUseEncrypt); |
| | | //将序列号,有效期 添加入license表 |
| | | service.add(data); |
| | | //获取macid是否一致 |
| | | boolean res = false; |
| | | //初始化sm2参数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:"; |
| | | //获取解密后license,附带校验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和TimeInUse加密存入数据库 |
| | | String durationEncrypt = AESUtil.aesEncrypt(String.valueOf(duration)); |
| | | data.setDuration(durationEncrypt); |
| | | |
| | | String timeInUseEncrypt = AESUtil.aesEncrypt(String.valueOf(0)); |
| | | data.setTimeInUse(timeInUseEncrypt); |
| | | //将序列号,有效期 添加入license表 |
| | | service.add(data); |
| | | } else { |
| | | model.setCode(1); |
| | | model.setData(false); |
| | | model.setMsg("验证失败"); |
| | | //model.setData(decryptResult); |
| | | //model.setMsgN(serialNumberStr); |
| | | } |
| | | |
| | | return model; |
| | | } |
| | | |