AuthLicenseUtil.java 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package com.fdkankan.ucenter.common.utils;
  2. import cn.hutool.core.io.FileUtil;
  3. import cn.hutool.core.util.XmlUtil;
  4. import cn.hutool.json.JSONObject;
  5. import cn.hutool.json.JSONUtil;
  6. import cn.hutool.json.XML;
  7. import com.fdkankan.common.util.FileUtils;
  8. import com.fdkankan.ucenter.util.DateUserUtil;
  9. import com.fdkankan.ucenter.vo.response.AuthLicenseEntityVo;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.w3c.dom.Document;
  12. import org.w3c.dom.Node;
  13. import javax.validation.constraints.Size;
  14. import java.io.File;
  15. import java.io.IOException;
  16. import java.util.Date;
  17. @Slf4j
  18. public class AuthLicenseUtil {
  19. // Launcher.bat @inPath";
  20. static String cmd ="sudo bash /home/ubuntu/bin/Launcher.sh %s";
  21. static String licensePath = "/home/backend/4dkankan_v4/ucenter/license";
  22. public static JSONObject readLicense(){
  23. try {
  24. if (FileUtil.exist(licensePath + File.separator + "results" + File.separator + "encryption_info.xml")) {
  25. String xml = FileUtils.readFile((licensePath + File.separator + "results" + File.separator + "encryption_info.xml"));
  26. return XML.toJSONObject(xml);
  27. }
  28. }catch (Exception e){
  29. log.error("readLicense-error:",e);
  30. }
  31. return createLicense();
  32. }
  33. public static JSONObject createLicense() {
  34. File file = new File(licensePath);
  35. if(!file.exists()){
  36. file.mkdirs();
  37. }
  38. File caches = new File(licensePath + File.separator+ "caches");
  39. FileUtil.del(caches);
  40. File results = new File(licensePath + File.separator+ "results");
  41. FileUtil.del(results);
  42. JSONObject licenseDataJson = new JSONObject();
  43. licenseDataJson.put("split_type", "SPLIT_V23");
  44. licenseDataJson.put("skybox_type", "SKYBOX_V5");
  45. FileUtils.writeFile(licensePath + File.separator + "data.json", licenseDataJson.toString());
  46. ShellUtil.execCmd(String.format(cmd,licensePath));
  47. int count = 10;
  48. try {
  49. for (int i = count; i > 0; i--) {
  50. if (FileUtil.exist(licensePath + File.separator + "results" + File.separator + "encryption_info.xml")) {
  51. String xml = FileUtils.readFile((licensePath + File.separator + "results" + File.separator + "encryption_info.xml"));
  52. return XML.toJSONObject(xml);
  53. }
  54. Thread.sleep(1000);
  55. }
  56. } catch (Exception e) {
  57. log.error("createLicense-error:",e);
  58. return null;
  59. }
  60. return null;
  61. }
  62. public static void checkAuthLicense() {
  63. try {
  64. JSONObject jsonObject = AuthLicenseUtil.readLicense();
  65. JSONObject licenseInfo = jsonObject.getJSONObject("licenseInfo");
  66. JSONObject snInfo = licenseInfo.getJSONObject("snInfo");
  67. String endDate = snInfo.getStr("endDate");
  68. Date date = DateUserUtil.getDate(endDate);
  69. if(new Date().getTime() > date.getTime()){
  70. AuthLicenseUtil.createLicense();
  71. }
  72. }catch (Exception e){
  73. log.error("checkAuthLicense-error:",e);
  74. }
  75. }
  76. }