package com.jzdsh.wxpay.sdk;

import com.jfinal.kit.PropKit;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * @description:
 * @author: lc
 * @create 2019-08-26  10:50
 */
public class MyWxPayConfig extends WXPayConfig {
    private byte[] certData;

    @Override
    public String getAppID( ) {
        return PropKit.get("appid");
    }

    @Override
    public String getMchID( ) {
        return PropKit.get("mch_id");
    }

    @Override
    public String getKey( ) {
        return PropKit.get("mch_key");
    }

    @Override
    public InputStream getCertStream( ) {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    @Override
    public int getHttpConnectTimeoutMs( ) {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs( ) {
        return 10000;
    }

    @Override
    public IWXPayDomain getWXPayDomain( ) {
        // 这个方法需要这样实现, 否则无法正常初始化WXPay
        IWXPayDomain iwxPayDomain = new IWXPayDomain( ) {

            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }

            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
        return iwxPayDomain;

    }


}
