package com.supplier.service.impl;

import com.github.wxpay.sdk.WXPayConfig;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class WxPayConfigImpl implements WXPayConfig {

    private byte[] certData = null;

    public WxPayConfigImpl() {

        try {
            //微信支付证书 这里放的是项目下
            InputStream is = this.getClass().getClassLoader().getResourceAsStream("static/wx/apiclient_cert.p12");
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] bs = new byte[1024];
            int cnt = -1;
            while ((cnt = is.read(bs)) != -1) {
                baos.write(bs, 0, cnt);
            }
            is.close();
            certData = baos.toByteArray();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public String getAppID() {
        return "wxc2d9b6a59eccffe5";
    }

    @Override
    public String getMchID() {
        return "1629374258";
    }

    @Override
    public String getKey() {
        return "ueYnFyZimfIkejHrags9grqvHyekdXGa";
    }

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

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

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