撤销转账
更新时间:2025.07.29商户通过转账接口发起付款后,在用户确认收款之前可以通过该接口撤销付款。该接口返回成功仅表示撤销请求已受理,系统会异步处理退款等操作,以最终查询单据返回状态为准。
注:单个商户的接口频率限制为100次/s
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/fund-app/mch-transfer/partner/transfer-bills/out-bill-no/{out_bill_no}/cancel
请求域名:【主域名】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
path 路径参数
out_bill_no 必填 string(32)
【商户单号】 商户系统内部的商家单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一
body 包体参数
sub_mchid 必填 string(32)
【子商户号】 微信支付分配的商户号,出资商户号
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/partner/transfer-bills/out-bill-no/plfk2020042013/cancel \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "sub_mchid" : "1900001109" 8 }' 9
需配合微信支付工具库 WXPayUtility 使用,请参考Java
1package com.java.demo; 2 3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/partner/4014985777 4 5import com.google.gson.annotations.SerializedName; 6import com.google.gson.annotations.Expose; 7import okhttp3.MediaType; 8import okhttp3.OkHttpClient; 9import okhttp3.Request; 10import okhttp3.RequestBody; 11import okhttp3.Response; 12 13import java.io.IOException; 14import java.io.UncheckedIOException; 15import java.security.PrivateKey; 16import java.security.PublicKey; 17import java.util.ArrayList; 18import java.util.HashMap; 19import java.util.List; 20import java.util.Map; 21 22/** 23 * 撤销转账 24 */ 25public class TransferBillCancel { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/fund-app/mch-transfer/partner/transfer-bills/out-bill-no/{out_bill_no}/cancel"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 TransferBillCancel client = new TransferBillCancel( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 TransferBillCancelRequest request = new TransferBillCancelRequest(); 41 request.outBillNo = "plfk2020042013"; 42 request.subMchid = "1900001109"; 43 try { 44 TransferBillEntity response = client.run(request); 45 // TODO: 请求成功,继续业务逻辑 46 System.out.println(response); 47 } catch (WXPayUtility.ApiException e) { 48 // TODO: 请求失败,根据状态码执行不同的逻辑 49 e.printStackTrace(); 50 } 51 } 52 53 public TransferBillEntity run(TransferBillCancelRequest request) { 54 String uri = PATH; 55 uri = uri.replace("{out_bill_no}", WXPayUtility.urlEncode(request.outBillNo)); 56 String reqBody = WXPayUtility.toJson(request); 57 58 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 59 reqBuilder.addHeader("Accept", "application/json"); 60 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 61 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 62 reqBuilder.addHeader("Content-Type", "application/json"); 63 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 64 reqBuilder.method(METHOD, requestBody); 65 Request httpRequest = reqBuilder.build(); 66 67 // 发送HTTP请求 68 OkHttpClient client = new OkHttpClient.Builder().build(); 69 try (Response httpResponse = client.newCall(httpRequest).execute()) { 70 String respBody = WXPayUtility.extractBody(httpResponse); 71 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 72 // 2XX 成功,验证应答签名 73 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 74 httpResponse.headers(), respBody); 75 76 // 从HTTP应答报文构建返回数据 77 return WXPayUtility.fromJson(respBody, TransferBillEntity.class); 78 } else { 79 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 80 } 81 } catch (IOException e) { 82 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 83 } 84 } 85 86 private final String mchid; 87 private final String certificateSerialNo; 88 private final PrivateKey privateKey; 89 private final String wechatPayPublicKeyId; 90 private final PublicKey wechatPayPublicKey; 91 92 public TransferBillCancel(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 93 this.mchid = mchid; 94 this.certificateSerialNo = certificateSerialNo; 95 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 96 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 97 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 98 } 99 100 public static class TransferBillCancelRequest { 101 @SerializedName("sub_mchid") 102 public String subMchid; 103 104 @SerializedName("out_bill_no") 105 @Expose(serialize = false) 106 public String outBillNo; 107 } 108 109 public static class TransferBillEntity { 110 @SerializedName("sub_mchid") 111 public String subMchid; 112 113 @SerializedName("mchid") 114 public String mchid; 115 116 @SerializedName("out_bill_no") 117 public String outBillNo; 118 119 @SerializedName("transfer_bill_no") 120 public String transferBillNo; 121 122 @SerializedName("appid") 123 public String appid; 124 125 @SerializedName("state") 126 public TransferBillStatus state; 127 128 @SerializedName("transfer_amount") 129 public Long transferAmount; 130 131 @SerializedName("transfer_remark") 132 public String transferRemark; 133 134 @SerializedName("fail_reason") 135 public String failReason; 136 137 @SerializedName("openid") 138 public String openid; 139 140 @SerializedName("user_name") 141 public String userName; 142 143 @SerializedName("create_time") 144 public String createTime; 145 146 @SerializedName("update_time") 147 public String updateTime; 148 } 149 150 public enum TransferBillStatus { 151 @SerializedName("ACCEPTED") 152 ACCEPTED, 153 @SerializedName("PROCESSING") 154 PROCESSING, 155 @SerializedName("WAIT_USER_CONFIRM") 156 WAIT_USER_CONFIRM, 157 @SerializedName("TRANSFERING") 158 TRANSFERING, 159 @SerializedName("SUCCESS") 160 SUCCESS, 161 @SerializedName("FAIL") 162 FAIL, 163 @SerializedName("CANCELING") 164 CANCELING, 165 @SerializedName("CANCELLED") 166 CANCELLED 167 } 168 169} 170
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 10 "strings" 11 "time" 12) 13 14func main() { 15 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 config, err := wxpay_utility.CreateMchConfig( 17 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 18 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 19 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 20 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 21 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 22 ) 23 if err != nil { 24 fmt.Println(err) 25 return 26 } 27 28 request := &TransferBillCancelRequest{ 29 OutBillNo: wxpay_utility.String("plfk2020042013"), 30 SubMchid: wxpay_utility.String("1900001109"), 31 } 32 33 response, err := TransferBillCancel(config, request) 34 if err != nil { 35 fmt.Printf("请求失败: %+v\n", err) 36 // TODO: 请求失败,根据状态码执行不同的处理 37 return 38 } 39 40 // TODO: 请求成功,继续业务逻辑 41 fmt.Printf("请求成功: %+v\n", response) 42} 43 44func TransferBillCancel(config *wxpay_utility.MchConfig, request *TransferBillCancelRequest) (response *TransferBillEntity, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "POST" 48 path = "/v3/fund-app/mch-transfer/partner/transfer-bills/out-bill-no/{out_bill_no}/cancel" 49 ) 50 51 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 52 if err != nil { 53 return nil, err 54 } 55 reqUrl.Path = strings.Replace(reqUrl.Path, "{out_bill_no}", url.PathEscape(*request.OutBillNo), -1) 56 reqBody, err := json.Marshal(request) 57 if err != nil { 58 return nil, err 59 } 60 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 61 if err != nil { 62 return nil, err 63 } 64 httpRequest.Header.Set("Accept", "application/json") 65 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 66 httpRequest.Header.Set("Content-Type", "application/json") 67 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 68 if err != nil { 69 return nil, err 70 } 71 httpRequest.Header.Set("Authorization", authorization) 72 73 client := &http.Client{} 74 httpResponse, err := client.Do(httpRequest) 75 if err != nil { 76 return nil, err 77 } 78 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 79 if err != nil { 80 return nil, err 81 } 82 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 83 // 2XX 成功,验证应答签名 84 err = wxpay_utility.ValidateResponse( 85 config.WechatPayPublicKeyId(), 86 config.WechatPayPublicKey(), 87 &httpResponse.Header, 88 respBody, 89 ) 90 if err != nil { 91 return nil, err 92 } 93 response := &TransferBillEntity{} 94 if err := json.Unmarshal(respBody, response); err != nil { 95 return nil, err 96 } 97 98 return response, nil 99 } else { 100 return nil, wxpay_utility.NewApiException( 101 httpResponse.StatusCode, 102 httpResponse.Header, 103 respBody, 104 ) 105 } 106} 107 108type TransferBillCancelRequest struct { 109 SubMchid *string `json:"sub_mchid,omitempty"` 110 OutBillNo *string `json:"out_bill_no,omitempty"` 111} 112 113func (o *TransferBillCancelRequest) MarshalJSON() ([]byte, error) { 114 type Alias TransferBillCancelRequest 115 a := &struct { 116 OutBillNo *string `json:"out_bill_no,omitempty"` 117 *Alias 118 }{ 119 // 序列化时移除非 Body 字段 120 OutBillNo: nil, 121 Alias: (*Alias)(o), 122 } 123 return json.Marshal(a) 124} 125 126type TransferBillEntity struct { 127 SubMchid *string `json:"sub_mchid,omitempty"` 128 Mchid *string `json:"mchid,omitempty"` 129 OutBillNo *string `json:"out_bill_no,omitempty"` 130 TransferBillNo *string `json:"transfer_bill_no,omitempty"` 131 Appid *string `json:"appid,omitempty"` 132 State *TransferBillStatus `json:"state,omitempty"` 133 TransferAmount *int64 `json:"transfer_amount,omitempty"` 134 TransferRemark *string `json:"transfer_remark,omitempty"` 135 FailReason *string `json:"fail_reason,omitempty"` 136 Openid *string `json:"openid,omitempty"` 137 UserName *string `json:"user_name,omitempty"` 138 CreateTime *time.Time `json:"create_time,omitempty"` 139 UpdateTime *string `json:"update_time,omitempty"` 140} 141 142type TransferBillStatus string 143 144func (e TransferBillStatus) Ptr() *TransferBillStatus { 145 return &e 146} 147 148const ( 149 TRANSFERBILLSTATUS_ACCEPTED TransferBillStatus = "ACCEPTED" 150 TRANSFERBILLSTATUS_PROCESSING TransferBillStatus = "PROCESSING" 151 TRANSFERBILLSTATUS_WAIT_USER_CONFIRM TransferBillStatus = "WAIT_USER_CONFIRM" 152 TRANSFERBILLSTATUS_TRANSFERING TransferBillStatus = "TRANSFERING" 153 TRANSFERBILLSTATUS_SUCCESS TransferBillStatus = "SUCCESS" 154 TRANSFERBILLSTATUS_FAIL TransferBillStatus = "FAIL" 155 TRANSFERBILLSTATUS_CANCELING TransferBillStatus = "CANCELING" 156 TRANSFERBILLSTATUS_CANCELLED TransferBillStatus = "CANCELLED" 157) 158
应答参数
200 OK
sub_mchid 必填 string(32)
【子商户】 微信支付分配的商户号,出资商户号
mchid 必填 string(32)
【商户号】 微信支付分配的商户号
out_bill_no 必填 string(32)
【商户单号】 商户系统内部的商家单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一
transfer_bill_no 必填 string(64)
【商家转账订单号】 商家转账订单的主键,唯一定义此资源的标识
appid 必填 string(32)
【商户AppID】 申请商户号的AppID或商户号绑定的AppID(企业号corpid即为此AppID)
state 必填 string
【单据状态】
可选取值
ACCEPTED: 转账已受理PROCESSING: 转账处理中,转账结果尚未明确,如一直处于此状态,建议检查账户余额是否足够WAIT_USER_CONFIRM: 待收款用户确认,可拉起微信收款确认页面进行收款确认TRANSFERING: 转账结果尚未明确,可拉起微信收款确认页面再次重试确认收款SUCCESS: 转账成功FAIL: 转账失败CANCELING: 商户撤销请求受理成功,该笔转账正在撤销中CANCELLED: 转账撤销完成
transfer_amount 必填 integer
【转账金额】 转账金额单位为“分”。
transfer_remark 必填 string(32)
【转账备注】 单条转账备注(微信用户会收到该备注),UTF8编码,最多允许32个字符
fail_reason 选填 string(64)
【失败原因】 订单已失败或者已退资金时,返回 订单失败原因
openid 选填 string(64)
【收款用户OpenID】 商户AppID下,某用户的OpenID
user_name 选填 string
【收款用户姓名】 收款方真实姓名。支持标准RSA算法和国密算法,公钥由微信侧提供转账金额 >= 2,000元时,该笔明细必须填写若商户传入收款用户姓名,微信支付会校验用户OpenID与姓名是否一致,并提供电子回单
create_time 必填 string(32)
【单据创建时间】 单据受理成功时返回,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE
update_time 必填 string(32)
【最后一次状态变更时间】 单据最后更新时间,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE
应答示例
200 OK
1{ 2 "sub_mchid" : "1900001109", 3 "mchid" : "1900001109", 4 "out_bill_no" : "plfk2020042013", 5 "transfer_bill_no" : "1330000071100999991182020050700019480001", 6 "appid" : "wxf636efh567hg4356", 7 "state" : "SUCCESS", 8 "transfer_amount" : 400000, 9 "transfer_remark" : "2020年4月报销", 10 "fail_reason" : "PAYEE_ACCOUNT_ABNORMAL", 11 "openid" : "o-MYE42l80oelYMDE34nYD456Xoy", 12 "user_name" : "757b340b45ebef5467rter35gf464344v3542sdf4t6re4tb4f54ty45t4yyry45", 13 "create_time" : "2025-11-30T10:20:58+08:00", 14 "update_time" : "2015-04-21T13:31:35+08:00" 15} 16
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示

