商户关单
更新时间:2025.05.29还款单支付订单只能使用此还款单关单api完成关单。
还款单支付关单接口不支持关闭部分还款单, 关单的还款单订单号、还款单发起商户号、还款明细单个数、还款明细单订单号、子商户号必须与下单时完全一致。
接口说明
支持商户:【平台商户】
请求方式:【POST】/v3/repayment/combine-transactions/partner/out-trade-no/{combine_out_trade_no}/close
请求域名:【主域名】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 路径参数
combine_out_trade_no 必填 string(32)
【还款单订单号】 还款下单时传入的还款商户订单号。
body 包体参数
sub_orders 必填 array[object]
【还款明细单信息列表】 还款下单传入的明细单信息列表
| 属性 | |
mchid 必填 string(32) 【还款单发起商户号】 还款下单时传入的服务商商户号 out_trade_no 必填 string(32) 【还款明细单订单号】 还款下单时传入的子单商户订单号。 sub_mchid 选填 string(32) 【子商户号(也叫特约商户号)】 还款下单时传入的子商户号。 |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/repayment/combine-transactions/partner/out-trade-no/1217752501201407033233368018/close \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "sub_orders" : [ 8 { 9 "mchid" : "1230000109", 10 "out_trade_no" : "20150806125346", 11 "sub_mchid" : "1900000109" 12 } 13 ] 14 }' 15
需配合微信支付工具库 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 RepaymentClose { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/repayment/combine-transactions/partner/out-trade-no/{combine_out_trade_no}/close"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 RepaymentClose client = new RepaymentClose( 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 RepaymentCloseRequest request = new RepaymentCloseRequest(); 41 request.combineOutTradeNo = "1217752501201407033233368018"; 42 request.subOrders = new ArrayList<>(); 43 { 44 RepaymentCloseSubOrder subOrdersItem = new RepaymentCloseSubOrder(); 45 subOrdersItem.mchid = "1230000109"; 46 subOrdersItem.outTradeNo = "20150806125346"; 47 subOrdersItem.subMchid = "1900000109"; 48 request.subOrders.add(subOrdersItem); 49 }; 50 try { 51 client.run(request); 52 } catch (WXPayUtility.ApiException e) { 53 // TODO: 请求失败,根据状态码执行不同的逻辑 54 e.printStackTrace(); 55 } 56 } 57 58 public void run(RepaymentCloseRequest request) { 59 String uri = PATH; 60 uri = uri.replace("{combine_out_trade_no}", WXPayUtility.urlEncode(request.combineOutTradeNo)); 61 String reqBody = WXPayUtility.toJson(request); 62 63 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 64 reqBuilder.addHeader("Accept", "application/json"); 65 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 66 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 67 reqBuilder.addHeader("Content-Type", "application/json"); 68 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 69 reqBuilder.method(METHOD, requestBody); 70 Request httpRequest = reqBuilder.build(); 71 72 // 发送HTTP请求 73 OkHttpClient client = new OkHttpClient.Builder().build(); 74 try (Response httpResponse = client.newCall(httpRequest).execute()) { 75 String respBody = WXPayUtility.extractBody(httpResponse); 76 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 77 // 2XX 成功,验证应答签名 78 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 79 httpResponse.headers(), respBody); 80 81 return; 82 } else { 83 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 84 } 85 } catch (IOException e) { 86 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 87 } 88 } 89 90 private final String mchid; 91 private final String certificateSerialNo; 92 private final PrivateKey privateKey; 93 private final String wechatPayPublicKeyId; 94 private final PublicKey wechatPayPublicKey; 95 96 public RepaymentClose(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 97 this.mchid = mchid; 98 this.certificateSerialNo = certificateSerialNo; 99 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 100 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 101 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 102 } 103 104 public static class RepaymentCloseRequest { 105 @SerializedName("combine_out_trade_no") 106 @Expose(serialize = false) 107 public String combineOutTradeNo; 108 109 @SerializedName("sub_orders") 110 public List<RepaymentCloseSubOrder> subOrders = new ArrayList<RepaymentCloseSubOrder>(); 111 } 112 113 public static class RepaymentCloseSubOrder { 114 @SerializedName("mchid") 115 public String mchid; 116 117 @SerializedName("out_trade_no") 118 public String outTradeNo; 119 120 @SerializedName("sub_mchid") 121 public String subMchid; 122 } 123 124} 125
需配合微信支付工具库 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) 12 13func main() { 14 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 15 config, err := wxpay_utility.CreateMchConfig( 16 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 17 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 18 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 19 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 20 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 21 ) 22 if err != nil { 23 fmt.Println(err) 24 return 25 } 26 27 request := &RepaymentCloseRequest{ 28 CombineOutTradeNo: wxpay_utility.String("1217752501201407033233368018"), 29 SubOrders: []RepaymentCloseSubOrder{RepaymentCloseSubOrder{ 30 Mchid: wxpay_utility.String("1230000109"), 31 OutTradeNo: wxpay_utility.String("20150806125346"), 32 SubMchid: wxpay_utility.String("1900000109"), 33 }}, 34 } 35 36 err = RepaymentClose(config, request) 37 if err != nil { 38 fmt.Printf("请求失败: %+v\n", err) 39 // TODO: 请求失败,根据状态码执行不同的处理 40 return 41 } 42 43 // TODO: 请求成功,继续业务逻辑 44 fmt.Println("请求成功") 45} 46 47func RepaymentClose(config *wxpay_utility.MchConfig, request *RepaymentCloseRequest) (err error) { 48 const ( 49 host = "https://api.mch.weixin.qq.com" 50 method = "POST" 51 path = "/v3/repayment/combine-transactions/partner/out-trade-no/{combine_out_trade_no}/close" 52 ) 53 54 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 55 if err != nil { 56 return err 57 } 58 reqUrl.Path = strings.Replace(reqUrl.Path, "{combine_out_trade_no}", url.PathEscape(*request.CombineOutTradeNo), -1) 59 reqBody, err := json.Marshal(request) 60 if err != nil { 61 return err 62 } 63 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 64 if err != nil { 65 return err 66 } 67 httpRequest.Header.Set("Accept", "application/json") 68 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 69 httpRequest.Header.Set("Content-Type", "application/json") 70 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 71 if err != nil { 72 return err 73 } 74 httpRequest.Header.Set("Authorization", authorization) 75 76 client := &http.Client{} 77 httpResponse, err := client.Do(httpRequest) 78 if err != nil { 79 return err 80 } 81 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 82 if err != nil { 83 return err 84 } 85 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 86 // 2XX 成功,验证应答签名 87 err = wxpay_utility.ValidateResponse( 88 config.WechatPayPublicKeyId(), 89 config.WechatPayPublicKey(), 90 &httpResponse.Header, 91 respBody, 92 ) 93 if err != nil { 94 return err 95 } 96 return nil 97 } else { 98 return wxpay_utility.NewApiException( 99 httpResponse.StatusCode, 100 httpResponse.Header, 101 respBody, 102 ) 103 } 104} 105 106type RepaymentCloseRequest struct { 107 CombineOutTradeNo *string `json:"combine_out_trade_no,omitempty"` 108 SubOrders []RepaymentCloseSubOrder `json:"sub_orders,omitempty"` 109} 110 111func (o *RepaymentCloseRequest) MarshalJSON() ([]byte, error) { 112 type Alias RepaymentCloseRequest 113 a := &struct { 114 CombineOutTradeNo *string `json:"combine_out_trade_no,omitempty"` 115 *Alias 116 }{ 117 // 序列化时移除非 Body 字段 118 CombineOutTradeNo: nil, 119 Alias: (*Alias)(o), 120 } 121 return json.Marshal(a) 122} 123 124type RepaymentCloseSubOrder struct { 125 Mchid *string `json:"mchid,omitempty"` 126 OutTradeNo *string `json:"out_trade_no,omitempty"` 127 SubMchid *string `json:"sub_mchid,omitempty"` 128} 129
应答参数
无应答包体
应答示例
204 No Content
1'无应答包体' 2
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
