Skip to content

Commit b17d06c

Browse files
committed
优化代码
1 parent 3969124 commit b17d06c

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpXmlMessage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.io.InputStream;
55
import java.io.Serializable;
6+
import java.nio.charset.StandardCharsets;
67
import java.util.ArrayList;
78
import java.util.List;
89

@@ -369,7 +370,7 @@ public static WxCpXmlMessage fromEncryptedXml(String encryptedXml, WxCpConfigSto
369370
public static WxCpXmlMessage fromEncryptedXml(InputStream is, WxCpConfigStorage wxCpConfigStorage,
370371
String timestamp, String nonce, String msgSignature) {
371372
try {
372-
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxCpConfigStorage, timestamp, nonce, msgSignature);
373+
return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8), wxCpConfigStorage, timestamp, nonce, msgSignature);
373374
} catch (IOException e) {
374375
throw new RuntimeException(e);
375376
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/message/WxMpXmlMessage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.io.InputStream;
55
import java.io.Serializable;
6+
import java.nio.charset.StandardCharsets;
67
import java.util.Map;
78

89
import org.apache.commons.io.IOUtils;
@@ -662,7 +663,7 @@ public static WxMpXmlMessage fromEncryptedXml(String encryptedXml, WxMpConfigSto
662663
public static WxMpXmlMessage fromEncryptedXml(InputStream is, WxMpConfigStorage wxMpConfigStorage, String timestamp,
663664
String nonce, String msgSignature) {
664665
try {
665-
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxMpConfigStorage, timestamp, nonce, msgSignature);
666+
return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8), wxMpConfigStorage, timestamp, nonce, msgSignature);
666667
} catch (IOException e) {
667668
throw new RuntimeException(e);
668669
}

weixin-java-open/src/main/java/me/chanjar/weixin/open/bean/message/WxOpenXmlMessage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.io.InputStream;
55
import java.io.Serializable;
6+
import java.nio.charset.StandardCharsets;
67

78
import org.apache.commons.io.IOUtils;
89

@@ -99,7 +100,7 @@ public static WxMpXmlMessage fromEncryptedMpXml(String encryptedXml, WxOpenConfi
99100
public static WxOpenXmlMessage fromEncryptedXml(InputStream is, WxOpenConfigStorage wxOpenConfigStorage,
100101
String timestamp, String nonce, String msgSignature) {
101102
try {
102-
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"),
103+
return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8),
103104
wxOpenConfigStorage, timestamp, nonce, msgSignature);
104105
} catch (IOException e) {
105106
throw new RuntimeException(e);

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/BaseWxPayResult.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.github.binarywang.wxpay.bean.result;
22

33
import java.io.ByteArrayInputStream;
4-
import java.io.IOException;
54
import java.io.Serializable;
65
import java.math.BigDecimal;
76
import java.nio.charset.StandardCharsets;
87
import java.util.List;
98
import java.util.Map;
109
import javax.xml.parsers.DocumentBuilderFactory;
11-
import javax.xml.parsers.ParserConfigurationException;
1210
import javax.xml.xpath.XPathConstants;
1311
import javax.xml.xpath.XPathExpressionException;
1412
import javax.xml.xpath.XPathFactory;
@@ -18,7 +16,6 @@
1816
import org.slf4j.LoggerFactory;
1917
import org.w3c.dom.Document;
2018
import org.w3c.dom.NodeList;
21-
import org.xml.sax.SAXException;
2219

2320
import com.github.binarywang.wxpay.constant.WxPayConstants;
2421
import com.github.binarywang.wxpay.exception.WxPayException;
@@ -195,8 +192,8 @@ private Document getXmlDoc() {
195192
this.xmlDoc = factory.newDocumentBuilder()
196193
.parse(new ByteArrayInputStream(this.xmlString.getBytes(StandardCharsets.UTF_8)));
197194
return xmlDoc;
198-
} catch (SAXException | IOException | ParserConfigurationException e) {
199-
throw new RuntimeException("非法的xml文本内容:" + this.xmlString);
195+
} catch (Exception e) {
196+
throw new RuntimeException("非法的xml文本内容:\n" + this.xmlString, e);
200197
}
201198

202199
}

0 commit comments

Comments
 (0)