解锁公益捐赠预算
更新时间:2025.07.10解锁公益捐赠预算
注:单个商户的接口频率限制为100次/s
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/fund-app/mch-transfer/partner/charity-budget/{out_budget_no}/unlock
请求域名:【主域名】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_budget_no 必填 string(32)
【商户预算单号】 服务商系统内部预算单号,此参数只能由数字、大小写字母组成,服务商系统内部唯一
body 包体参数
sponsor_mchid 必填 string(32)
【出资商户号】 出资商户号
unlock_remark 必填 string(32)
【解锁备注】 撤销该笔资金锁定的说明
请求示例
需配合微信支付工具库 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 UnlockBudget { 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/charity-budget/{out_budget_no}/unlock"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 UnlockBudget client = new UnlockBudget( 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 UnlockBudgetRequest request = new UnlockBudgetRequest(); 41 request.outBudgetNo = "budget202506300102"; 42 request.sponsorMchid = "1900001109"; 43 request.unlockRemark = "公益活动结束,解锁资金"; 44 try { 45 BudgetInfo response = client.run(request); 46 47 // TODO: 请求成功,继续业务逻辑 48 System.out.println(response); 49 } catch (WXPayUtility.ApiException e) { 50 // TODO: 请求失败,根据状态码执行不同的逻辑 51 e.printStackTrace(); 52 } 53 } 54 55 public BudgetInfo run(UnlockBudgetRequest request) { 56 String uri = PATH; 57 uri = uri.replace("{out_budget_no}", WXPayUtility.urlEncode(request.outBudgetNo)); 58 String reqBody = WXPayUtility.toJson(request); 59 60 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 61 reqBuilder.addHeader("Accept", "application/json"); 62 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 63 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 64 reqBuilder.addHeader("Content-Type", "application/json"); 65 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 66 reqBuilder.method(METHOD, requestBody); 67 Request httpRequest = reqBuilder.build(); 68 69 // 发送HTTP请求 70 OkHttpClient client = new OkHttpClient.Builder().build(); 71 try (Response httpResponse = client.newCall(httpRequest).execute()) { 72 String respBody = WXPayUtility.extractBody(httpResponse); 73 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 74 // 2XX 成功,验证应答签名 75 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 76 httpResponse.headers(), respBody); 77 78 // 从HTTP应答报文构建返回数据 79 return WXPayUtility.fromJson(respBody, BudgetInfo.class); 80 } else { 81 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 82 } 83 } catch (IOException e) { 84 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 85 } 86 } 87 88 private final String mchid; 89 private final String certificateSerialNo; 90 private final PrivateKey privateKey; 91 private final String wechatPayPublicKeyId; 92 private final PublicKey wechatPayPublicKey; 93 94 public UnlockBudget(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 95 this.mchid = mchid; 96 this.certificateSerialNo = certificateSerialNo; 97 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 98 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 99 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 100 } 101 102 public static class UnlockBudgetRequest { 103 @SerializedName("out_budget_no") 104 @Expose(serialize = false) 105 public String outBudgetNo; 106 107 @SerializedName("sponsor_mchid") 108 public String sponsorMchid; 109 110 @SerializedName("unlock_remark") 111 public String unlockRemark; 112 } 113 114 public static class BudgetInfo { 115 @SerializedName("sp_mchid") 116 public String spMchid; 117 118 @SerializedName("out_budget_no") 119 public String outBudgetNo; 120 121 @SerializedName("budget_id") 122 public String budgetId; 123 124 @SerializedName("amount") 125 public Long amount; 126 127 @SerializedName("sponsor_mchid") 128 public String sponsorMchid; 129 130 @SerializedName("activity_name") 131 public String activityName; 132 133 @SerializedName("activity_remark") 134 public String activityRemark; 135 136 @SerializedName("state") 137 public BudgetOrderState state; 138 139 @SerializedName("unlock_remark") 140 public String unlockRemark; 141 142 @SerializedName("locked_time") 143 public String lockedTime; 144 145 @SerializedName("finished_time") 146 public String finishedTime; 147 } 148 149 public enum BudgetOrderState { 150 @SerializedName("FINISHED") 151 FINISHED 152 } 153 154} 155
需配合微信支付工具库 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 := &UnlockBudgetRequest{ 28 OutBudgetNo: wxpay_utility.String("budget202506300102"), 29 SponsorMchid: wxpay_utility.String("1900001109"), 30 UnlockRemark: wxpay_utility.String("公益活动结束,解锁资金"), 31 } 32 33 response, err := UnlockBudget(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 UnlockBudget(config *wxpay_utility.MchConfig, request *UnlockBudgetRequest) (response *BudgetInfo, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "POST" 48 path = "/v3/fund-app/mch-transfer/partner/charity-budget/{out_budget_no}/unlock" 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_budget_no}", url.PathEscape(*request.OutBudgetNo), -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 79 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 80 if err != nil { 81 return nil, err 82 } 83 84 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 85 // 2XX 成功,验证应答签名 86 err = wxpay_utility.ValidateResponse( 87 config.WechatPayPublicKeyId(), 88 config.WechatPayPublicKey(), 89 &httpResponse.Header, 90 respBody, 91 ) 92 if err != nil { 93 return nil, err 94 } 95 96 if err := json.Unmarshal(respBody, response); err != nil { 97 return nil, err 98 } 99 100 return response, nil 101 } else { 102 return nil, wxpay_utility.NewApiException( 103 httpResponse.StatusCode, 104 httpResponse.Header, 105 respBody, 106 ) 107 } 108} 109 110type UnlockBudgetRequest struct { 111 OutBudgetNo *string `json:"out_budget_no,omitempty"` 112 SponsorMchid *string `json:"sponsor_mchid,omitempty"` 113 UnlockRemark *string `json:"unlock_remark,omitempty"` 114} 115 116func (o *UnlockBudgetRequest) MarshalJSON() ([]byte, error) { 117 type Alias UnlockBudgetRequest 118 a := &struct { 119 OutBudgetNo *string `json:"out_budget_no,omitempty"` 120 *Alias 121 }{ 122 // 序列化时移除非 Body 字段 123 OutBudgetNo: nil, 124 Alias: (*Alias)(o), 125 } 126 return json.Marshal(a) 127} 128 129type BudgetInfo struct { 130 SpMchid *string `json:"sp_mchid,omitempty"` 131 OutBudgetNo *string `json:"out_budget_no,omitempty"` 132 BudgetId *string `json:"budget_id,omitempty"` 133 Amount *int64 `json:"amount,omitempty"` 134 SponsorMchid *string `json:"sponsor_mchid,omitempty"` 135 ActivityName *string `json:"activity_name,omitempty"` 136 ActivityRemark *string `json:"activity_remark,omitempty"` 137 State *BudgetOrderState `json:"state,omitempty"` 138 UnlockRemark *string `json:"unlock_remark,omitempty"` 139 LockedTime *string `json:"locked_time,omitempty"` 140 FinishedTime *string `json:"finished_time,omitempty"` 141} 142 143type BudgetOrderState string 144 145func (e BudgetOrderState) Ptr() *BudgetOrderState { 146 return &e 147} 148 149const ( 150 BUDGETORDERSTATE_FINISHED BudgetOrderState = "FINISHED" 151) 152
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/partner/charity-budget/budget202506300102/unlock \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "sponsor_mchid" : "1900001109", 8 "unlock_remark" : "公益活动结束,解锁资金" 9 }' 10
应答参数
200 OK
sp_mchid 必填 string(32)
【服务商商户号】 服务商商户号
out_budget_no 必填 string(32)
【商户预算单号】 服务商系统内部预算单号,此参数只能由数字、大小写字母组成,在服务商系统内部唯一。
budget_id 必填 string(32)
【微信支付预算单号】 微信支付预算单号,微信系统返回的唯一标识。
amount 必填 integer
【活动总金额】 活动预算总金额,单位为“分”。
sponsor_mchid 必填 string(32)
【出资商户号】 出资商户号
activity_name 必填 string(32)
【活动名称】 活动名称
activity_remark 必填 string(64)
【活动说明】 活动说明
state 必填 string
【预算单状态】 预算单状态
可选取值
FINISHED
: 已完成(终态),预算捐赠完成或者解锁后,预算单会由LOCKED转变为FINISHED状态
unlock_remark 必填 string(32)
【撤销说明】 预算解锁时,商户传入的解锁说明
locked_time 必填 string
【资金锁定时间】 资金锁定时间,遵循rfc3339标准格式:yyyy-MM-DDThh:mm:ss+TIMEZONE
finished_time 必填 string
【完成时间】 完成时间,遵循rfc3339标准格式:yyyy-MM-DDThh:mm:ss+TIMEZONE
应答示例
200 OK
1{ 2 "sp_mchid" : "1900001109", 3 "out_budget_no" : "budget202506300102", 4 "budget_id" : "1182020050700019480001", 5 "amount" : 20000000, 6 "sponsor_mchid" : "1900001109", 7 "activity_name" : "公益企业配捐活动", 8 "activity_remark" : "公益活动开始于9月1日,帮助困难儿童筹款活动", 9 "state" : "FINISHED", 10 "unlock_remark" : "公益活动结束,解锁资金", 11 "locked_time" : "2025-06-21T13:29:35.120+08:00", 12 "finished_time" : "2025-06-21T13:29:35.120+08:00" 13} 14
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
429 | RATELIMIT_EXCEEDED | 请求接口频率过快 | 降低频率,稍后重试 |
404 | NOT_FOUND | 记录不存在 | 确认预算单号 |
400 | INVALID_REQUEST | 请求不符合业务规则 | 预算单单已经关闭,无法解锁,请通过查单接口确认预算单状态 |