Compare commits
2 Commits
v4.7.9
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8cbe46768 | ||
|
|
b8c6fccf84 |
@@ -319,6 +319,13 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
|
|||||||
public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData, String signType) throws WxPayException {
|
public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData, String signType) throws WxPayException {
|
||||||
try {
|
try {
|
||||||
log.debug("微信支付异步通知请求参数:{}", xmlData);
|
log.debug("微信支付异步通知请求参数:{}", xmlData);
|
||||||
|
|
||||||
|
// 检测数据格式并给出适当的处理建议
|
||||||
|
if (xmlData != null && xmlData.trim().startsWith("{")) {
|
||||||
|
throw new WxPayException("检测到V3版本的JSON格式通知数据,请使用parseOrderNotifyV3Result方法解析。" +
|
||||||
|
"V3 API需要传入SignatureHeader参数进行签名验证。");
|
||||||
|
}
|
||||||
|
|
||||||
WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData);
|
WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData);
|
||||||
if (signType == null) {
|
if (signType == null) {
|
||||||
this.switchover(result.getMchId(), result.getAppid());
|
this.switchover(result.getMchId(), result.getAppid());
|
||||||
|
|||||||
@@ -82,4 +82,35 @@ public class WxPayOrderNotifyResultTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that JSON format input throws a helpful error message.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testFromXMLWithJsonShouldGiveHelpfulError() {
|
||||||
|
String jsonString = "{\n" +
|
||||||
|
" \"id\": \"EV-2018022511223320873\",\n" +
|
||||||
|
" \"create_time\": \"2015-05-20T13:29:35+08:00\",\n" +
|
||||||
|
" \"resource_type\": \"encrypt-resource\",\n" +
|
||||||
|
" \"event_type\": \"TRANSACTION.SUCCESS\",\n" +
|
||||||
|
" \"summary\": \"支付成功\",\n" +
|
||||||
|
" \"resource\": {\n" +
|
||||||
|
" \"algorithm\": \"AEAD_AES_256_GCM\",\n" +
|
||||||
|
" \"ciphertext\": \"test\",\n" +
|
||||||
|
" \"associated_data\": \"transaction\",\n" +
|
||||||
|
" \"nonce\": \"test\"\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
try {
|
||||||
|
WxPayOrderNotifyResult.fromXML(jsonString);
|
||||||
|
Assert.fail("Expected exception for JSON input");
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Verify that the error message mentions whitespace/XML parsing issues
|
||||||
|
// This is the original XStream error that would occur
|
||||||
|
Assert.assertTrue(e.getMessage().contains("whitespace") ||
|
||||||
|
e.getMessage().contains("XmlPull") ||
|
||||||
|
e.getMessage().contains("START_DOCUMENT"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user