package com.bohuikeji.frame.module.admin.wxpay;


import com.bohuikeji.frame.module.admin.utils.FileUtil;
import com.bohuikeji.frame.module.admin.utils.MinioUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import static com.bohuikeji.frame.module.admin.wxpay.WXPayConstants.DOMAIN_API;


public class MyConfig extends WXPayConfig {
    /**
     * 开发配置
     * AppID: wx43d3df96abd88dba
     * AppSecret: 6072213c0460bd4b7d84bac2f1b406de
     * MchID：     1513305011
     */
    //AppSecret：39ffdd654753048238b9678c74975723
    private InputStream certData;
    private static MyConfig config;
    private static WXPay wxpay;
    public static  MyConfig getConfig(){
        if (config==null){
            config=new MyConfig();
        }
        return config;
    }
    public static  WXPay getWXPay(){
        if (wxpay==null){
            try {
                wxpay=new WXPay(getConfig());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return  wxpay;
    }

    public MyConfig() {
        this.certData=FileUtil.download("https://oss.tcjskd.com/delivery/upload/pay/wx/apiclient_cert.p12");
    }

    /**
     * 公众号/服务号appId
     * @return
     */
    @Override
    public String getAppID() {

        return "wx622a1adff1efa32a";
    }

    @Override
    public String getMchID() {

        return "1555319231";
    }

    @Override
    public String getKey() {
        return "I5EZ5jAYudbmOfe9ouOiSGMcBpWuieET";
        /*return "6141e9ac7e5bbb317921f28790f7f8d6";*///更新前的
    }


    @Override
    public InputStream getCertStream() {
        //https://oss.bhynm.com/delivery/upload/2020/2/23/158243117447517.p12旧的
        return FileUtil.download("https://oss.tcjskd.com/delivery/upload/pay/wx/apiclient_cert.p12");
    }

    @Override
    IWXPayDomain getWXPayDomain() {
        return new IWXPayDomain() {
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }

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

}
