国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

微信支付apiV3異常:The corresponding provider for the merchant already exists

這篇具有很好參考價(jià)值的文章主要介紹了微信支付apiV3異常:The corresponding provider for the merchant already exists。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

異常信息
java.lang.IllegalStateException: The corresponding provider for the merchant already exists.
原因

這個(gè)錯(cuò)誤是微信SDK拋出的,這是因?yàn)槲⑿胖Ц禷piV3的RSAConfig重復(fù)build導(dǎo)致,即RSAConfig要保證是單例才不會導(dǎo)致報(bào)錯(cuò)。

// 要保證這個(gè)Config在服務(wù)中單例
private RSAAutoCertificateConfig config;

@Autowired
public void setConfig(){
    config = new RSAAutoCertificateConfig.Builder()
            .merchantId(mchId)
            .privateKey(privateKey)
            .merchantSerialNumber(mchSerialNo)
                    .apiV3Key(apiV3Key)
                            .build();
}

public Config getConfig(){
    return this.config;
}

public NotificationConfig getNotificationConfig(){
    return this.config;
}
參數(shù)說明
  • mchId:商戶號
  • privateKey:商戶號密鑰
  • mchSerialNo:商戶證書號
  • apiV3Key:apiV3密鑰
建議

可以把商戶配置參數(shù)使用數(shù)據(jù)庫保存,服務(wù)啟動(dòng)的時(shí)候加載在緩存里面,緩存的key為mchId,value為config對象,這樣可以實(shí)現(xiàn)一個(gè)服務(wù)多個(gè)直連商戶號共存。

package com.swkj.payment.test;

import com.swkj.common.base.enums.PaymentMchType;
import com.swkj.common.base.util.CollectionUtils;
import com.swkj.common.charge.model.po.paymentmch.PaymentMchPo;
import com.swkj.common.charge.service.paymentmch.PaymentMchService;
import com.swkj.common.core.wrapper.LambdaQueryWrapperX;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.notification.NotificationConfig;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: GE LIANG
 * @Date: 2023/3/14 8:49
 */
public class PaymentServiceImpl {



    // 本地緩存
    private Map<String, RSAAutoCertificateConfig> configMap;

    @Resource
    PaymentMchService paymentMchService;

    @PostConstruct
    public void initConfig() {
        LambdaQueryWrapperX<PaymentMchPo> wrapperX = new LambdaQueryWrapperX<>();
        wrapperX.eq(PaymentMchPo::getMchTypeId, PaymentMchType.WECHAT.getValue());
        List<PaymentMchPo> list = paymentMchService.list(wrapperX);
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        for (PaymentMchPo paymentMchPo : list) {
            RSAAutoCertificateConfig config =
                    new RSAAutoCertificateConfig.Builder()
                            .merchantId(paymentMchPo.getMchId())
                            .privateKey(paymentMchPo.getPrivateKey())
                            // .privateKeyFromPath(wechatPaymentConfig.getPrivateKeyPath())
                            .merchantSerialNumber(paymentMchPo.getMchSerialNo())
                            .apiV3Key(paymentMchPo.getApiV3Key())
                            .build();
            configMap.put(paymentMchPo.getAppId(), config);
        }
    }


    /**
     * @param appId 根據(jù)AppId獲取Config
     * @return
     */
    public Config getWechatConfig(String appId) {
        return configMap.get(appId);
    }

    /**
     * @param appId 根據(jù)appId獲取NotificationConfig
     * @return
     */
    public NotificationConfig getNotificationConfig(String appId) {
        return configMap.get(appId);
    }
}

PaymentMchPo 對應(yīng)的sql結(jié)構(gòu)文章來源地址http://www.zghlxwxcb.cn/news/detail-511964.html

DROP TABLE IF EXISTS "public"."charge_payment_mch";
CREATE TABLE "public"."charge_payment_mch" (
  "payment_mch_id" int8 NOT NULL,
  "revision" int4 NOT NULL,
  "created_by" int8 NOT NULL,
  "created_time" timestamp(0) NOT NULL,
  "updated_by" int8,
  "updated_time" timestamp(0),
  "mch_id" varchar(50) COLLATE "pg_catalog"."default",
  "private_key" text COLLATE "pg_catalog"."default",
  "mch_serial_no" varchar(256) COLLATE "pg_catalog"."default",
  "api_v3_key" varchar(256) COLLATE "pg_catalog"."default",
  "app_id" varchar(50) COLLATE "pg_catalog"."default"
)
;

到了這里,關(guān)于微信支付apiV3異常:The corresponding provider for the merchant already exists的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包