properties配置文件的读取工具类

package com.chb.pay.util;

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

public class PropertiesUtil {
	
	/**
	 * 从指定路径读取Properties文件
	 * @param path
	 * @return
	 * @throws IOException
	 */
	public static Properties getPropertiesFromClassPath(String path) throws IOException{
		Properties prop = new Properties();
		if(path != null){
			InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
			prop.load(input);
		}
		return prop;
	}
}

配置文件路径:  src/main/resources/conf/pay/Alipay.properties

package com.chb.pay.module.alipay.config;

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

import com.chb.pay.util.PropertiesUtil;

/* *
 *类名:AlipayConfig
 *功能:基础配置类
 *详细:设置帐户有关信息及返回路径

 *提示:如何获取安全校验码和合作身份者ID
 *1.用您的签约支付宝账号登录支付宝网站(www.alipay.com)
 *2.点击“商家服务”(https://b.alipay.com/order/myOrder.htm)
 *3.点击“查询合作者身份(PID)”、“查询安全校验码(Key)”

 *安全校验码查看时,输入支付密码后,页面呈灰色的现象:
 *解决方法:
 *1、检查浏览器配置,不让浏览器做弹框屏蔽设置
 *2、更换浏览器或电脑,重新登录查询。
 */

public class AlipayConfig {
	
	private static Properties prop = null;

	static {
		if(prop == null){
			try {
				prop = PropertiesUtil.getPropertiesFromClassPath("conf/pay/Alipay.properties");
			} catch (IOException e) {
				throw new RuntimeException("Alipay.properties");
			}
		}
	}

	// ↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
	// 合作身份者ID,以2088开头由16位纯数字组成的字符串
	
	public static List<String> partners = new ArrayList<String>();

	 
	
	public static List<String> mobile_partners = new ArrayList<String>();
	
	// 商户的私钥
	public static List<String> keys = new ArrayList<String>();

	
	/ 
	
	public static List<String> mobile_keys = new ArrayList<String>();

	// ↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

	// 调试用,创建TXT日志文件夹路径
	public static String log_path = "D:\\";

	// 字符编码格式 目前支持 gbk 或 utf-8
	public static String input_charset = prop.getProperty("input_charset");

	// 商户的私钥
	// 如果签名方式设置为“0001”时,请设置该参数
	
	public static List<String> private_keys = new ArrayList<String>();

	public static List<String> ali_public_keys = new ArrayList<String>();

	// 签名方式 不需修改
	public static String sign_type = "MD5";

	public static String payment_type = prop.getProperty("payment_type");

	public static List<String> seller_emails = new ArrayList<String>();

	 
	public static List<String> mobile_seller_emails = new ArrayList<String>();

	public static String paymethod = "";

	public static String defaultbank = "";

	public static String it_b_pay = prop.getProperty("it_b_pay");
	
//	请求方式
	public static Integer pcType = 1;
	
//	请求方式
	public static Integer wapType = 2;

	 

	// online
	public static String notify_url = prop.getProperty("notify_url");
	public static String return_url = prop.getProperty("return_url");
	public static String hebao_req_url = prop.getProperty("hebao_req_url");
	public static String refund_notify_url = prop.getProperty("refund_notify_url");
	public static String merchant_url = prop.getProperty("merchant_url");
	

	static{
		String zero = "0";
		for (int i = 1; i < 7; i++) {
			partners.add(prop.getProperty(zero+i+"_partner"));
			mobile_partners.add(prop.getProperty(zero+i+"_mobile_partner"));
			keys.add(prop.getProperty(zero+i+"_key"));
			mobile_keys.add(prop.getProperty(zero + i + "_mobile_key"));
			private_keys.add(prop.getProperty(zero + i + "_private_key"));
			ali_public_keys.add(prop.getProperty(zero + i + "_ali_public_key"));
			seller_emails.add(prop.getProperty(zero + i + "_seller_email"));
			mobile_seller_emails.add(prop.getProperty(zero + i + "_mobile_seller_email"));
		}
	}
	 

}


将配置文件的信息转换成Map:

package com.chb.pay.config;

import com.chb.pay.util.PropertiesUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * 功能说明:读取servercode.properties文件
 * @author caohaibing
 * @date 2015年3月25日上午9:35:15
 * @version V0.1
 * @since JDK1.6
 */
public class ServerCodeConfig {
	private static Properties prop = null;

	static {
		if(prop == null){
			try {
				prop = PropertiesUtil.getPropertiesFromClassPath("conf/servercode.properties");
			} catch (IOException e) {
				throw new RuntimeException("conf/servercode.properties");
			}
		}
	}
	
	public static Map<String, String> serverCodeMap;
	static{
		serverCodeMap = new HashMap<String, String>();
		Set<Object> set = prop.keySet();
		for (Object object : set) {
			serverCodeMap.put((String) object, prop.getProperty((String) object));
		}
	}
}
String serverCode = ServerCodeConfig.serverCodeMap.get(ipAddressPort);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值