package com.huiju.estateagents.common.wxpay;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * 监控 控制器
 * @author fxf
 */
public class WxConfig extends WXPayConfig {
	private String appid;

	private String machId;

	private String key;

	private byte[] certData;

	/**
	 * 获取 App ID
	 *
	 * @return App ID
	 */
	@Override
	public String getAppID() {
		//银城慧家
		return appid;
	}
	
	/**
	 * 获取 Mch ID
	 *
	 * @return Mch ID
	 */
	@Override
	public String getMchID() {
		return machId;
	}
	
	/**
	 * 获取 API 密钥
	 *
	 * @return API密钥
	 */
	@Override
	public String getKey() {
		return key;
	}
	
	/**
	 * 获取商户证书内容
	 *
	 * @return 商户证书内容
	 */
	@Override
	public InputStream getCertStream() {
		ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
		return certBis;

	}

	public int getHttpConnectTimeoutMs() {
		return 8000;
	}

	public int getHttpReadTimeoutMs() {
		return 10000;
	}
	
	/**
	 * 获取WXPayDomain, 用于多域名容灾自动切换
	 *
	 * @return
	 */
	@Override
	IWXPayDomain getWXPayDomain() {
		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;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public void setMachId(String machId) {
		this.machId = machId;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public void setCertData(byte[] certData) {
		this.certData = certData;
	}
}

