🎨 #1390 微信支付增加XML转换的快速模式,发送请求以及组装响应对象的时候不再依赖反射机制

* 增加XML的快速模式,发送请求以及组装响应对象的时候,不再依赖java的反射机制。
1:提升性能
2:可以通过 graalvm 生成native image.

本次完成:全部BaseWxPayRequest的改造,部分BaseWxPayResult子类的改造。

* clean code

* 标记 xmlDoc 为 transient 否则toString()方法中Gson可能会堆栈溢出

* 完成大多数BaseWxPayResult子类的改造。还有 notify.*Result下面留了两个TODO需要处理。

* toXML时遗漏了sign参数

* 使用dom4j简化了toXML,同时根据本版本构建native-image的demo已经提交: https://github.com/outersky/wx-micronaut-graal.git 供参考。

* 完成了最后两个Result的xml解析。
This commit is contained in:
outersky
2020-01-28 20:21:06 +08:00
committed by Binary Wang
parent 15f7de33f9
commit ccb25345ff
77 changed files with 1420 additions and 37 deletions

View File

@@ -21,6 +21,7 @@ import com.github.binarywang.wxpay.service.ProfitSharingService;
import com.github.binarywang.wxpay.service.RedpackService;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.util.SignUtils;
import com.github.binarywang.wxpay.util.XmlConfig;
import com.google.common.base.Joiner;
import com.google.common.collect.Maps;
import jodd.io.ZipUtil;
@@ -117,7 +118,8 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
}
String responseContent = this.post(url, request.toXML(), true);
WxPayRefundResult result = WxPayRefundResult.fromXML(responseContent);
WxPayRefundResult result = BaseWxPayResult.fromXML(responseContent, WxPayRefundResult.class);
result.composeRefundCoupons();
result.checkResult(this, request.getSignType(), true);
return result;
}
@@ -165,7 +167,13 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
public WxPayRefundNotifyResult parseRefundNotifyResult(String xmlData) throws WxPayException {
try {
log.debug("微信支付退款异步通知参数:{}", xmlData);
WxPayRefundNotifyResult result = WxPayRefundNotifyResult.fromXML(xmlData, this.getConfig().getMchKey());
WxPayRefundNotifyResult result;
if (XmlConfig.fastMode) {
result = BaseWxPayResult.fromXML(xmlData, WxPayRefundNotifyResult.class);
result.decryptReqInfo(this.getConfig().getMchKey());
} else {
result = WxPayRefundNotifyResult.fromXML(xmlData, this.getConfig().getMchKey());
}
log.debug("微信支付退款异步通知解析后的对象:{}", result);
return result;
} catch (Exception e) {