add
yj
2024-12-05 b9900893177c78fc559223521fe839aa21000017
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package com.dobbinsoft.fw.pay.exception;
 
import com.dobbinsoft.fw.pay.model.result.MatrixBasePayResult;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.google.common.base.Joiner;
import lombok.Data;
import lombok.EqualsAndHashCode;
 
/**
 * <pre>
 * 微信支付异常结果类
 * </pre>
 *
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class MatrixPayException extends RuntimeException {
    private static final long serialVersionUID = 2214381471513460742L;
 
    /**
     * 自定义错误讯息.
     */
    private String customErrorMsg;
    /**
     * 返回状态码.
     */
    private String returnCode;
    /**
     * 返回信息.
     */
    private String returnMsg;
 
    /**
     * 业务结果.
     */
    private String resultCode;
 
    /**
     * 错误代码.
     */
    private String errCode;
 
    /**
     * 错误代码描述.
     */
    private String errCodeDes;
 
    /**
     * 微信支付返回的结果xml字符串.
     */
    private String xmlString;
 
    /**
     * Instantiates a new Wx pay exception.
     *
     * @param customErrorMsg the custom error msg
     */
    public MatrixPayException(String customErrorMsg) {
        super(customErrorMsg);
        this.customErrorMsg = customErrorMsg;
    }
 
    public MatrixPayException(WxPayException e) {
        returnCode = e.getReturnCode();
        returnMsg = e.getReturnMsg();
        resultCode = e.getResultCode();
        errCode = e.getErrCode();
        errCodeDes = e.getErrCodeDes();
        xmlString = e.getXmlString();
    }
 
    /**
     * Instantiates a new Wx pay exception.
     *
     * @param customErrorMsg the custom error msg
     * @param tr             the tr
     */
    public MatrixPayException(String customErrorMsg, Throwable tr) {
        super(customErrorMsg, tr);
        this.customErrorMsg = customErrorMsg;
    }
 
    private MatrixPayException(Builder builder) {
        super(builder.buildErrorMsg());
        returnCode = builder.returnCode;
        returnMsg = builder.returnMsg;
        resultCode = builder.resultCode;
        errCode = builder.errCode;
        errCodeDes = builder.errCodeDes;
        xmlString = builder.xmlString;
    }
 
    /**
     * 通过BaseWxPayResult生成异常对象.
     *
     * @param payBaseResult the pay base result
     * @return the wx pay exception
     */
    public static MatrixPayException from(MatrixBasePayResult payBaseResult) {
        return MatrixPayException.newBuilder()
                .xmlString(payBaseResult.getXmlString())
                .returnMsg(payBaseResult.getReturnMsg())
                .returnCode(payBaseResult.getReturnCode())
                .resultCode(payBaseResult.getResultCode())
                .errCode(payBaseResult.getErrCode())
                .errCodeDes(payBaseResult.getErrCodeDes())
                .build();
    }
 
    /**
     * New builder builder.
     *
     * @return the builder
     */
    public static Builder newBuilder() {
        return new Builder();
    }
 
    /**
     * The type Builder.
     */
    public static final class Builder {
        private String returnCode;
        private String returnMsg;
        private String resultCode;
        private String errCode;
        private String errCodeDes;
        private String xmlString;
 
        private Builder() {
        }
 
        /**
         * Return code builder.
         *
         * @param returnCode the return code
         * @return the builder
         */
        public Builder returnCode(String returnCode) {
            this.returnCode = returnCode;
            return this;
        }
 
        /**
         * Return msg builder.
         *
         * @param returnMsg the return msg
         * @return the builder
         */
        public Builder returnMsg(String returnMsg) {
            this.returnMsg = returnMsg;
            return this;
        }
 
        /**
         * Result code builder.
         *
         * @param resultCode the result code
         * @return the builder
         */
        public Builder resultCode(String resultCode) {
            this.resultCode = resultCode;
            return this;
        }
 
        /**
         * Err code builder.
         *
         * @param errCode the err code
         * @return the builder
         */
        public Builder errCode(String errCode) {
            this.errCode = errCode;
            return this;
        }
 
        /**
         * Err code des builder.
         *
         * @param errCodeDes the err code des
         * @return the builder
         */
        public Builder errCodeDes(String errCodeDes) {
            this.errCodeDes = errCodeDes;
            return this;
        }
 
        /**
         * Xml string builder.
         *
         * @param xmlString the xml string
         * @return the builder
         */
        public Builder xmlString(String xmlString) {
            this.xmlString = xmlString;
            return this;
        }
 
        /**
         * Build wx pay exception.
         *
         * @return the wx pay exception
         */
        public MatrixPayException build() {
            return new MatrixPayException(this);
        }
 
        /**
         * Build error msg string.
         *
         * @return the string
         */
        public String buildErrorMsg() {
            return Joiner.on(",").skipNulls().join(
                    returnCode == null ? null : String.format("返回代码:[%s]", returnCode),
                    returnMsg == null ? null : String.format("返回信息:[%s]", returnMsg),
                    resultCode == null ? null : String.format("结果代码:[%s]", resultCode),
                    errCode == null ? null : String.format("错误代码:[%s]", errCode),
                    errCodeDes == null ? null : String.format("错误详情:[%s]", errCodeDes),
                    xmlString == null ? null : "微信返回的原始报文:\n" + xmlString
            );
        }
    }
}