dromara/payment-spring-boot

多租户模式下能否改成从数据库中获取而非yaml文件中

huchuansai opened this issue · 1 comments

场景:saas系统下,支持商户去配置自己的支付参数,这样的话放到yml文件里肯定是不现实的,能否改为从数据库中获取数据。还有一个问题,如果是这样的话,证书应该怎么保存和获取

    @Bean
    @ConditionalOnMissingBean
    WechatMetaContainer wechatMetaContainer(WechatPayProperties wechatPayProperties) {

        Map<String, WechatPayProperties.V3> v3Map = wechatPayProperties.getV3();
        WechatMetaContainer container = new WechatMetaContainer();
        KeyPairFactory keyPairFactory = new KeyPairFactory();
        v3Map.keySet().forEach(tenantId -> {
            WechatPayProperties.V3 v3 = v3Map.get(tenantId);
            String certPath = v3.getCertPath();
            String certAbsolutePath = v3.getCertAbsolutePath();
            String mchId = v3.getMchId();
            Resource resource = certAbsolutePath != null ? new FileSystemResource(certAbsolutePath) :
                    new ClassPathResource(certPath == null ? "wechat/apiclient_cert.p12" : certPath);
            WechatMetaBean wechatMetaBean = keyPairFactory.initWechatMetaBean(resource, CERT_ALIAS, mchId);
            wechatMetaBean.setV3(v3);
            wechatMetaBean.setTenantId(tenantId);
            container.addWechatMeta(tenantId, wechatMetaBean);
        });
        return container;
    }

默认行为是从yaml中配置