payment-spring-boot
payment-spring-boot copied to clipboard
配置多租户时如果有相同的微信证书会复用,导致配置的tenantId无法找到对应的证书,报错failed to obtain wechat pay x509Certificate
一个微信证书对应多个appid时,CERTIFICATE_MAP有缓存 `/** * Get certificate x 509 wechat certificate info. * * @param tenantId the tenant id * @return the x 509 wechat certificate info */ public X509WechatCertificateInfo getCertificate(String tenantId) { for (String serial : CERTIFICATE_MAP.keySet()) { X509WechatCertificateInfo wechatCertificateInfo = CERTIFICATE_MAP.get(serial); X509Certificate x509Cert = wechatCertificateInfo.getX509Certificate(); if (wechatCertificateInfo.getTenantId().equals(tenantId)){ try { x509Cert.checkValidity();
return wechatCertificateInfo;
} catch (Exception e) {
log.warn("the wechat certificate is invalid , {}", e.getMessage());
// Async?
wechatMetaContainer.getTenantIds().forEach(this::refreshCertificate);
}
}
}
throw new PayException("failed to obtain wechat pay x509Certificate ");
}`