package com.iamberry.wechat.tools;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.text.SimpleDateFormat;
import java.util.regex.Pattern;

import org.springframework.core.io.ClassPathResource;

import com.iamberry.app.tool.des.MD5;

/**
 * @description 用于存放静态变量
 * @author 欧阳明
 * @date 2016-4-20
 */
public class StaticInfo {

	public final static String SevenDay="7Day";
	public final static String SixMon="6Mon";
	public final static String Year="Year";
	public static final MD5 md5 = new MD5("product5");
	public static final MD5 orderIdMD5 = new MD5();
	public final static String endDateC=" 23:59:59";
	public final static Pattern pattern = Pattern.compile("[0-9]*");
	public final static SimpleDateFormat dateFormat = new SimpleDateFormat("MMddHHmmss"); 
	
	/**
	 *
	 * 加载双向加密SSL KeyStory文件位置
	 * 
	 */
	public static String resourceKey = "F:\\爱贝源-工作安排\\code\\iamberry\\build\\classes\\apiclient_cert.p12";	// 文件位置
	public static File file = new File(getResourcekey());	// 保存文件
	public static URL sslJksUrl = null;	// URL
	public static KeyStore keyStore  = null; // key
    static {
    	try {
			sslJksUrl = file.toURI().toURL();
			keyStore = KeyStore.getInstance("PKCS12");
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
	public static String getResourcekey() {
		if (resourceKey == null) {
			ClassPathResource resource = new ClassPathResource("apiclient_cert.p12");
			try {
				resourceKey = URLDecoder.decode(resource.getFile().getAbsolutePath(), "UTF-8");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return resourceKey;
	}
}
