@@ -3,6 +3,7 @@ package me.chanjar.weixin.cp.bean; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.io.Serializable; | import java.io.Serializable; | ||||
import java.nio.charset.StandardCharsets; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
@@ -369,7 +370,7 @@ public class WxCpXmlMessage implements Serializable { | |||||
public static WxCpXmlMessage fromEncryptedXml(InputStream is, WxCpConfigStorage wxCpConfigStorage, | public static WxCpXmlMessage fromEncryptedXml(InputStream is, WxCpConfigStorage wxCpConfigStorage, | ||||
String timestamp, String nonce, String msgSignature) { | String timestamp, String nonce, String msgSignature) { | ||||
try { | try { | ||||
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxCpConfigStorage, timestamp, nonce, msgSignature); | |||||
return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8), wxCpConfigStorage, timestamp, nonce, msgSignature); | |||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
@@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.bean.message; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.io.Serializable; | import java.io.Serializable; | ||||
import java.nio.charset.StandardCharsets; | |||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.commons.io.IOUtils; | import org.apache.commons.io.IOUtils; | ||||
@@ -662,7 +663,7 @@ public class WxMpXmlMessage implements Serializable { | |||||
public static WxMpXmlMessage fromEncryptedXml(InputStream is, WxMpConfigStorage wxMpConfigStorage, String timestamp, | public static WxMpXmlMessage fromEncryptedXml(InputStream is, WxMpConfigStorage wxMpConfigStorage, String timestamp, | ||||
String nonce, String msgSignature) { | String nonce, String msgSignature) { | ||||
try { | try { | ||||
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), wxMpConfigStorage, timestamp, nonce, msgSignature); | |||||
return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8), wxMpConfigStorage, timestamp, nonce, msgSignature); | |||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
} | } | ||||
@@ -3,6 +3,7 @@ package me.chanjar.weixin.open.bean.message; | |||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.io.InputStream; | import java.io.InputStream; | ||||
import java.io.Serializable; | import java.io.Serializable; | ||||
import java.nio.charset.StandardCharsets; | |||||
import org.apache.commons.io.IOUtils; | import org.apache.commons.io.IOUtils; | ||||
@@ -99,7 +100,7 @@ public class WxOpenXmlMessage implements Serializable { | |||||
public static WxOpenXmlMessage fromEncryptedXml(InputStream is, WxOpenConfigStorage wxOpenConfigStorage, | public static WxOpenXmlMessage fromEncryptedXml(InputStream is, WxOpenConfigStorage wxOpenConfigStorage, | ||||
String timestamp, String nonce, String msgSignature) { | String timestamp, String nonce, String msgSignature) { | ||||
try { | try { | ||||
return fromEncryptedXml(IOUtils.toString(is, "UTF-8"), | |||||
return fromEncryptedXml(IOUtils.toString(is, StandardCharsets.UTF_8), | |||||
wxOpenConfigStorage, timestamp, nonce, msgSignature); | wxOpenConfigStorage, timestamp, nonce, msgSignature); | ||||
} catch (IOException e) { | } catch (IOException e) { | ||||
throw new RuntimeException(e); | throw new RuntimeException(e); | ||||
@@ -1,14 +1,12 @@ | |||||
package com.github.binarywang.wxpay.bean.result; | package com.github.binarywang.wxpay.bean.result; | ||||
import java.io.ByteArrayInputStream; | import java.io.ByteArrayInputStream; | ||||
import java.io.IOException; | |||||
import java.io.Serializable; | import java.io.Serializable; | ||||
import java.math.BigDecimal; | import java.math.BigDecimal; | ||||
import java.nio.charset.StandardCharsets; | import java.nio.charset.StandardCharsets; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import javax.xml.parsers.DocumentBuilderFactory; | import javax.xml.parsers.DocumentBuilderFactory; | ||||
import javax.xml.parsers.ParserConfigurationException; | |||||
import javax.xml.xpath.XPathConstants; | import javax.xml.xpath.XPathConstants; | ||||
import javax.xml.xpath.XPathExpressionException; | import javax.xml.xpath.XPathExpressionException; | ||||
import javax.xml.xpath.XPathFactory; | import javax.xml.xpath.XPathFactory; | ||||
@@ -18,7 +16,6 @@ import org.slf4j.Logger; | |||||
import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
import org.w3c.dom.Document; | import org.w3c.dom.Document; | ||||
import org.w3c.dom.NodeList; | import org.w3c.dom.NodeList; | ||||
import org.xml.sax.SAXException; | |||||
import com.github.binarywang.wxpay.constant.WxPayConstants; | import com.github.binarywang.wxpay.constant.WxPayConstants; | ||||
import com.github.binarywang.wxpay.exception.WxPayException; | import com.github.binarywang.wxpay.exception.WxPayException; | ||||
@@ -195,8 +192,8 @@ public abstract class BaseWxPayResult implements Serializable { | |||||
this.xmlDoc = factory.newDocumentBuilder() | this.xmlDoc = factory.newDocumentBuilder() | ||||
.parse(new ByteArrayInputStream(this.xmlString.getBytes(StandardCharsets.UTF_8))); | .parse(new ByteArrayInputStream(this.xmlString.getBytes(StandardCharsets.UTF_8))); | ||||
return xmlDoc; | return xmlDoc; | ||||
} catch (SAXException | IOException | ParserConfigurationException e) { | |||||
throw new RuntimeException("非法的xml文本内容:" + this.xmlString); | |||||
} catch (Exception e) { | |||||
throw new RuntimeException("非法的xml文本内容:\n" + this.xmlString, e); | |||||
} | } | ||||
} | } | ||||