申请退款

更新时间:2025.01.09

在交易完成后的一年内(以支付成功时间为起点+365天计算),若因用户或商户方面导致需进行订单退款,商户可通过此接口将支付金额的全部或部分原路退还至用户。详细介绍参考:订单退款-产品介绍

注意:

1、一笔订单最多支持50次部分退款(若需多次部分退款,请更换商户退款单号并间隔1分钟后再次调用)。

2、在申请退款失败后进行重试时,请务必使用原商户退款单号,以避免因重复退款而导致的资金损失。

3、同一商户号下,此接口调用成功的频率限制为150QPS,而调用失败报错时的频率限制为6QPS。

4、申请退款接口返回成功仅表示退款单已受理成功,具体的退款结果需依据退款结果通知查询退款的返回信息为准。

5、若一个月前的订单申请退款时返回报错“频率限制,1个月之前的订单请降低申请频率再重试”,请调整退款时间,再使用原参数进行重试。

接口说明

支持商户:【普通商户】

请求方式:【POST】/v3/refund/domestic/refunds

请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点

     【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看

请求参数

Header HTTP头参数

Authorization  必填 string

请参考签名认证生成认证信息


Accept  必填 string

请设置为application/json


Content-Type  必填 string

请设置为application/json


body 包体参数

transaction_id  选填 string(32)

【微信支付订单号】 微信支付侧订单的唯一标识,订单支付成功后,查询订单支付成功回调通知会返回该参数。
transaction_id和out_trade_no必须二选一进行传参。


out_trade_no  选填 string(32)

【商户订单号】 商户下单时传入的商户系统内部订单号。
transaction_id和out_trade_no必须二选一进行传参。


out_refund_no  必填 string(64)

【商户退款单号】 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一商户退款单号多次请求只退一笔。不可超过64个字节数。


reason  选填 string(80)

【退款原因】 若商户传了退款原因,该原因将在下发给用户的退款消息中显示,具体展示可参见退款通知UI示意图

请注意:1、该退款原因参数的长度不得超过80个字节;2、当订单退款金额小于等于1元且为部分退款时,退款原因将不会在消息中体现。


notify_url  选填 string(256)

【退款结果回调url】 异步接收微信支付退款结果通知的回调地址,通知url必须为外网可访问的url,不能携带参数。 如果传了该参数,则商户平台上配置的回调地址(商户平台-交易中心-退款管理-退款配置)将不会生效,优先回调当前传的这个地址。


funds_account  选填 string

【退款资金来源】 若传递此参数则使用对应的资金账户退款。

可选取值:

  • AVAILABLE: 仅对旧资金流商户适用(请参考旧资金流介绍区分),传此枚举指定从可用余额账户出资,否则默认使用未结算资金退款。

  • UNSETTLED: 仅对出行预付押金退款适用,指定从未结算资金出资。


amount  必填 object

【金额信息】订单退款金额信息

属性

goods_detail  选填 array[GoodsDetail]

【退款商品】 请填写需要指定退款的商品信息,所指定的商品信息需要与下单时传入的单品列表goods_detail中的对应商品信息一致 ,如无需按照指定商品退款,本字段不填。 

属性

请求示例

Java
Go
curl

需配合微信支付工具库 WXPayUtility 使用,请参考 Java 

1package com.java.demo;
2
3import com.google.gson.annotations.Expose;
4import com.google.gson.annotations.SerializedName;
5import com.java.utils.WXPayUtility; // 引用微信支付工具库 参考:https://pay.weixin.qq.com/doc/v3/merchant/4014931831
6import java.io.IOException;
7import java.io.UncheckedIOException;
8import java.security.PrivateKey;
9import java.security.PublicKey;
10import java.util.ArrayList;
11import java.util.HashMap;
12import java.util.List;
13import java.util.Map;
14import okhttp3.MediaType;
15import okhttp3.OkHttpClient;
16import okhttp3.Request;
17import okhttp3.RequestBody;
18import okhttp3.Response;
19
20/**
21 * 退款申请
22 */
23public class Create {
24  private static String HOST = "https://api.mch.weixin.qq.com";
25  private static String METHOD = "POST";
26  private static String PATH = "/v3/refund/domestic/refunds";
27
28  public static void main(String[] args) {
29    // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756
30    Create client = new Create(
31        "填入 商户号",                  // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考https://pay.weixin.qq.com/doc/v3/merchant/4013070756
32        "填入 商户API证书序列号",       // 商户API证书序列号,如何获取请参考https://pay.weixin.qq.com/doc/v3/merchant/4013053053
33        "填入 商户API证书私钥文件路径", // 商户API证书私钥文件路径,本地文件路径
34        "填入 微信支付公钥ID",          // 微信支付公钥ID,如何获取请参考https://pay.weixin.qq.com/doc/v3/merchant/4013038816
35        "填入 微信支付公钥文件路径"     // 微信支付公钥文件路径,本地文件路径
36    );
37
38    CreateRequest request = new CreateRequest();
39    request.transactionId = "1217752501201407033233368018";
40    request.outTradeNo = "1217752501201407033233368018";
41    request.outRefundNo = "1217752501201407033233368018";
42    request.reason = "商品已售完";
43    request.notifyUrl = "https://weixin.qq.com";
44    request.fundsAccount = ReqFundsAccount.AVAILABLE;
45    request.amount = new AmountReq();
46    request.amount.refund = 888L;
47    request.amount.from = new ArrayList<>();
48    {
49      FundsFromItem item0 = new FundsFromItem();
50      item0.account = Account.AVAILABLE;
51      item0.amount = 444L;
52      request.amount.from.add(item0);
53    };
54    request.amount.total = 888L;
55    request.amount.currency = "CNY";
56    request.goodsDetail = new ArrayList<>();
57    {
58      GoodsDetail item0 = new GoodsDetail();
59      item0.merchantGoodsId = "1217752501201407033233368018";
60      item0.wechatpayGoodsId = "1001";
61      item0.goodsName = "iPhone6s 16G";
62      item0.unitPrice = 528800L;
63      item0.refundAmount = 528800L;
64      item0.refundQuantity = 1;
65      request.goodsDetail.add(item0);
66    };
67    try {
68      Refund response = client.run(request);
69
70      // TODO: 请求成功,继续业务逻辑
71      System.out.println(response);
72    } catch (WXPayUtility.ApiException e) {
73      // TODO: 请求失败,根据状态码执行不同的逻辑
74      e.printStackTrace();
75    }
76  }
77
78  public Refund run(CreateRequest request) {
79    String uri = PATH;
80    String reqBody = WXPayUtility.toJson(request);
81
82    Request.Builder reqBuilder = new Request.Builder().url(HOST + uri);
83    reqBuilder.addHeader("Accept", "application/json");
84    reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId);
85    reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, reqBody));
86    reqBuilder.addHeader("Content-Type", "application/json");
87    RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody);
88    reqBuilder.method(METHOD, requestBody);
89    Request httpRequest = reqBuilder.build();
90
91    // 发送HTTP请求
92    OkHttpClient client = new OkHttpClient.Builder().build();
93    try (Response httpResponse = client.newCall(httpRequest).execute()) {
94      String respBody = WXPayUtility.extractBody(httpResponse);
95      if (httpResponse.code() >= 200 && httpResponse.code() < 300) {
96        // 2XX 成功,验证应答签名
97        WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey,
98                                      httpResponse.headers(), respBody);
99
100        // 从HTTP应答报文构建返回数据
101        return WXPayUtility.fromJson(respBody, Refund.class);
102      } else {
103        throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers());
104      }
105    } catch (IOException e) {
106      throw new UncheckedIOException("Sending request to " + uri + " failed.", e);
107    }
108  }
109
110  private final String mchid;
111  private final String certificateSerialNo;
112  private final PrivateKey privateKey;
113  private final String wechatPayPublicKeyId;
114  private final PublicKey wechatPayPublicKey;
115
116  public Create(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) {
117    this.mchid = mchid;
118    this.certificateSerialNo = certificateSerialNo;
119    this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath);
120    this.wechatPayPublicKeyId = wechatPayPublicKeyId;
121    this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath);
122  }
123
124  public enum Status {
125    @SerializedName("SUCCESS")
126    SUCCESS,
127    @SerializedName("CLOSED")
128    CLOSED,
129    @SerializedName("PROCESSING")
130    PROCESSING,
131    @SerializedName("ABNORMAL")
132    ABNORMAL
133  }
134
135  public enum Account {
136    @SerializedName("AVAILABLE")
137    AVAILABLE,
138    @SerializedName("UNAVAILABLE")
139    UNAVAILABLE
140  }
141
142  public enum PromotionType {
143    @SerializedName("COUPON")
144    COUPON,
145    @SerializedName("DISCOUNT")
146    DISCOUNT
147  }
148
149  public static class GoodsDetail {
150    @SerializedName("merchant_goods_id")
151    public String merchantGoodsId;
152
153    @SerializedName("wechatpay_goods_id")
154    public String wechatpayGoodsId;
155
156    @SerializedName("goods_name")
157    public String goodsName;
158
159    @SerializedName("unit_price")
160    public Long unitPrice;
161
162    @SerializedName("refund_amount")
163    public Long refundAmount;
164
165    @SerializedName("refund_quantity")
166    public Integer refundQuantity;
167  }
168
169  public static class CreateRequest {
170    @SerializedName("transaction_id")
171    public String transactionId;
172
173    @SerializedName("out_trade_no")
174    public String outTradeNo;
175
176    @SerializedName("out_refund_no")
177    public String outRefundNo;
178
179    @SerializedName("reason")
180    public String reason;
181
182    @SerializedName("notify_url")
183    public String notifyUrl;
184
185    @SerializedName("funds_account")
186    public ReqFundsAccount fundsAccount;
187
188    @SerializedName("amount")
189    public AmountReq amount;
190
191    @SerializedName("goods_detail")
192    public List<GoodsDetail> goodsDetail;
193  }
194
195  public enum Channel {
196    @SerializedName("ORIGINAL")
197    ORIGINAL,
198    @SerializedName("BALANCE")
199    BALANCE,
200    @SerializedName("OTHER_BALANCE")
201    OTHER_BALANCE,
202    @SerializedName("OTHER_BANKCARD")
203    OTHER_BANKCARD
204  }
205
206  public static class Amount {
207    @SerializedName("total")
208    public Long total;
209
210    @SerializedName("refund")
211    public Long refund;
212
213    @SerializedName("from")
214    public List<FundsFromItem> from;
215
216    @SerializedName("payer_total")
217    public Long payerTotal;
218
219    @SerializedName("payer_refund")
220    public Long payerRefund;
221
222    @SerializedName("settlement_refund")
223    public Long settlementRefund;
224
225    @SerializedName("settlement_total")
226    public Long settlementTotal;
227
228    @SerializedName("discount_refund")
229    public Long discountRefund;
230
231    @SerializedName("currency")
232    public String currency;
233
234    @SerializedName("refund_fee")
235    public Long refundFee;
236  }
237
238  public enum ReqFundsAccount {
239    @SerializedName("AVAILABLE")
240    AVAILABLE,
241    @SerializedName("UNSETTLED")
242    UNSETTLED
243  }
244
245  public enum FundsAccount {
246    @SerializedName("UNSETTLED")
247    UNSETTLED,
248    @SerializedName("AVAILABLE")
249    AVAILABLE,
250    @SerializedName("UNAVAILABLE")
251    UNAVAILABLE,
252    @SerializedName("OPERATION")
253    OPERATION,
254    @SerializedName("BASIC")
255    BASIC,
256    @SerializedName("ECNY_BASIC")
257    ECNY_BASIC
258  }
259
260  public static class Promotion {
261    @SerializedName("promotion_id")
262    public String promotionId;
263
264    @SerializedName("scope")
265    public PromotionScope scope;
266
267    @SerializedName("type")
268    public PromotionType type;
269
270    @SerializedName("amount")
271    public Long amount;
272
273    @SerializedName("refund_amount")
274    public Long refundAmount;
275
276    @SerializedName("goods_detail")
277    public List<GoodsDetail> goodsDetail;
278  }
279
280  public static class Refund {
281    @SerializedName("refund_id")
282    public String refundId;
283
284    @SerializedName("out_refund_no")
285    public String outRefundNo;
286
287    @SerializedName("transaction_id")
288    public String transactionId;
289
290    @SerializedName("out_trade_no")
291    public String outTradeNo;
292
293    @SerializedName("channel")
294    public Channel channel;
295
296    @SerializedName("user_received_account")
297    public String userReceivedAccount;
298
299    @SerializedName("success_time")
300    public String successTime;
301
302    @SerializedName("create_time")
303    public String createTime;
304
305    @SerializedName("status")
306    public Status status;
307
308    @SerializedName("funds_account")
309    public FundsAccount fundsAccount;
310
311    @SerializedName("amount")
312    public Amount amount;
313
314    @SerializedName("promotion_detail")
315    public List<Promotion> promotionDetail;
316  }
317
318  public static class FundsFromItem {
319    @SerializedName("account")
320    public Account account;
321
322    @SerializedName("amount")
323    public Long amount;
324  }
325
326  public static class AmountReq {
327    @SerializedName("refund")
328    public Long refund;
329
330    @SerializedName("from")
331    public List<FundsFromItem> from;
332
333    @SerializedName("total")
334    public Long total;
335
336    @SerializedName("currency")
337    public String currency;
338  }
339
340  public enum PromotionScope {
341    @SerializedName("GLOBAL")
342    GLOBAL,
343    @SerializedName("SINGLE")
344    SINGLE
345  }
346}

应答参数

200 OK

refund_id  必填 string(32)

【微信支付退款单号】申请退款受理成功时,该笔退款单在微信支付侧生成的唯一标识。


out_refund_no  必填 string(64)

【商户退款单号】 商户申请退款时传的商户系统内部退款单号。


transaction_id  必填 string(32)

【微信支付订单号】微信支付侧订单的唯一标识。


out_trade_no  必填 string(32)

【商户订单号】 商户下单时传入的商户系统内部订单号。


channel  必填 string

【退款渠道】 订单退款渠道
以下枚举:

  • ORIGINAL: 原路退款

  • BALANCE: 退回到余额

  • OTHER_BALANCE: 原账户异常退到其他余额账户

  • OTHER_BANKCARD: 原银行卡异常退到其他银行卡(发起异常退款成功后返回)


user_received_account  必填 string(64)

【退款入账账户】 取当前退款单的退款入账方,有以下几种情况:
1)退回银行卡:{银行名称}{卡类型}{卡尾号}
2)退回支付用户零钱:支付用户零钱
3)退还商户:商户基本账户商户结算银行账户
4)退回支付用户零钱通:支付用户零钱通
5)退回支付用户银行电子账户:支付用户银行电子账户
6)退回支付用户零花钱:支付用户零花钱
7)退回用户经营账户:用户经营账户
8)退回支付用户来华零钱包:支付用户来华零钱包
9)退回企业支付商户:企业支付商户


success_time   选填 string(64)

【退款成功时间】

1、定义:退款成功的时间,该字段在退款状态status为SUCCESS(退款成功)时返回。

2、格式遵循rfc3339标准格式:yyyy-MM-DDTHH:mm:ss+TIMEZONEyyyy-MM-DD 表示年月日;T 字符用于分隔日期和时间部分;HH:mm:ss 表示具体的时分秒;TIMEZONE 表示时区(例如,+08:00 对应东八区时间,即北京时间)。

示例:2015-05-20T13:29:35+08:00 表示北京时间2015年5月20日13点29分35秒。


create_time  必填 string(64)

【退款创建时间】

1、定义:提交退款申请成功,微信受理退款申请单的时间。

2、格式遵循rfc3339标准格式:yyyy-MM-DDTHH:mm:ss+TIMEZONEyyyy-MM-DD 表示年月日;T 字符用于分隔日期和时间部分;HH:mm:ss 表示具体的时分秒;TIMEZONE 表示时区(例如,+08:00 对应东八区时间,即北京时间)。

示例:2015-05-20T13:29:35+08:00 表示北京时间2015年5月20日13点29分35秒。


status  必填 string

【退款状态】退款单的退款处理状态。

  • SUCCESS: 退款成功

  • CLOSED: 退款关闭

  • PROCESSING: 退款处理中

  • ABNORMAL: 退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台-交易中心,手动处理此笔退款,可参考: 退款异常的处理,或者通过发起异常退款接口进行处理。
    注:状态流转说明请参考状态流转图


funds_account  必填 string

【资金账户】 退款所使用资金对应的资金账户类型

  • UNSETTLED: 未结算资金

  • AVAILABLE: 可用余额

  • UNAVAILABLE: 不可用余额

  • OPERATION: 运营账户

  • BASIC: 基本账户(含可用余额和不可用余额)

  • ECNY_BASIC: 数字人民币基本账户


amount  必填 object

【金额信息】订单退款金额信息

属性

promotion_detail   选填 array[object]

【优惠退款详情】 订单各个代金券的退款详情,订单使用了代金券且代金券发生退款时返回。

属性

应答示例

200 OK

1{
2  "refund_id" : "50000000382019052709732678859",
3  "out_refund_no" : "1217752501201407033233368018",
4  "transaction_id" : "1217752501201407033233368018",
5  "out_trade_no" : "1217752501201407033233368018",
6  "channel" : "ORIGINAL",
7  "user_received_account" : "招商银行信用卡0403",
8  "success_time" : "2020-12-01T16:18:12+08:00",
9  "create_time" : "2020-12-01T16:18:12+08:00",
10  "status" : "SUCCESS",
11  "funds_account" : "UNSETTLED",
12  "amount" : {
13    "total" : 100,
14    "refund" : 100,
15    "from" : [
16      {
17        "account" : "AVAILABLE",
18        "amount" : 444
19      }
20    ],
21    "payer_total" : 90,
22    "payer_refund" : 90,
23    "settlement_refund" : 100,
24    "settlement_total" : 100,
25    "discount_refund" : 10,
26    "currency" : "CNY",
27    "refund_fee" : 100
28  },
29  "promotion_detail" : [
30    {
31      "promotion_id" : "109519",
32      "scope" : "GLOBAL",
33      "type" : "COUPON",
34      "amount" : 5,
35      "refund_amount" : 100,
36      "goods_detail" : [
37        {
38          "merchant_goods_id" : "1217752501201407033233368018",
39          "wechatpay_goods_id" : "1001",
40          "goods_name" : "iPhone6s 16G",
41          "unit_price" : 528800,
42          "refund_amount" : 528800,
43          "refund_quantity" : 1
44        }
45      ]
46    }
47  ]
48}

错误码

公共错误码

状态码

错误码

描述

解决方案

400

PARAM_ERROR

参数错误

请根据错误提示正确传入参数

400

INVALID_REQUEST

HTTP 请求不符合微信支付 APIv3 接口规则

请参阅 接口规则

401

SIGN_ERROR

验证不通过

请参阅 签名常见问题

500

SYSTEM_ERROR

系统异常,请稍后重试

请稍后重试

业务错误码

状态码

错误码

描述

解决方案

400

INVALID_REQUEST

请求参数符合参数格式,但不符合业务规则

此状态代表退款申请失败,商户可根据具体的错误提示做相应的处理。

401

SIGN_ERROR

签名错误

请检查签名参数和方法是否都符合签名算法要求,参考:如何生成签名

403

NOT_ENOUGH

余额不足

此状态代表退款申请失败,商户账户余额不足。

403

USER_ACCOUNT_ABNORMAL

退款请求失败

此状态代表退款申请失败,商户可自行处理退款。

404

MCH_NOT_EXISTS

MCHID不存在

请检查商户号是否正确,商户号获取方式请参考普通商户模式开发必要参数说明

404

RESOURCE_NOT_EXISTS

订单号不存在

请检查你的订单号是否正确且是否已支付,未支付的订单不能发起退款

429

FREQUENCY_LIMITED

频率限制

该笔退款未受理,请降低频率后重试

500

SYSTEM_ERROR

系统超时

请不要更换商户退款单号,请使用相同参数再次调用API。

 

 

反馈
咨询
目录
置顶