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; } }