mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 16:18:51 +08:00
🎨 优化微信支付异常处理代码,兼容混乱且变态的微信官方字段命名习惯
This commit is contained in:
parent
76fd3a20b5
commit
6852617bd7
@ -59,11 +59,18 @@ public abstract class BaseWxPayResult {
|
||||
*/
|
||||
@XStreamAlias("result_code")
|
||||
private String resultCode;
|
||||
|
||||
/**
|
||||
* 错误代码.
|
||||
*/
|
||||
@XStreamAlias("err_code")
|
||||
private String errCode;
|
||||
/**
|
||||
* 错误代码描述.
|
||||
*/
|
||||
@XStreamAlias("err_code_des")
|
||||
private String errCodeDes;
|
||||
|
||||
/**
|
||||
* 错误代码.
|
||||
*/
|
||||
@ -72,8 +79,9 @@ public abstract class BaseWxPayResult {
|
||||
/**
|
||||
* 错误代码描述.
|
||||
*/
|
||||
@XStreamAlias("err_code_des")
|
||||
private String errCodeDes;
|
||||
@XStreamAlias("error_message")
|
||||
private String errorMessage;
|
||||
|
||||
/**
|
||||
* 公众账号ID.
|
||||
*/
|
||||
|
@ -89,7 +89,7 @@ public class WxPayException extends Exception {
|
||||
* @return the wx pay exception
|
||||
*/
|
||||
public static WxPayException from(BaseWxPayResult payBaseResult) {
|
||||
return WxPayException.newBuilder()
|
||||
WxPayException exception = WxPayException.newBuilder()
|
||||
.xmlString(payBaseResult.getXmlString())
|
||||
.returnMsg(payBaseResult.getReturnMsg())
|
||||
.returnCode(payBaseResult.getReturnCode())
|
||||
@ -97,6 +97,16 @@ public class WxPayException extends Exception {
|
||||
.errCode(payBaseResult.getErrCode())
|
||||
.errCodeDes(payBaseResult.getErrCodeDes())
|
||||
.build();
|
||||
|
||||
if (payBaseResult.getErrorCode() != null) {
|
||||
exception.setErrCode(payBaseResult.getErrorCode());
|
||||
}
|
||||
|
||||
if (payBaseResult.getErrorMessage() != null) {
|
||||
exception.setErrCodeDes(payBaseResult.getErrorMessage());
|
||||
}
|
||||
|
||||
return exception;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user