yangys
2025-05-26 2ba2c339acf41fd7bb2a49f0ce186fd664a80cb5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.qianwen.license.controller;
 
import java.util.ArrayList;
import java.util.Arrays;
 
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
 
import com.alibaba.fastjson.JSONObject;
import com.qianwen.license.common.License;
import com.qianwen.license.common.LicenseCreator;
import com.qianwen.license.common.LicenseExtraModel;
import com.qianwen.license.dto.LicenseCreateDTO;
 
 
@RestController
public class LicenseCreateController {
    private static Logger logger = LoggerFactory.getLogger(LicenseCreateController.class);
    
    //@Autowired
    //SuperProcessParameterMapper pMapper;
    @PostMapping("create")
    public JSONObject generateLicense(@RequestBody LicenseCreateDTO createDTO) {
        JSONObject result = new JSONObject();
        org.springframework.util.ResourceUtils a;
        org.apache.logging.log4j.LogManager b;
        try {
            // 生成license需要的一些参数
            License param = new License();
            // 证书授权主体(即CA机构,证书发放者,我们发放,应该是qianwen)
            param.setSubject(createDTO.getSubject());
            // 私钥别名
            param.setPrivateAlias(createDTO.getPrivateAlias());
            // 私钥密码(需要妥善保管,不能让使用者知道)
            param.setKeyPass(createDTO.getKeyPass());
            // 访问私钥库的密码
            param.setStorePass(createDTO.getStorePass());
            // 证书存储地址(磁盘位置)
            param.setLicensePath(createDTO.getLicensePath());
            // 私钥库所在地址
            param.setPrivateKeysStorePath(createDTO.getPrivateKeysStorePath());
            //证书生效时间
            param.setIssuedTime(createDTO.getIssuedTime());
    
            param.setExpiryTime(createDTO.getExpiryTime());
            // 用户类型
            param.setConsumerType(createDTO.getConsumerType());
            // 用户数量
            param.setConsumerAmount(createDTO.getConsumerAmount());
            // 描述
            param.setDescription(createDTO.getDescription());
            
            LicenseExtraModel extraModel = new LicenseExtraModel();
            
            ArrayList<String> macList = new ArrayList<>(Arrays.asList(StringUtils.split(createDTO.getMacAddress())));
            extraModel.setMacAddress(macList);
            
            ArrayList<String> ipList = new ArrayList<>(Arrays.asList(StringUtils.split(createDTO.getIpAddress())));
            extraModel.setIpAddress(ipList);
            
            extraModel.setCpuSerial(createDTO.getCpuSerial());
            
            extraModel.setExtData(createDTO.getExtData());
            
            param.setLicenseExtraModel(extraModel);//这里配置额外信息,比如设备数量,ip等等
            
            LicenseCreator licenseCreator = new LicenseCreator(param);
            // 生成license
            
            boolean genResult = licenseCreator.generateLicense();
            
            logger.info("证书生成完成");
            result.put("success", genResult);
        }catch(Exception e) {
            logger.error("生成证书失败",e);
            result.put("success", false);
            result.put("msg", e.getMessage());
        }
        return result;
    }
}