【特大注意】weixin4j.properties全部的属性名添加weixin4j前缀,并用.代替原来的_
This commit is contained in:
@@ -59,7 +59,7 @@ public abstract class BaseApi {
|
||||
static {
|
||||
DEFAULT_WEIXIN_ACCOUNT = Weixin4jConfigUtil.getWeixinAccount();
|
||||
DEFAULT_TOKEN_STORAGER = new FileTokenStorager(
|
||||
Weixin4jConfigUtil.getValue("token_path",
|
||||
Weixin4jConfigUtil.getValue("token.path",
|
||||
Weixin4jConst.DEFAULT_TOKEN_PATH));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.foxinmy.weixin4j.util.DateUtil;
|
||||
import com.foxinmy.weixin4j.util.RandomUtil;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConst;
|
||||
import com.foxinmy.weixin4j.xml.ListsuffixResultDeserializer;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
|
||||
@@ -305,7 +306,8 @@ public class Pay3Api {
|
||||
billType = BillType.ALL;
|
||||
}
|
||||
String formatBillDate = DateUtil.fortmat2yyyyMMdd(billDate);
|
||||
String bill_path = Weixin4jConfigUtil.getValue("bill_path");
|
||||
String bill_path = Weixin4jConfigUtil.getValue("bill.path",
|
||||
Weixin4jConst.DEFAULT_BILL_PATH);
|
||||
String fileName = String.format("%s_%s_%s.txt", formatBillDate,
|
||||
billType.name().toLowerCase(), weixinAccount.getId());
|
||||
File file = new File(String.format("%s/%s", bill_path, fileName));
|
||||
|
||||
@@ -115,7 +115,12 @@ public abstract class AbstractHttpClient implements HttpClient {
|
||||
protected void handleResponse(HttpResponse response)
|
||||
throws HttpClientException {
|
||||
HttpStatus status = response.getStatus();
|
||||
if (hasError(status)) {
|
||||
HttpHeaders headers = response.getHeaders();
|
||||
String contentType = headers.getFirst(HttpHeaders.CONTENT_TYPE);
|
||||
boolean jsonResult = contentType != null
|
||||
&& contentType.contains(ContentType.APPLICATION_JSON
|
||||
.getMimeType());
|
||||
if (!jsonResult && hasError(status)) {
|
||||
switch (status.series()) {
|
||||
case CLIENT_ERROR:
|
||||
case SERVER_ERROR:
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ public abstract class HttpClientFactory {
|
||||
private static volatile HttpClientFactory defaultFactory = newDefaultFactory();
|
||||
|
||||
/**
|
||||
* NettyHttpClient -> ApachHttpClient -> SimpleHttpClient(HttpURLConnection)
|
||||
* NettyHttpClient -> ApacheHttpClient -> SimpleHttpClient(HttpURLConnection)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@@ -68,7 +68,7 @@ public class WeixinPayProxy {
|
||||
this.pay3Api = new Pay3Api(weixinAccount);
|
||||
this.couponApi = new CouponApi(weixinAccount);
|
||||
this.cashApi = new CashApi(weixinAccount);
|
||||
this.DEFAULT_CA_FILE = Weixin4jConfigUtil.getClassPathValue("ca_file",
|
||||
this.DEFAULT_CA_FILE = Weixin4jConfigUtil.getClassPathValue("certificate.file",
|
||||
Weixin4jConst.DEFAULT_CAFILE_PATH);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.foxinmy.weixin4j.util;
|
||||
import java.io.File;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
@@ -23,12 +22,11 @@ public class Weixin4jConfigUtil {
|
||||
private final static ResourceBundle weixinBundle;
|
||||
static {
|
||||
weixinBundle = ResourceBundle.getBundle("weixin4j");
|
||||
Set<String> keySet = weixinBundle.keySet();
|
||||
File file = null;
|
||||
CLASSPATH_VALUE = Thread.currentThread().getContextClassLoader()
|
||||
.getResource("").getPath();
|
||||
for (String key : keySet) {
|
||||
if (!key.endsWith("_path")) {
|
||||
for (String key : weixinBundle.keySet()) {
|
||||
if (!key.endsWith(".path")) {
|
||||
continue;
|
||||
}
|
||||
file = new File(getValue(key).replaceFirst(CLASSPATH_PREFIX,
|
||||
@@ -40,6 +38,15 @@ public class Weixin4jConfigUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private final static String WEIXIN4J_PREFIX = "weixin4j";
|
||||
|
||||
private static String wrapKeyName(String key) {
|
||||
if (!key.startsWith(WEIXIN4J_PREFIX)) {
|
||||
return String.format("%s.%s", WEIXIN4J_PREFIX, key);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取weixin4j.properties文件中的key值
|
||||
*
|
||||
@@ -47,7 +54,8 @@ public class Weixin4jConfigUtil {
|
||||
* @return
|
||||
*/
|
||||
public static String getValue(String key) {
|
||||
return weixinBundle.getString(key);
|
||||
String wrapKey = wrapKeyName(key);
|
||||
return System.getProperty(wrapKey, weixinBundle.getString(wrapKey));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +68,7 @@ public class Weixin4jConfigUtil {
|
||||
public static String getValue(String key, String defaultValue) {
|
||||
String value = defaultValue;
|
||||
try {
|
||||
value = weixinBundle.getString(key);
|
||||
value = getValue(key);
|
||||
} catch (MissingResourceException e) {
|
||||
System.err.println("'" + key
|
||||
+ "' key not found in weixin4j.properties file.");
|
||||
@@ -101,7 +109,8 @@ public class Weixin4jConfigUtil {
|
||||
public static WeixinAccount getWeixinAccount() {
|
||||
WeixinAccount account = null;
|
||||
try {
|
||||
account = JSON.parseObject(getValue("account"), WeixinAccount.class);
|
||||
account = JSON
|
||||
.parseObject(getValue("account"), WeixinAccount.class);
|
||||
} catch (MissingResourceException e) {
|
||||
System.err
|
||||
.println("'account' key not found in weixin4j.properties file.");
|
||||
|
||||
Reference in New Issue
Block a user