package com.duowenlvshi.duowenlszp.app.wxPay;

import com.github.wxpay.sdk.WXPayConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ClassUtils;

import javax.annotation.PostConstruct;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @author yang fang yu
 * @since 2019/9/18 15:32
 */
public class WXConfigUtil implements WXPayConfig {
    private byte[] certData;

    public static final String APP_ID = "wxf04c691286b6dd2b";
    public static final String KEY = "fadumiyaofadumiyaofadumiyao12345";
    public static final String MCH_ID = "1392918102";

    public WXConfigUtil() throws Exception {
        String certPath = ClassUtils.getDefaultClassLoader().getResource("").getPath()+"/apiclient_cert.duowenapp_b.p12";//从微信商户平台下载的安全证书存放的路径
        File file = new File(certPath);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }


    public String getAppID() {
        return APP_ID;
    }

    public String getMchID() {
        return MCH_ID;
    }

    public String getKey() {
        return KEY;
    }

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

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

}

