payment-spring-boot icon indicating copy to clipboard operation
payment-spring-boot copied to clipboard

[FEATURE REQUEST] 希望支付宝private key可以通过外部文件加载

Open ccfish86 opened this issue 1 year ago • 2 comments

设置了支付宝classpath-used: false后,但private key还是通过classpath读取文件 [ali pay app private key is required] 环境版本信息 [payment-spring-boot-autoconfigure-1.0.20.RELEASE.jar:na]

代码与截图 image

ccfish86 avatar Dec 13 '24 01:12 ccfish86

这个是证书路径, 私钥你可以参考类似方式实现

NotFound403 avatar Dec 13 '24 01:12 NotFound403

建议通过Spring的Resource加载类来读取文件,这样就能读取多个地方(classpath/file/url)的文件了。

        var resourceLoader = new DefaultResourceLoader();
        var resource = resourceLoader.getResource(location);
        String content;
        try {
            content = resource.getContentAsString(StandardCharsets.UTF_8);
            return ResponseEntity.ok(content);
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseEntity.internalServerError().body("error:"+e.getMessage());
        }

根本 location不同值,读取不同位置的文件

  • alipay/app_rsa 读取classpath下的
  • classpath:alipay/app_rsa 读取classpath下的
  • file:///config/alipay/app_rsa 读取本地文件 .....

ccfish86 avatar Dec 13 '24 02:12 ccfish86