package com.iamberry.wechat.tools;

import com.iamberry.zk.ZookeeperFactory;

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

/**
 * 本类保存所有常见、常用名称，如登陆用户在session中的名称，验证码在session中的名称
 * 慎重修改!
 * @author 何秀刚
 */
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;}

	// 验证码session中保存的名称
	public static final String VERIFYCODE_NAME = "verifyCode";
	// 会员登陆成功过后session中保存的名称
	public static final String LOGIN_USER_NAME = "loginUser";
	// 超级管理员登陆成功后session中保存的名称
	public static final String ADMIN_LOGIN_NAME = "admin";
	// 二级管理员登陆成功后色素死哦你中保存的名称
	public static final String ADMINCHILD_LOGIN_NAME = "adminChild";
	// 线上试用订单ID前缀
	public static final String ETC_ORDER_PREFIX = "1102";
	// 线下试用订单ID前缀
	public static final String ORDER_ID = "1310";
	/** path root */
	public static final String PATH_ROOT = "https://h5.iamberry.com";
	public static final String PATH_ROOT_LCOAL = "http://h5.iamberry.com";
	/** 微信端会员 */
	public static final String WECHAT_MEMBER_ROOT = "/member"; // 微信端会员根目录
	public static final String WECHAT_MEMBER_INDEX = "/index"; // 会员首页
	public static final String WECHAT_MEMBER_INDEX_RES = "wechat/member/user_index"; // 资源位置
	public static final String WECHAT_MEMBER_URL_INDEX = "/member/index"; // URL
	public static final String WECHAT_MEMBER_1 = "wechat/member/user_index_1";
	public static final String WECHAT_MEMBER_QRCODE = "/qrcode";
	public static final String WECHAT_MEMBER_QRCODE_RES = "wechat/member/user_qrcode";
	public static final String WECHAT_MEMBER_QRCODE_INDEX = "/member/qrcode";
	public static final String WECHAT_MEMBER_LEVEL = "/ascensionMemberLevelJSON";
	public static final String WECHAT_MEMBER_HELP = "/help";
	public static final String WECHAT_MEMBER_HELP_RES = "wechat/member/user_help";
	public static final String WECHAT_MEMBER_USERINFO = "/userinfoUI";
	public static final String WECHAT_MEMBER_USERINFO_RES = "wechat/member/user_info";
	public static final String WECHAT_MEMBER_UPDATE_USERINFO = "/updateUserInfoJSON";
	public static final String WECHAT_QRCODE_SHARE = "/share/{userId}";
	public static final String WECHAT_QRCODE_SHARE_RES = "wechat/member/user_qrcode";
	public static final String PLACE_CODE_PREFIX = "CODE";
	public static final String WECHAT_BACK_URL = PATH_ROOT + "/iamberry/wechatBack";
	public static final String WECHAT_ORDER_BACK = PATH_ROOT + "/iamberry/callback/orderPayBack";
	public static final String redirectUrl = "redirectUrl";
	public static final String redirectUrl_index = "redirect:/wechat/index";
	public static final String WECHAT_DRP_BACK = PATH_ROOT + "/iamberry/callback/drpPayBack";
	public static final String WECHAT_PRODUCT_SHARE_URL = PATH_ROOT + "/iamberry/wechat/product/sharePorductDesc";
	public static final String WECHAT_MEMBER_SHARE_URL = PATH_ROOT + "/iamberry/wechat/member/showQrcode";
	public static final String WECHAT_MEMBER_SHARE_QRCODE = PATH_ROOT + "/iamberry/wechat/member/showQrcode";
	public static final String WECHAT_MEMBER_PROXY_QRCODE = PATH_ROOT + "/iamberry/wechat/drp/share2WM";
	public static final String WECHAT_DRP_SHARE_URL = PATH_ROOT + "/iamberry/wechat/drp/share2WM";
	public static final String WECHAT_DEFAULT_QRCODE = PATH_ROOT + "/iamberry/common/images/default_qrcode.png";
	public static final String WECHAT_DEFAULT_WATERMARK = "/common/images/default_watermark.png";
	/** 商城所有的今天页面 */
	public static final String WECHAT_SHOP_WITHDRAW_APPLY = "/WEB-INF/views/wechat/tixian_apply.html"; // 积分提现
	public static final String WECHAT_SHOP_WITHDRAW_APPLY_CASH = "/WEB-INF/views/wechat/tixian_apply_cash.html"; // 现金提现
	public static final String WECHAT_SHOP_WITHDRAW_APPLY_CASH_SUCCESS = "/WEB-INF/views/wechat/tixian_cash_success.html"; // 现金提现申请成功页面

	public static final String WECHAT_SHOP_PRODUCT_DESC_PAGE = "/WEB-INF/views/wechat/chanpin_details.html"; // 产品详情
	public static final String WECHAT_SHOP_PRODUCT_LIST_PAGE = "/WEB-INF/views/wechat/chanpin_list.html"; // 产品列表
	public static final String WECHAT_SHOP_INDEX = "/WEB-INF/views/wechat/index.html"; // 首页
	public static final String WECHAT_SHOP_VIDEO = "/WEB-INF/views/wechat/iamberry_video.html"; // 首页
	public static final String WECHAT_SHOP_MEMGER_INDEX = "/WEB-INF/views/wechat/daili_2wm.html"; // 二维码
	public static final String WECHAT_SHOP_CART_INDEX = "/WEB-INF/views/wechat/shopping_cart.html"; // 购物车
	public static final String WECHAT_SHOP_ORDER_PAY = "/WEB-INF/views/wechat/clearing.html"; // 支付页面
	public static final String WECHAT_SHOP_ORDER_PAY_SUCCESS = "/WEB-INF/views/wechat/pay_win.html"; // 支付成功页面
	
	public static final String WECHAT_SHOP_ORDER_GOORDERINFO = "/WEB-INF/views/wechat/order_details.html";//去订单详情页面
	public static final String WECHAT_SHOP_ORDER_GOORDERLIST = "/WEB-INF/views/wechat/order_list.html";//去订单列表页
	public static final String WECHAT_SHOP_PRODUCT_LIST = "/WEB-INF/views/wechat/chanpin_list.html";
	
	public static final String WECHAT_CASH_LOG_LIST = "/WEB-INF/views/wechat/cash_log.html";
	public static final String WECHAT_WITHDRAW_CASH_LOG_LIST = "/WEB-INF/views/wechat/tixian_log_cash.html";
	
	//分销
	public static final String WECHAT_SHOP_FENXIAO_INDEX="/WEB-INF/views/wechat/drp/indexPage";  //分销首页
	public static final String WECHAT_SHOP_FENXIAO_ORDERLIST="/WEB-INF/views/wechat/fenxiao_fahuo_log.html";  //分销列表页
	public static final String WECHAT_SHOP_FENXIAO_PAYORDERPAGE="/WEB-INF/views/wechat/fenxiao_clearing.html";  //分销订货支付页面
	
	//大转盘页面
	public static final String WECHAT_GO_ZHUANPAN = "/WEB-INF/views/wechat/zhuanpan.html";
	public static final String WECHAT_GO_PRIZE_LOG = "/WEB-INF/views/wechat/wheel_log.html";
	public static final String WECHAT_GO_LUCK_DRAW = "/WEB-INF/views/wechat/share_zhuanpan.html";
	// 允许的URL连接
	public static final String XSS_HANDLER_LOCALHOST_URL = "https://localhost:";
//	public static final String XSS_HANDLER_OUT_URL = "https://h5.iamberry.com:";
	public static final String XSS_HANDLER_OUT_URL = "https://h5.iamberry.com:";
	
	/**
	 * 百胜订单信息
	 */
//	public static final String app_nick = "openapi";
//	public static final String app_key = "8888";
//	public static final String app_secret = "8888";
	//public static final String efast_base_url = "http://121.199.165.244/efast_test/efast_api/webservice/web/index.php";
//	public static final String efast_base_url = "http://121.199.165.244/efast/efast_api/webservice/web/index.php";
	//public static final String order_field = "order_sn,deal_code,order_status,shipping_status,pay_status,process_status,is_send,is_locked,is_separate,consignee,address,zipcode,tel,mobile,shipping_name,pay_name,invoice_no,order_amount ,money_paid,user_id ,orders.goods_sn,orders.goods_name,orders.goods_number,orders.goods_price,orders.goods_barcode,orders.payment_ft,pay_time,to_buyer,postscript,order_amount,user_nick,money_paid,shipping_fee";

	/**App 绑定下载 **/
	public static final String BINDINGDOWNLOD="/WEB-INF/views/other/index.html";
	
	public static final int OT_NONE = 0, OT_WRITER = 1, OT_STREAM = 2;
	
	public static final String WECHAT_INDEX_FORWARD = "/WEB-INF/views/wechat/index.html";
	
	public static final String DATE_FORMAT = "yyyy-MM-dd";
	public static final String TIME_FORMAT = "HH:mm:ss";
	public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
	public static final String DATE_TIME_FORMAT1 = "yyyy/MM/dd HH:mm:ss";
	public static final String DATE_TIME_FORMAT2 = "yyyy年MM月dd日 HH:mm";
	
	/**图片格式：JPG*/
	public static final String PICTRUE_FORMATE_JPG = "jpg";

	public static final String signatureSimple = "userAgent=%s&userIp=%s&token=%s&timestamp=%s&sessionId=%s";
	
	/** 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";
	
	//*********************  WXPublicNo.java begin  *************/
    //description ： 微信公众号的一些基本信息	 @author 何秀刚 	create date：2016年3月10日
    
//    /**
	/* 测试账号信息：爱贝源科技
	public final static String pubNo = "gh_63843ac1ca52";// 微信号
	public final static String appId = "wxd995fb95b97ece1b";// 应用ID
	public final static String token = "weixin";// token
	public final static String appSecret = "34922854462fba23cf54ce859349fcf4";// 应用密钥
	public final static String partner = "1347735301";// 微信支付商户号
     */

	/** 公众号账户信息:水时代 */
	/*public final static String pubNo = "gh_c73446c8ce91";// 微信号
	public final static String appId = "wxc71b789fad06a2d7";// 应用ID
	public final static String token = "weixin";// token
	public final static String appSecret = "8a90e3ab0e2db7772f5f64e7ed2f4b98";// 应用密钥
	public final static String partner = "1321590501";// 微信支付商户号*/

	/** 水时代公众号商户信息 */
	/*public final static String partnerkey = "cdb9075e7ecad945ba788bc5aedM212B";// 财付通初始密码
	public final static String charset = "UTF-8"; // 支付编码
	public final static String KEYSTORE_FILE = "E:/apiclient_cert.p12"; // 支付API安全文件FILE位置，但是现在保存到/resource/apiclient_cert.p12
	public final static String KEYSTORE_PASSWORD = "124022090"; // 支付API安全文件密码
	public final static String ipAddress = "120.25.79.106"; // ip地址*/

	/** 公众号账户信息:爱贝源 */
	public final static String pubNo = "gh_487d0dbf8e30";// 微信号
	public final static String appId = "wx09aa7519c4e5b360";// 应用ID
	public final static String token = "weixin";// token
	public final static String appSecret = "c006d5a6af80b5291265a1364fd17edc";// 应用密钥
	public final static String partner = "1340351501";// 微信支付商户号
	/** 公众号商户信息 */
	public final static String partnerkey = "8a90e3ab0e2db7772f5f64e7edwechat";// 财付通初始密码
	public final static String charset = "UTF-8"; // 支付编码
	public final static String KEYSTORE_FILE = "E:/apiclient_cert.p12"; // 支付API安全文件FILE位置，但是现在保存到/resource/apiclient_cert.p12
	public final static String KEYSTORE_PASSWORD = partner; // 支付API安全文件密码
	public final static String ipAddress = "120.76.152.52"; // ip地址
	
	/** 微信支付回掉url接口 */
	public final static String ORDER_PAY_BACK_URL = NameUtils.PATH_ROOT + "/iamberry/cart/payBack"; // 销售订单支付成功后回调地址
	public final static String ONLINE_TRIAL_BACK_URL = NameUtils.PATH_ROOT + "/iamberry/trial/back"; // 线上试用订单支付成功后的回调地址
	public final static String ONNLINE_TRIAL_BACK_URL = NameUtils.PATH_ROOT + "/iamberry/trial/onnlineBack"; // 线下使用订单，微信支付成功后的回调地址
	
	/** 微信授权获取用户的openid */
	public final static String GET_OPENID_DEAL_URL = NameUtils.PATH_ROOT + "/iamberry/dealOpenId";
	
	/** 发起微信支付的url地址 */
	// 下面两类，需要单独设置微信支付发起的权限URL
	public final static String CHECKOUT_TOPAY_URL = NameUtils.PATH_ROOT + "/iamberry/cart/toCheckOutUI/*"; // 结算页面发起微信支付
	public final static String ORDER_INFO_DESC_TOPAY_URL = NameUtils.PATH_ROOT + "/iamberry/cart/orderDescUI/*"; // 订单详情页面中发起微信支付
	// 下面三类可以使用一个微信支付权限URL
	public final static String ONLINE_TRIAL_TOPAY_URL = NameUtils.PATH_ROOT + "/iamberry/trial/index"; // 线上试用订单页面，发起微信支付请求
	public final static String ONLINE_TRIAL_ORDER_INFO_DESC_TOPAY_URL = NameUtils.PATH_ROOT + "/iamberry/trial/trialEtcOrderUI?order=*";// 线上试用订单详细界面中发起微信支付请求
	public final static String ONNLINE_TRIAL_ORDER_TOPAY_URL = NameUtils.PATH_ROOT + "/iamberry/trial/toOnnlinePayUI"; // 线下使用订单，线上付款，发起微信支付请求url
	
	/** 微信共享地址回调 */
	public final static String TOCHECKOUT_ADDR_URL = NameUtils.PATH_ROOT + "/iamberr/wechat/cart/settlement/"; // 结算页面的微信收货地址url
	public final static String TRIAL_ADDR_URL = NameUtils.PATH_ROOT + "/iamberry/trial/index"; // 线上试用的微信共享地址
	
	/** 微信图片的url */
	public final static String IMAGE_BASE_URL = NameUtils.PATH_ROOT;
	
	/** 官网  */
	public final static String WWW_INDEX = "http://www.iamberry.com";
	
	/** 线下订单付款前缀 */
	public final static String OFFLINE_ORDER_PREFIX = "9900123";
	
	/** 产品图片保存位置 */
	public final static String GOODS_SAVE_PATH = "/common/images/uploadimages/";
	
	/** 微信会员码起始数量 */
	public final static int MEMBER_NUM = 888888;
	
	/** 试用到期时间 */
	public final static Long TRIAL_DATE = 2592000000L;
	
	/** 替换的图片 */
	public final static String REPLACE_SECURITY_IMAGE = "http://192.168.1.129:8080/iamberry/common/images/security.jpg";
	
	//*********************  WXPublicNo.java end  *************/
	
	
	////***************** WeixnUtil  begin ***********************//////////
	// 获取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=";
	// 临时二维码
	public static String QR_SCENE = "{\"expire_seconds\": %s, \"action_name\": \"QR_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": %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";

	//***************** WeixnUtil  end ***********************//////////
	
	//***************** VerifyCodeUtil begin ******************/////////
	/** 
     * 验证码类型为仅数字,即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;  
    
  //***************** VerifyCodeUtil end ******************/////////
}
