配置文件
weixinpay.properties 配置文件
##weixin_pay_APPID
WeiXin_AppId = wxfce80d1dsf934765793
##åweixin_pay_mch_id
WeiXin_MCH_ID=15035236491
##weixin_pay_NOTIFY_URL
WeiXin_NOTIFY_URL=m.wdefs.com/product/app/weiXinPayNotify
##weixin_pay_Refund_Url
WeiXin_Refund_Url=C:/apiclient_cert/apiclient_cert.p12
##
WeiXin_Secret_Key=
##weixin_pay_Sign_Key
WeiXin_Sign_Key=VrYzT4sdDoCSGSCpKYWMZ3ZQy11fk2V
工具类 PropertiesUtil
/**
*
* <p>
* Title: getProperty
* </p>
* <p>
* Description:
* </p>
*
* @param resourcePath
* properties 路径 文件名
* @param key
* 值对应的键
* @return
*/
public static String getProperty(String resourcePath, String key) {
String value = "";
InputStream in = null;
try {
in = PropertiesUtil.class.getClassLoader().getResourceAsStream(resourcePath + ".properties");
Properties properties = new Properties();
InputStreamReader inputStreamReader = new InputStreamReader(in, "UTF-8");
properties.load(inputStreamReader);
value = (String) properties.get(key);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return value;
}
工具类调用配置文件读取所对应的值 WeiXinPayController
String WeiXin_AppId = PropertiesUtil.getProperty("weixinpay", "WeiXin_AppId"); //安卓
String WeiXin_MCH_ID = PropertiesUtil.getProperty("weixinpay", "WeiXin_MCH_ID"); //安卓
String WeiXin_NOTIFY_URL = PropertiesUtil.getProperty("weixinpay", "WeiXin_NOTIFY_URL"); //安卓
String WeiXin_Refund_Url = PropertiesUtil.getProperty("weixinpay", "WeiXin_Refund_Url"); //安卓
String WeiXin_Sign_Key = PropertiesUtil.getProperty("weixinpay", "WeiXin_Sign_Key"); //安卓