涉及支付需要在资源文件下resource下放置秘钥,java代码里读取
首先在pom文件里配置以下配置,不然在不会编译在class包里
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <configuration><encoding>UTF-8</encoding> <!-- 过滤后缀为pem、pfx的证书文件 --> <nonFilteredFileExtensions> <nonFilteredFileExtension>cer</nonFilteredFileExtension> <nonFilteredFileExtension>pem</nonFilteredFileExtension> <nonFilteredFileExtension>pfx</nonFilteredFileExtension> </nonFilteredFileExtensions> </configuration> </plugin>
java读取方式:
public static InputStream getInputStreamtByPath(String enterpriseCerFilePath) throws IOException { try{ InputStream stream = BhRSAUtil.class.getClassLoader().getResourceAsStream(enterpriseCerFilePath); return stream; }catch(Exception ioe){ throw ioe; } } public static InputStream getSignCertByJarFile2(String enterpriseCerFilePath) throws IOException { try{ ClassPathResource ClassPathResource = new ClassPathResource(enterpriseCerFilePath); return ClassPathResource.getInputStream(); }catch(IOException ioe){ ioe.printStackTrace(); throw ioe; } }