package com.buy507.mall.portal.pay.wxpay;

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

import org.apache.commons.io.IOUtils;

public class MyConfig extends WXPayConfig {
	
	private String appId;
	
	private String mchId;
	
	private String key;

	private byte[] certData;

	public MyConfig(String appId, String mchId, String key) throws Exception {
		InputStream certStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("cert/apiclient_cert.p12");
		this.certData = IOUtils.toByteArray(certStream);
		certStream.close();
		this.appId = appId;
		this.mchId = mchId;
		this.key = key;
	}

	// 小程序appid
	@Override
	public String getAppID() {
		return this.appId;
	}

	// 商户号
	@Override
	public String getMchID() {
		return this.mchId;
	}

	/** 商户平台-账户中心-API安全中的密钥 */
	@Override
	public String getKey() {
		return this.key;
	}

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

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

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

	@Override
	IWXPayDomain getWXPayDomain() {
		return 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);
			}
		};
	}

}
