Visitar URL original
:art: 优化微信支付异常处理代码,兼容混乱且变态的微信官方字段命名习惯 · linlinjava/WxJava@6852617 · GitHub
Skip to content

Commit 6852617

Browse files
committed
🎨 优化微信支付异常处理代码,兼容混乱且变态的微信官方字段命名习惯
1 parent 76fd3a2 commit 6852617

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,18 @@ public abstract class BaseWxPayResult {
5959
*/
6060
@XStreamAlias("result_code")
6161
private String resultCode;
62+
6263
/**
6364
* 错误代码.
6465
*/
6566
@XStreamAlias("err_code")
6667
private String errCode;
68+
/**
69+
* 错误代码描述.
70+
*/
71+
@XStreamAlias("err_code_des")
72+
private String errCodeDes;
73+
6774
/**
6875
* 错误代码.
6976
*/
@@ -72,8 +79,9 @@ public abstract class BaseWxPayResult {
7279
/**
7380
* 错误代码描述.
7481
*/
75-
@XStreamAlias("err_code_des")
76-
private String errCodeDes;
82+
@XStreamAlias("error_message")
83+
private String errorMessage;
84+
7785
/**
7886
* 公众账号ID.
7987
*/

‎weixin-java-pay/src/main/java/com/github/binarywang/wxpay/exception/WxPayException.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,24 @@ private WxPayException(Builder builder) {
8989
* @return the wx pay exception
9090
*/
9191
public static WxPayException from(BaseWxPayResult payBaseResult) {
92-
return WxPayException.newBuilder()
92+
WxPayException exception = WxPayException.newBuilder()
9393
.xmlString(payBaseResult.getXmlString())
9494
.returnMsg(payBaseResult.getReturnMsg())
9595
.returnCode(payBaseResult.getReturnCode())
9696
.resultCode(payBaseResult.getResultCode())
9797
.errCode(payBaseResult.getErrCode())
9898
.errCodeDes(payBaseResult.getErrCodeDes())
9999
.build();
100+
101+
if (payBaseResult.getErrorCode() != null) {
102+
exception.setErrCode(payBaseResult.getErrorCode());
103+
}
104+
105+
if (payBaseResult.getErrorMessage() != null) {
106+
exception.setErrCodeDes(payBaseResult.getErrorMessage());
107+
}
108+
109+
return exception;
100110
}
101111

102112
/**

0 commit comments

Comments
 (0)