package com.iamberry.wechat.tools;

import java.io.IOException;
import java.util.Properties;

import com.iamberry.zk.ZookeeperFactory;

/**
 * @company	深圳爱贝源科技有限公司
 * @website www.iamberry.com
 * @author 	献
 * @tel		18271840547
 * @date	2016年11月30日
 * @explain	本类保存平台配置信息
 */
public class NameUtils {
	
	private static volatile Properties properties = null;
	
	public static String getConfig(String keyName) {
		try {
			if (properties == null) {
				synchronized (NameUtils.class) {
					if (properties == null) {
						properties = ZookeeperFactory.loadProperties("classpath:platform.properties");
					}
				}
			}
			return properties.getProperty(keyName);
		} catch (IOException e) {
			throw new AttrNotFoundException();
		}
	}
	
	static class AttrNotFoundException extends RuntimeException {private static final long serialVersionUID = 1L;}

	
	/** 16进制字符集 */
	public static final char HEX_DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
	
    public static final String DEFAULT_SEND_CHARSET = "UTF-8";

    public static final String DEFAULT_RES_CHARSET = "UTF-8";
	
	/** 试用到期时间 */
	public final static Long TRIAL_DATE = 2592000000L;
	
	// 获取access_token的接口地址(GET) 限200次/天
	public final static String access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
	// 获取jsapi_ticket的接口地址(GET)
	public static String jsapi_ticket_url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi";
	// 菜单创建(POST) 限100次/天
	public static String menu_create_url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";
	// 根据access_token换取二维码ticket
	public static String get_token_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN";
	// 二维码图片链接
	public static String show_qrcode_url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=";
	// 临时二维码	QR_SCENE为临时的整型参数值，
	public static String QR_SCENE = "{\"expire_seconds\": %s, \"action_name\": \"QR_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": %s}}}";
	// 临时二维码	 QR_STR_SCENE为临时的字符串参数值
	public static String QR_SCENE_STR = "{\"expire_seconds\": %s, \"action_name\": \"QR_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"%s\"}}}";
	// 　永久二维码
	public static String QR_LIMIT_STR_SCENE = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"%s\"}}}";
	// 获取用户信息
	public static String userinfo_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=ACCESS_TOKEN&openid=OPENID";
	// 网页授权获取access_token
	public static String oauth2_getToken_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
	// 网页授权获取user_info
	public static String oauth2_getUserInfo_url = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID&lang=zh_CN";
	// 引导授权链接
	public static String oauth2_url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect";

	/** 
     * 验证码类型为仅数字,即0~9 
     */  
    public static final int TYPE_NUM_ONLY = 0;  
  
    /** 
     * 验证码类型为仅字母,即大小写字母混合 
     */  
    public static final int TYPE_LETTER_ONLY = 1;  
  
    /** 
     * 验证码类型为数字和大小写字母混合 
     */  
    public static final int TYPE_ALL_MIXED = 2;  
  
    /** 
     * 验证码类型为数字和大写字母混合 
     */  
    public static final int TYPE_NUM_UPPER = 3;  
  
    /** 
     * 验证码类型为数字和小写字母混合 
     */  
    public static final int TYPE_NUM_LOWER = 4;  
  
    /** 
     * 验证码类型为仅大写字母 
     */  
    public static final int TYPE_UPPER_ONLY = 5;  
  
    /** 
     * 验证码类型为仅小写字母 
     */  
    public static final int TYPE_LOWER_ONLY = 6;

}
