预约还款
更新时间:2025.12.05商户在发起还款前,需要调用该接口进行预约还款
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/credit-repayment/partner/schedule-records/batch-create
请求域名:【主域名】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 包体参数
contract_id 必填 string(64)
【还款协议ID】 商户与用户签约成功后得到的还款协议ID
appid 必填 string(32)
【商户AppID】 商户在微信申请的公众号或移动应用AppID,与服务商商户号绑定。可参考服务商模式开发必要参数说明
openid 必填 string
【用户标识】 用户在商户AppID下的唯一标识,获取方式可参考OpenID获取
schedule_items 必填 array[object]
【预约还款项列表】 本次预约还款项的列表;当前只支持传入1个预约还款项
| 属性 | |
out_record_id 必填 string(32) 【商户侧预约还款记录ID】 商户系统的预约还款记录ID,只能是数字、大小写字母。需要保证在同一个商户号下唯一 sub_mchid 必填 string(32) 【子商户号】 微信支付分配的商户号,服务商商户号与子商户号存在父子关系 sub_appid 选填 string 【子商户AppID】 与子商户号绑定的AppID。可参考服务商模式开发必要参数说明 repayment_amount 必填 string 【应还款金额】 单位:分。不能超过在商户平台申请的模板中设置的每次还款金额上限,以及与用户签约成功的还款协议中设置的还款金额上限 min_repayment_amount 选填 string 【最低还款金额】 单位:分。如果与用户签约成功的还款协议归属于消费贷模板,则必填且需要大于等于应还款金额的5%。如果与用户签约成功的还款协议归属于现金贷模板,则可以不填;如果填,则需要大于等于应还款金额的10% repayment_date 必填 string 【还款日期】 本次还款的日期;取值只能在以下范围从本次预约日+1天开始,到本次预约日+15天(不包括这天)为止。格式遵循rfc3339标准格式,格式为yyyy-MM-DD,yyyy-MM-DD表示年月日,例如:2015-05-20表示,北京时间2015年5月20日。 |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/credit-repayment/partner/schedule-records/batch-create \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "contract_id" : "20251105000000123456789", 8 "appid" : "wxcbda96de0b165486", 9 "openid" : "oUpF8uMuAJO_M2pxb1Q9zNjWeS6o", 10 "schedule_items" : [ 11 { 12 "out_record_id" : "1234567abcde", 13 "sub_mchid" : "1900000109", 14 "sub_appid" : "wxcbda96de0b165489", 15 "repayment_amount" : "10000", 16 "min_repayment_amount" : "2000", 17 "repayment_date" : "2025-11-18" 18 } 19 ] 20 }' 21
需配合微信支付工具库 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 PartnerBatchCreateScheduleRecord { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/credit-repayment/partner/schedule-records/batch-create"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 PartnerBatchCreateScheduleRecord client = new PartnerBatchCreateScheduleRecord( 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 BatchCreateScheduleRecordRequest request = new BatchCreateScheduleRecordRequest(); 41 request.contractId = "20251105000000123456789"; 42 request.appid = "wxcbda96de0b165486"; 43 request.openid = "oUpF8uMuAJO_M2pxb1Q9zNjWeS6o"; 44 request.scheduleItems = new ArrayList<>(); 45 { 46 ScheduleItem scheduleItemsItem = new ScheduleItem(); 47 scheduleItemsItem.outRecordId = "1234567abcde"; 48 scheduleItemsItem.subMchid = "1900000109"; 49 scheduleItemsItem.subAppid = "wxcbda96de0b165489"; 50 scheduleItemsItem.repaymentAmount = "10000"; 51 scheduleItemsItem.minRepaymentAmount = "2000"; 52 scheduleItemsItem.repaymentDate = "2025-11-18"; 53 request.scheduleItems.add(scheduleItemsItem); 54 }; 55 try { 56 BatchCreateScheduleRecordResponse response = client.run(request); 57 // TODO: 请求成功,继续业务逻辑 58 System.out.println(response); 59 } catch (WXPayUtility.ApiException e) { 60 // TODO: 请求失败,根据状态码执行不同的逻辑 61 e.printStackTrace(); 62 } 63 } 64 65 public BatchCreateScheduleRecordResponse run(BatchCreateScheduleRecordRequest request) { 66 String uri = PATH; 67 String reqBody = WXPayUtility.toJson(request); 68 69 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 70 reqBuilder.addHeader("Accept", "application/json"); 71 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 72 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 73 reqBuilder.addHeader("Content-Type", "application/json"); 74 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 75 reqBuilder.method(METHOD, requestBody); 76 Request httpRequest = reqBuilder.build(); 77 78 // 发送HTTP请求 79 OkHttpClient client = new OkHttpClient.Builder().build(); 80 try (Response httpResponse = client.newCall(httpRequest).execute()) { 81 String respBody = WXPayUtility.extractBody(httpResponse); 82 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 83 // 2XX 成功,验证应答签名 84 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 85 httpResponse.headers(), respBody); 86 87 // 从HTTP应答报文构建返回数据 88 return WXPayUtility.fromJson(respBody, BatchCreateScheduleRecordResponse.class); 89 } else { 90 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 91 } 92 } catch (IOException e) { 93 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 94 } 95 } 96 97 private final String mchid; 98 private final String certificateSerialNo; 99 private final PrivateKey privateKey; 100 private final String wechatPayPublicKeyId; 101 private final PublicKey wechatPayPublicKey; 102 103 public PartnerBatchCreateScheduleRecord(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 104 this.mchid = mchid; 105 this.certificateSerialNo = certificateSerialNo; 106 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 107 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 108 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 109 } 110 111 public static class BatchCreateScheduleRecordRequest { 112 @SerializedName("contract_id") 113 public String contractId; 114 115 @SerializedName("appid") 116 public String appid; 117 118 @SerializedName("openid") 119 public String openid; 120 121 @SerializedName("schedule_items") 122 public List<ScheduleItem> scheduleItems = new ArrayList<ScheduleItem>(); 123 } 124 125 public static class BatchCreateScheduleRecordResponse { 126 @SerializedName("schedule_records") 127 public List<ScheduleRecord> scheduleRecords; 128 } 129 130 public static class ScheduleItem { 131 @SerializedName("out_record_id") 132 public String outRecordId; 133 134 @SerializedName("sub_mchid") 135 public String subMchid; 136 137 @SerializedName("sub_appid") 138 public String subAppid; 139 140 @SerializedName("repayment_amount") 141 public String repaymentAmount; 142 143 @SerializedName("min_repayment_amount") 144 public String minRepaymentAmount; 145 146 @SerializedName("repayment_date") 147 public String repaymentDate; 148 } 149 150 public static class ScheduleRecord { 151 @SerializedName("out_record_id") 152 public String outRecordId; 153 154 @SerializedName("appid") 155 public String appid; 156 157 @SerializedName("sub_appid") 158 public String subAppid; 159 160 @SerializedName("contract_id") 161 public String contractId; 162 163 @SerializedName("repayment_amount") 164 public String repaymentAmount; 165 166 @SerializedName("min_repayment_amount") 167 public String minRepaymentAmount; 168 169 @SerializedName("repayment_date") 170 public String repaymentDate; 171 172 @SerializedName("openid") 173 public String openid; 174 } 175 176} 177
需配合微信支付工具库 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) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &BatchCreateScheduleRecordRequest{ 27 ContractId: wxpay_utility.String("20251105000000123456789"), 28 Appid: wxpay_utility.String("wxcbda96de0b165486"), 29 Openid: wxpay_utility.String("oUpF8uMuAJO_M2pxb1Q9zNjWeS6o"), 30 ScheduleItems: []ScheduleItem{ScheduleItem{ 31 OutRecordId: wxpay_utility.String("1234567abcde"), 32 SubMchid: wxpay_utility.String("1900000109"), 33 SubAppid: wxpay_utility.String("wxcbda96de0b165489"), 34 RepaymentAmount: wxpay_utility.String("10000"), 35 MinRepaymentAmount: wxpay_utility.String("2000"), 36 RepaymentDate: wxpay_utility.String("2025-11-18"), 37 }}, 38 } 39 40 response, err := PartnerBatchCreateScheduleRecord(config, request) 41 if err != nil { 42 fmt.Printf("请求失败: %+v\n", err) 43 // TODO: 请求失败,根据状态码执行不同的处理 44 return 45 } 46 47 // TODO: 请求成功,继续业务逻辑 48 fmt.Printf("请求成功: %+v\n", response) 49} 50 51func PartnerBatchCreateScheduleRecord(config *wxpay_utility.MchConfig, request *BatchCreateScheduleRecordRequest) (response *BatchCreateScheduleRecordResponse, err error) { 52 const ( 53 host = "https://api.mch.weixin.qq.com" 54 method = "POST" 55 path = "/v3/credit-repayment/partner/schedule-records/batch-create" 56 ) 57 58 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 59 if err != nil { 60 return nil, err 61 } 62 reqBody, err := json.Marshal(request) 63 if err != nil { 64 return nil, err 65 } 66 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 67 if err != nil { 68 return nil, err 69 } 70 httpRequest.Header.Set("Accept", "application/json") 71 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 72 httpRequest.Header.Set("Content-Type", "application/json") 73 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 74 if err != nil { 75 return nil, err 76 } 77 httpRequest.Header.Set("Authorization", authorization) 78 79 client := &http.Client{} 80 httpResponse, err := client.Do(httpRequest) 81 if err != nil { 82 return nil, err 83 } 84 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 85 if err != nil { 86 return nil, err 87 } 88 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 89 // 2XX 成功,验证应答签名 90 err = wxpay_utility.ValidateResponse( 91 config.WechatPayPublicKeyId(), 92 config.WechatPayPublicKey(), 93 &httpResponse.Header, 94 respBody, 95 ) 96 if err != nil { 97 return nil, err 98 } 99 response := &BatchCreateScheduleRecordResponse{} 100 if err := json.Unmarshal(respBody, response); err != nil { 101 return nil, err 102 } 103 104 return response, nil 105 } else { 106 return nil, wxpay_utility.NewApiException( 107 httpResponse.StatusCode, 108 httpResponse.Header, 109 respBody, 110 ) 111 } 112} 113 114type BatchCreateScheduleRecordRequest struct { 115 ContractId *string `json:"contract_id,omitempty"` 116 Appid *string `json:"appid,omitempty"` 117 Openid *string `json:"openid,omitempty"` 118 ScheduleItems []ScheduleItem `json:"schedule_items,omitempty"` 119} 120 121type BatchCreateScheduleRecordResponse struct { 122 ScheduleRecords []ScheduleRecord `json:"schedule_records,omitempty"` 123} 124 125type ScheduleItem struct { 126 OutRecordId *string `json:"out_record_id,omitempty"` 127 SubMchid *string `json:"sub_mchid,omitempty"` 128 SubAppid *string `json:"sub_appid,omitempty"` 129 RepaymentAmount *string `json:"repayment_amount,omitempty"` 130 MinRepaymentAmount *string `json:"min_repayment_amount,omitempty"` 131 RepaymentDate *string `json:"repayment_date,omitempty"` 132} 133 134type ScheduleRecord struct { 135 OutRecordId *string `json:"out_record_id,omitempty"` 136 Appid *string `json:"appid,omitempty"` 137 SubAppid *string `json:"sub_appid,omitempty"` 138 ContractId *string `json:"contract_id,omitempty"` 139 RepaymentAmount *string `json:"repayment_amount,omitempty"` 140 MinRepaymentAmount *string `json:"min_repayment_amount,omitempty"` 141 RepaymentDate *string `json:"repayment_date,omitempty"` 142 Openid *string `json:"openid,omitempty"` 143} 144
应答参数
折叠全部参数
200 OK
schedule_records 选填 array[object]
【预约还款记录列表】 只返回预约成功的预约还款记录
| 属性 | |
out_record_id 必填 string(32) 【商户侧预约还款记录ID】 预约还款时传入的商户侧预约还款记录ID appid 必填 string(32) 【商户AppID】 商户在微信申请的公众号或移动应用AppID,与服务商商户号绑定。可参考服务商模式开发必要参数说明 sub_appid 选填 string(32) 【子商户AppID】 与子商户号绑定的AppID。可参考服务商模式开发必要参数说明 contract_id 必填 string(64) 【还款协议ID】 商户与用户签约的还款协议ID repayment_amount 必填 string 【应还款金额】 单位分 min_repayment_amount 必填 string 【最低还款金额】 单位分 repayment_date 必填 string 【还款日期】 本次还款的日期 openid 必填 string(128) 【用户标识】 用户在商户AppID下的唯一标识 |
应答示例
200 OK
1{ 2 "schedule_records" : [ 3 { 4 "out_record_id" : "1234567abcde", 5 "appid" : "wxcbda96de0b165486", 6 "sub_appid" : "wxcbda96de0b165489", 7 "contract_id" : "20251105000000123456789", 8 "repayment_amount" : "10000", 9 "min_repayment_amount" : "10000", 10 "repayment_date" : "2025-11-08", 11 "openid" : "oUpF8uMuAJO_M2pxb1Q9zNjWeS6o" 12 } 13 ] 14} 15
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示

