wechatpay-apiv3 / wechatpay-java

微信支付 APIv3 的官方 Java Library
Apache License 2.0
923 stars 206 forks source link

单个实例下,构造支付config和notificationConfig 报错"The corresponding provider for the merchant already exists." #183

Closed egosodv closed 1 year ago

egosodv commented 1 year ago

错误描述

应当考虑sdk使用者存在单实例运行,没有将下单和回调分成多个服务的情况

重现bug的步骤

在一个服务中,同时构造支付config和回调通知config抛出异常

预期行为

对notificationconfig和config分别处理,不抛出异常

导致错误的代码片段

protected AbstractAutoCertificateProvider(
      String requestUrl,
      CertificateHandler certificateHandler,
      AeadCipher aeadCipher,
      HttpClient httpClient,
      String merchantId,
      Map<String, Map<String, X509Certificate>> wechatPayCertificateMap,
      int updateInterval) {
    this.merchantId = merchantId;
    synchronized (AbstractAutoCertificateProvider.class) {
      if (!wechatPayCertificateMap.containsKey(merchantId)) {
        wechatPayCertificateMap.put(merchantId, new HashMap<>());
      } else {
        throw new IllegalStateException(
            "The corresponding provider for the merchant already exists.");
      }
    }

操作系统

Windows 10

Java 版本

Java 8

wechatpay-java 版本

v0.2.7

其他信息

No response

egosodv commented 1 year ago

有看到之前同样有人提出困惑,但好像没有就单实例同时处理下单和回调给出解决方案,https://github.com/wechatpay-apiv3/wechatpay-java/issues/92