package com.hzs.third.pay.listener;

import com.huifu.bspay.sdk.opps.core.BasePay;
import com.huifu.bspay.sdk.opps.core.config.MerConfig;
import com.hzs.third.pay.config.HuiFuConfig;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 汇付新支付的启动配置
 */
//@Component
@Slf4j
public class HuiFuLoadListener implements ServletContextListener {

    @Autowired
    private HuiFuConfig huiFuConfig;

    @SneakyThrows
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        log.info("==========汇付新支付配置加载开始==========");

        // debug 模式，开启后有详细的日志
        BasePay.debug = false;

        //  prodMode 模式
        BasePay.prodMode = BasePay.MODE_PROD;

        MerConfig merConfig = new MerConfig();
        merConfig.setProcutId(huiFuConfig.getProcutId());
        merConfig.setSysId(huiFuConfig.getSysId());
        merConfig.setRsaPrivateKey(huiFuConfig.getRsaPrivateKey());
        merConfig.setRsaPublicKey(huiFuConfig.getRsaPublicKey());

        BasePay.initWithMerConfig(merConfig);

        log.info("==========汇付新支付配置加载完成==========");
    }

}
