wujianwei
12 小时以前 2cf82c1c1959701fe7d31b3d891434575ed6b58f
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.ruoyi.cwgl.test;
 
 
import com.cmbs.client.header.ClientConfig;
 
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
 
public class GatewayConfigUtils {
 
    static Properties gatewayProperties;
 
    static {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("gateway.properties");
        gatewayProperties = loadProperties(is);
    }
 
    public static ClientConfig getClientConfig() {
 
        ClientConfig clientConfig = new ClientConfig();
 
        // 商户号
        clientConfig.setMerchantNum(gatewayProperties.getProperty("merchantNum"));
 
        // 系统编码
        clientConfig.setSystemCode(gatewayProperties.getProperty("plantFormCode"));
 
        //互联网https请求SSL双向认证
        clientConfig.setPostUrl(gatewayProperties.getProperty("url"));
 
        //https双向认证证书
        clientConfig.setSslClientCertPath(getCertFilePath("sslPath", "minsheng.pfx"));
 
        //https双向认证证书密码
        clientConfig.setSslClientPassword(gatewayProperties.getProperty("sslPassword"));
 
        //民生科技的公钥
        clientConfig.setBankCertPath(getCertFilePath("publicCertPath", "cmbs.cer"));
 
        // 测试环境商户私钥,生产环境需要替换(去民生网站下载商户自己的私钥)
        clientConfig.setOwnSm2Path(getCertFilePath("sm2Path", "private.sm2"));
 
        //商户私钥密码
        clientConfig.setOwnSm2Pwd(gatewayProperties.getProperty("sm2Password"));
        return clientConfig;
    }
 
    public static ClientConfig getClientConfig2() {
 
        ClientConfig clientConfig = new ClientConfig();
 
        // 商户号
        clientConfig.setMerchantNum("zjjr");
 
        // 系统编码
        clientConfig.setSystemCode("620");
 
        //互联网https请求SSL双向认证
        clientConfig.setPostUrl("https://tmc-demo.cmbc.com.cn/mop/ecp/httpMhtInVtFwd");
 
        //https双向认证证书
        clientConfig.setSslClientCertPath("C:\\Users\\w\\minsheng.pfx");
 
        //https双向认证证书密码
        clientConfig.setSslClientPassword("cfca1234");
 
        //民生科技的公钥
        clientConfig.setBankCertPath("C:\\Users\\w\\cmbs.cer");
 
        // 测试环境商户私钥,生产环境需要替换(去民生网站下载商户自己的私钥)
        clientConfig.setOwnSm2Path("C:\\Users\\w\\private.sm2");
 
        //商户私钥密码
        clientConfig.setOwnSm2Pwd("11111111");
        return clientConfig;
    }
 
    private static Properties loadProperties(InputStream is){
        Properties properties = new Properties();
        try {
            properties.load(is);
        } catch (IOException e) {
            System.out.println("properties配置文件失败");
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                    System.out.println("数据处理异常");
                }
            }
        }
        return properties;
    }
 
    private static String getCertFilePath(String key, String fileName){
        String filePath = gatewayProperties.getProperty(key, "");
        if (filePath.equals("")){
            String gatewayPath = Thread.currentThread().getContextClassLoader().getResource("gateway.properties").getPath();
            return gatewayPath.replace("gateway.properties", "") + fileName;
        }
        return filePath;
    }
}