申请二级商户充值
更新时间:2025.07.29商户系统须通过调用此接口获取充值链接,随后发起充值流程。
使用注意:
1、指定充值渠道后,部分商户仍可能因微信支付暂不支持导致无法使用该支付方式。(比如小微商户暂不支持网银和转账汇款)
2、充值链接有效期为7天。过期未支付,系统将自动关单
接口说明
支持商户:【平台商户】
请求方式:【POST】/v3/platsolution/ecommerce/recharges/apply
请求域名:【主域名】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 包体参数
sub_mchid 必填 string(32)
【二级商户号】 微信支付分配的商户号,出资商户号
out_recharge_no 必填 string(64)
【商户充值单号】 商户系统内部的充值单号,只能由数字、大小写字母组成,在平台商户系统内部唯一
recharge_scene 必填 string
【充值场景】 按照实际情况填写
可选取值
ECOMMERCE_DEPOSIT: 二级商户充值保证金ECOMMERCE_PAYMENT: 二级商户充值运营资金
account_type 必填 string
【充值入账账户】 使用充值场景所支持的入账账户
可选取值
DEPOSIT: 保证金账户OPERATION: 运营账户
recharge_amount 必填 object
【充值金额】 单位为分,仅支持CNY
| 属性 | |
amount 选填 integer 【总金额】 单位为分 currency 选填 string(16) 【货币类型】 人民币为CNY |
notify_url 选填 string(1024)
【商户回调地址】 异步接收充值结果的回调地址
available_recharge_channels 选填 array[string]
【可用充值渠道列表】 缺省展示全部充值渠道。若传入可用渠道列表,以传入内容为准
可选取值
BANK_TRANSFER: 银行转账QR_RECHARGE: 扫码充值ONLINE_BANK: 网银充值
remark 选填 string(20)
【充值备注】 将在充值页面展示。UTF8编码,最多允许20个字符
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/platsolution/ecommerce/recharges/apply \ 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 "out_recharge_no" : "cz202407181234", 9 "recharge_scene" : "ECOMMERCE_DEPOSIT", 10 "account_type" : "DEPOSIT", 11 "recharge_amount" : { 12 "amount" : 500000, 13 "currency" : "CNY" 14 }, 15 "notify_url" : "https://www.weixin.qq.com/wxpay/pay.php", 16 "available_recharge_channels" : [ 17 "BANK_TRANSFER" 18 ], 19 "remark" : "example_remark" 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 PlatSolutionApply { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/platsolution/ecommerce/recharges/apply"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 PlatSolutionApply client = new PlatSolutionApply( 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 RechargeApplyRequest request = new RechargeApplyRequest(); 41 request.subMchid = "1900001109"; 42 request.outRechargeNo = "cz202407181234"; 43 request.rechargeScene = RechargeScene.ECOMMERCE_DEPOSIT; 44 request.accountType = AccountType.DEPOSIT; 45 request.rechargeAmount = new RechargeAmount(); 46 request.rechargeAmount.amount = 500000L; 47 request.rechargeAmount.currency = "CNY"; 48 request.notifyUrl = "https://www.weixin.qq.com/wxpay/pay.php"; 49 request.availableRechargeChannels = new ArrayList<>(); 50 { 51 request.availableRechargeChannels.add(RechargeChannel.BANK_TRANSFER); 52 }; 53 request.remark = "example_remark"; 54 try { 55 RechargeApplyResponse response = client.run(request); 56 // TODO: 请求成功,继续业务逻辑 57 System.out.println(response); 58 } catch (WXPayUtility.ApiException e) { 59 // TODO: 请求失败,根据状态码执行不同的逻辑 60 e.printStackTrace(); 61 } 62 } 63 64 public RechargeApplyResponse run(RechargeApplyRequest request) { 65 String uri = PATH; 66 String reqBody = WXPayUtility.toJson(request); 67 68 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 69 reqBuilder.addHeader("Accept", "application/json"); 70 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 71 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 72 reqBuilder.addHeader("Content-Type", "application/json"); 73 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 74 reqBuilder.method(METHOD, requestBody); 75 Request httpRequest = reqBuilder.build(); 76 77 // 发送HTTP请求 78 OkHttpClient client = new OkHttpClient.Builder().build(); 79 try (Response httpResponse = client.newCall(httpRequest).execute()) { 80 String respBody = WXPayUtility.extractBody(httpResponse); 81 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 82 // 2XX 成功,验证应答签名 83 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 84 httpResponse.headers(), respBody); 85 86 // 从HTTP应答报文构建返回数据 87 return WXPayUtility.fromJson(respBody, RechargeApplyResponse.class); 88 } else { 89 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 90 } 91 } catch (IOException e) { 92 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 93 } 94 } 95 96 private final String mchid; 97 private final String certificateSerialNo; 98 private final PrivateKey privateKey; 99 private final String wechatPayPublicKeyId; 100 private final PublicKey wechatPayPublicKey; 101 102 public PlatSolutionApply(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 103 this.mchid = mchid; 104 this.certificateSerialNo = certificateSerialNo; 105 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 106 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 107 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 108 } 109 110 public static class RechargeApplyRequest { 111 @SerializedName("sub_mchid") 112 public String subMchid; 113 114 @SerializedName("out_recharge_no") 115 public String outRechargeNo; 116 117 @SerializedName("recharge_scene") 118 public RechargeScene rechargeScene; 119 120 @SerializedName("account_type") 121 public AccountType accountType; 122 123 @SerializedName("recharge_amount") 124 public RechargeAmount rechargeAmount; 125 126 @SerializedName("notify_url") 127 public String notifyUrl; 128 129 @SerializedName("available_recharge_channels") 130 public List<RechargeChannel> availableRechargeChannels; 131 132 @SerializedName("remark") 133 public String remark; 134 } 135 136 public static class RechargeApplyResponse { 137 @SerializedName("recharge_id") 138 public String rechargeId; 139 140 @SerializedName("out_recharge_no") 141 public String outRechargeNo; 142 143 @SerializedName("recharge_url") 144 public String rechargeUrl; 145 146 @SerializedName("package_info") 147 public String packageInfo; 148 } 149 150 public enum RechargeScene { 151 @SerializedName("ECOMMERCE_DEPOSIT") 152 ECOMMERCE_DEPOSIT, 153 @SerializedName("ECOMMERCE_PAYMENT") 154 ECOMMERCE_PAYMENT 155 } 156 157 public enum AccountType { 158 @SerializedName("DEPOSIT") 159 DEPOSIT, 160 @SerializedName("OPERATION") 161 OPERATION 162 } 163 164 public static class RechargeAmount { 165 @SerializedName("amount") 166 public Long amount; 167 168 @SerializedName("currency") 169 public String currency; 170 } 171 172 public enum RechargeChannel { 173 @SerializedName("BANK_TRANSFER") 174 BANK_TRANSFER, 175 @SerializedName("QR_RECHARGE") 176 QR_RECHARGE, 177 @SerializedName("ONLINE_BANK") 178 ONLINE_BANK 179 } 180 181} 182
需配合微信支付工具库 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 := &RechargeApplyRequest{ 27 SubMchid: wxpay_utility.String("1900001109"), 28 OutRechargeNo: wxpay_utility.String("cz202407181234"), 29 RechargeScene: RECHARGESCENE_ECOMMERCE_DEPOSIT.Ptr(), 30 AccountType: ACCOUNTTYPE_DEPOSIT.Ptr(), 31 RechargeAmount: &RechargeAmount{ 32 Amount: wxpay_utility.Int64(500000), 33 Currency: wxpay_utility.String("CNY"), 34 }, 35 NotifyUrl: wxpay_utility.String("https://www.weixin.qq.com/wxpay/pay.php"), 36 AvailableRechargeChannels: []RechargeChannel{RECHARGECHANNEL_BANK_TRANSFER}, 37 Remark: wxpay_utility.String("example_remark"), 38 } 39 40 response, err := PlatSolutionApply(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 PlatSolutionApply(config *wxpay_utility.MchConfig, request *RechargeApplyRequest) (response *RechargeApplyResponse, err error) { 52 const ( 53 host = "https://api.mch.weixin.qq.com" 54 method = "POST" 55 path = "/v3/platsolution/ecommerce/recharges/apply" 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 := &RechargeApplyResponse{} 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 RechargeApplyRequest struct { 115 SubMchid *string `json:"sub_mchid,omitempty"` 116 OutRechargeNo *string `json:"out_recharge_no,omitempty"` 117 RechargeScene *RechargeScene `json:"recharge_scene,omitempty"` 118 AccountType *AccountType `json:"account_type,omitempty"` 119 RechargeAmount *RechargeAmount `json:"recharge_amount,omitempty"` 120 NotifyUrl *string `json:"notify_url,omitempty"` 121 AvailableRechargeChannels []RechargeChannel `json:"available_recharge_channels,omitempty"` 122 Remark *string `json:"remark,omitempty"` 123} 124 125type RechargeApplyResponse struct { 126 RechargeId *string `json:"recharge_id,omitempty"` 127 OutRechargeNo *string `json:"out_recharge_no,omitempty"` 128 RechargeUrl *string `json:"recharge_url,omitempty"` 129 PackageInfo *string `json:"package_info,omitempty"` 130} 131 132type RechargeScene string 133 134func (e RechargeScene) Ptr() *RechargeScene { 135 return &e 136} 137 138const ( 139 RECHARGESCENE_ECOMMERCE_DEPOSIT RechargeScene = "ECOMMERCE_DEPOSIT" 140 RECHARGESCENE_ECOMMERCE_PAYMENT RechargeScene = "ECOMMERCE_PAYMENT" 141) 142 143type AccountType string 144 145func (e AccountType) Ptr() *AccountType { 146 return &e 147} 148 149const ( 150 ACCOUNTTYPE_DEPOSIT AccountType = "DEPOSIT" 151 ACCOUNTTYPE_OPERATION AccountType = "OPERATION" 152) 153 154type RechargeAmount struct { 155 Amount *int64 `json:"amount,omitempty"` 156 Currency *string `json:"currency,omitempty"` 157} 158 159type RechargeChannel string 160 161func (e RechargeChannel) Ptr() *RechargeChannel { 162 return &e 163} 164 165const ( 166 RECHARGECHANNEL_BANK_TRANSFER RechargeChannel = "BANK_TRANSFER" 167 RECHARGECHANNEL_QR_RECHARGE RechargeChannel = "QR_RECHARGE" 168 RECHARGECHANNEL_ONLINE_BANK RechargeChannel = "ONLINE_BANK" 169) 170
应答参数
200 OK
recharge_id 必填 string(27)
【微信支付充值单号】 微信支付充值单号
out_recharge_no 必填 string(64)
【商户充值单号】 商户系统内部的充值单号,只能由数字、大小写字母组成,在平台商户系统内部唯一
recharge_url 必填 string(2048)
【充值链接】 由链接进入充值页面
package_info 选填 string(1024)
【跳转充值到商户账户页面的package信息】 APP调起充值到商户账户 时需要使用的参数
应答示例
200 OK
1{ 2 "recharge_id" : "172207846292553701", 3 "out_recharge_no" : "cz202407181234", 4 "recharge_url" : "https://www.payapp.qq.com/plat/recharge.html", 5 "package_info" : "affffddafdfafddffda==" 6} 7
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
400 | INVALID_REQUEST | 入账账户不存在 | 二级子商户开通对应入账账户 |
400 | INVALID_REQUEST | 单笔充值金额超过上限 | 单笔充值金额小于等于2千万元 |
400 | INVALID_REQUEST | 该业务充值单号已存在 | 请核实商户充值单号是否重复 |
403 | NO_AUTH | 服务商未开通平台收付通 | 服务商开通微信支付平台收付通 |
403 | NO_AUTH | 平台充值权限被处罚,无法发起充值 | 服务商登录「合作伙伴平台-账户中心-违约记录」查看详情 |
403 | NO_AUTH | 商户号出入金权限被管控 | 二级子商户前往「微信支付商户平台-账户中心-违约记录」或「商家助手小程序-风险处理」查看详情 |
429 | FREQUENCY_LIMITED | 频率超限 | 请降低请求频率 |
