申请二级商户充值
更新时间: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个字符
请求示例
需配合微信支付工具库 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 57 // TODO: 请求成功,继续业务逻辑 58 System.out.println(response); 59 } catch (WXPayUtility.ApiException e) { 60 // TODO: 请求失败,根据状态码执行不同的逻辑 61 e.printStackTrace(); 62 } 63 } 64 65 public RechargeApplyResponse run(RechargeApplyRequest 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, RechargeApplyResponse.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 PlatSolutionApply(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 RechargeApplyRequest { 112 @SerializedName("sub_mchid") 113 public String subMchid; 114 115 @SerializedName("out_recharge_no") 116 public String outRechargeNo; 117 118 @SerializedName("recharge_scene") 119 public RechargeScene rechargeScene; 120 121 @SerializedName("account_type") 122 public AccountType accountType; 123 124 @SerializedName("recharge_amount") 125 public RechargeAmount rechargeAmount; 126 127 @SerializedName("notify_url") 128 public String notifyUrl; 129 130 @SerializedName("available_recharge_channels") 131 public List<RechargeChannel> availableRechargeChannels; 132 133 @SerializedName("remark") 134 public String remark; 135 } 136 137 public static class RechargeApplyResponse { 138 @SerializedName("recharge_id") 139 public String rechargeId; 140 141 @SerializedName("out_recharge_no") 142 public String outRechargeNo; 143 144 @SerializedName("recharge_url") 145 public String rechargeUrl; 146 } 147 148 public enum RechargeScene { 149 @SerializedName("ECOMMERCE_DEPOSIT") 150 ECOMMERCE_DEPOSIT, 151 @SerializedName("ECOMMERCE_PAYMENT") 152 ECOMMERCE_PAYMENT 153 } 154 155 public enum AccountType { 156 @SerializedName("DEPOSIT") 157 DEPOSIT, 158 @SerializedName("OPERATION") 159 OPERATION 160 } 161 162 public static class RechargeAmount { 163 @SerializedName("amount") 164 public Long amount; 165 166 @SerializedName("currency") 167 public String currency; 168 } 169 170 public enum RechargeChannel { 171 @SerializedName("BANK_TRANSFER") 172 BANK_TRANSFER, 173 @SerializedName("QR_RECHARGE") 174 QR_RECHARGE, 175 @SerializedName("ONLINE_BANK") 176 ONLINE_BANK 177 } 178 179} 180
需配合微信支付工具库 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 85 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 86 if err != nil { 87 return nil, err 88 } 89 90 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 91 // 2XX 成功,验证应答签名 92 err = wxpay_utility.ValidateResponse( 93 config.WechatPayPublicKeyId(), 94 config.WechatPayPublicKey(), 95 &httpResponse.Header, 96 respBody, 97 ) 98 if err != nil { 99 return nil, err 100 } 101 102 if err := json.Unmarshal(respBody, response); err != nil { 103 return nil, err 104 } 105 106 return response, nil 107 } else { 108 return nil, wxpay_utility.NewApiException( 109 httpResponse.StatusCode, 110 httpResponse.Header, 111 respBody, 112 ) 113 } 114} 115 116type RechargeApplyRequest struct { 117 SubMchid *string `json:"sub_mchid,omitempty"` 118 OutRechargeNo *string `json:"out_recharge_no,omitempty"` 119 RechargeScene *RechargeScene `json:"recharge_scene,omitempty"` 120 AccountType *AccountType `json:"account_type,omitempty"` 121 RechargeAmount *RechargeAmount `json:"recharge_amount,omitempty"` 122 NotifyUrl *string `json:"notify_url,omitempty"` 123 AvailableRechargeChannels []RechargeChannel `json:"available_recharge_channels,omitempty"` 124 Remark *string `json:"remark,omitempty"` 125} 126 127type RechargeApplyResponse struct { 128 RechargeId *string `json:"recharge_id,omitempty"` 129 OutRechargeNo *string `json:"out_recharge_no,omitempty"` 130 RechargeUrl *string `json:"recharge_url,omitempty"` 131} 132 133type RechargeScene string 134 135func (e RechargeScene) Ptr() *RechargeScene { 136 return &e 137} 138 139const ( 140 RECHARGESCENE_ECOMMERCE_DEPOSIT RechargeScene = "ECOMMERCE_DEPOSIT" 141 RECHARGESCENE_ECOMMERCE_PAYMENT RechargeScene = "ECOMMERCE_PAYMENT" 142) 143 144type AccountType string 145 146func (e AccountType) Ptr() *AccountType { 147 return &e 148} 149 150const ( 151 ACCOUNTTYPE_DEPOSIT AccountType = "DEPOSIT" 152 ACCOUNTTYPE_OPERATION AccountType = "OPERATION" 153) 154 155type RechargeAmount struct { 156 Amount *int64 `json:"amount,omitempty"` 157 Currency *string `json:"currency,omitempty"` 158} 159 160type RechargeChannel string 161 162func (e RechargeChannel) Ptr() *RechargeChannel { 163 return &e 164} 165 166const ( 167 RECHARGECHANNEL_BANK_TRANSFER RechargeChannel = "BANK_TRANSFER" 168 RECHARGECHANNEL_QR_RECHARGE RechargeChannel = "QR_RECHARGE" 169 RECHARGECHANNEL_ONLINE_BANK RechargeChannel = "ONLINE_BANK" 170) 171
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
应答参数
200 OK
recharge_id 必填 string(27)
【微信支付充值单号】 微信支付充值单号
out_recharge_no 必填 string(64)
【商户充值单号】 商户系统内部的充值单号,只能由数字、大小写字母组成,在平台商户系统内部唯一
recharge_url 必填 string(2048)
【充值链接】 由链接进入充值页面
应答示例
200 OK
1{ 2 "recharge_id" : "172207846292553701", 3 "out_recharge_no" : "cz202407181234", 4 "recharge_url" : "https://www.payapp.qq.com/plat/recharge.html" 5} 6
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
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 | 频率超限 | 请降低请求频率 |