请求撤销保险理赔
更新时间:2025.07.25商户可通过该接口撤销赔付,在用户确认收款之前可以通过该接口撤销赔付。该接口返回成功仅表示撤销请求已受理,系统会异步处理退款等操作,以最终查询单据返回状态为准。
接口说明
支持商户:【平台商户】
请求方式:【POST】/v3/platsolution/ecommerce/mch-transfer/insurance-claim-bills/out-bill-no/{out_bill_no}/cancel
请求域名:【主域名】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_bill_no 必填 string(32)
【商户单号】 商户系统内部的商家单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一
body 包体参数
sub_mchid 选填 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 InsuranceClaimBillCancel { 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/mch-transfer/insurance-claim-bills/out-bill-no/{out_bill_no}/cancel"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 InsuranceClaimBillCancel client = new InsuranceClaimBillCancel( 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 InsuranceClaimBillCancelRequest request = new InsuranceClaimBillCancelRequest(); 41 request.outBillNo = "plfk2020042013"; 42 request.subMchid = "1900001109"; 43 try { 44 CancelTransferResponse response = client.run(request); 45 46 // TODO: 请求成功,继续业务逻辑 47 System.out.println(response); 48 } catch (WXPayUtility.ApiException e) { 49 // TODO: 请求失败,根据状态码执行不同的逻辑 50 e.printStackTrace(); 51 } 52 } 53 54 public CancelTransferResponse run(InsuranceClaimBillCancelRequest request) { 55 String uri = PATH; 56 uri = uri.replace("{out_bill_no}", WXPayUtility.urlEncode(request.outBillNo)); 57 String reqBody = WXPayUtility.toJson(request); 58 59 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 60 reqBuilder.addHeader("Accept", "application/json"); 61 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 62 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 63 reqBuilder.addHeader("Content-Type", "application/json"); 64 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 65 reqBuilder.method(METHOD, requestBody); 66 Request httpRequest = reqBuilder.build(); 67 68 // 发送HTTP请求 69 OkHttpClient client = new OkHttpClient.Builder().build(); 70 try (Response httpResponse = client.newCall(httpRequest).execute()) { 71 String respBody = WXPayUtility.extractBody(httpResponse); 72 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 73 // 2XX 成功,验证应答签名 74 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 75 httpResponse.headers(), respBody); 76 77 // 从HTTP应答报文构建返回数据 78 return WXPayUtility.fromJson(respBody, CancelTransferResponse.class); 79 } else { 80 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 81 } 82 } catch (IOException e) { 83 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 84 } 85 } 86 87 private final String mchid; 88 private final String certificateSerialNo; 89 private final PrivateKey privateKey; 90 private final String wechatPayPublicKeyId; 91 private final PublicKey wechatPayPublicKey; 92 93 public InsuranceClaimBillCancel(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 94 this.mchid = mchid; 95 this.certificateSerialNo = certificateSerialNo; 96 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 97 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 98 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 99 } 100 101 public static class InsuranceClaimBillCancelRequest { 102 @SerializedName("sub_mchid") 103 public String subMchid; 104 105 @SerializedName("out_bill_no") 106 @Expose(serialize = false) 107 public String outBillNo; 108 } 109 110 public static class CancelTransferResponse { 111 @SerializedName("sub_mchid") 112 public String subMchid; 113 114 @SerializedName("out_bill_no") 115 public String outBillNo; 116 117 @SerializedName("bill_id") 118 public String billId; 119 120 @SerializedName("state") 121 public TransferStatus state; 122 123 @SerializedName("cancel_accept_time") 124 public String cancelAcceptTime; 125 } 126 127 public enum TransferStatus { 128 @SerializedName("ACCEPTED") 129 ACCEPTED, 130 @SerializedName("SUCCESS") 131 SUCCESS, 132 @SerializedName("CLOSED") 133 CLOSED, 134 @SerializedName("WAIT_USER_CONFIRM") 135 WAIT_USER_CONFIRM, 136 @SerializedName("CANCELING") 137 CANCELING, 138 @SerializedName("CANCELLED") 139 CANCELLED 140 } 141 142} 143
需配合微信支付工具库 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 "time" 12) 13 14func main() { 15 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 config, err := wxpay_utility.CreateMchConfig( 17 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 18 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 19 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 20 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 21 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 22 ) 23 if err != nil { 24 fmt.Println(err) 25 return 26 } 27 28 request := &InsuranceClaimBillCancelRequest{ 29 OutBillNo: wxpay_utility.String("plfk2020042013"), 30 SubMchid: wxpay_utility.String("1900001109"), 31 } 32 33 response, err := InsuranceClaimBillCancel(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 InsuranceClaimBillCancel(config *wxpay_utility.MchConfig, request *InsuranceClaimBillCancelRequest) (response *CancelTransferResponse, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "POST" 48 path = "/v3/platsolution/ecommerce/mch-transfer/insurance-claim-bills/out-bill-no/{out_bill_no}/cancel" 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_bill_no}", url.PathEscape(*request.OutBillNo), -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 InsuranceClaimBillCancelRequest struct { 111 SubMchid *string `json:"sub_mchid,omitempty"` 112 OutBillNo *string `json:"out_bill_no,omitempty"` 113} 114 115func (o *InsuranceClaimBillCancelRequest) MarshalJSON() ([]byte, error) { 116 type Alias InsuranceClaimBillCancelRequest 117 a := &struct { 118 OutBillNo *string `json:"out_bill_no,omitempty"` 119 *Alias 120 }{ 121 // 序列化时移除非 Body 字段 122 OutBillNo: nil, 123 Alias: (*Alias)(o), 124 } 125 return json.Marshal(a) 126} 127 128type CancelTransferResponse struct { 129 SubMchid *string `json:"sub_mchid,omitempty"` 130 OutBillNo *string `json:"out_bill_no,omitempty"` 131 BillId *string `json:"bill_id,omitempty"` 132 State *TransferStatus `json:"state,omitempty"` 133 CancelAcceptTime *time.Time `json:"cancel_accept_time,omitempty"` 134} 135 136type TransferStatus string 137 138func (e TransferStatus) Ptr() *TransferStatus { 139 return &e 140} 141 142const ( 143 TRANSFERSTATUS_ACCEPTED TransferStatus = "ACCEPTED" 144 TRANSFERSTATUS_SUCCESS TransferStatus = "SUCCESS" 145 TRANSFERSTATUS_CLOSED TransferStatus = "CLOSED" 146 TRANSFERSTATUS_WAIT_USER_CONFIRM TransferStatus = "WAIT_USER_CONFIRM" 147 TRANSFERSTATUS_CANCELING TransferStatus = "CANCELING" 148 TRANSFERSTATUS_CANCELLED TransferStatus = "CANCELLED" 149) 150
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/platsolution/ecommerce/mch-transfer/insurance-claim-bills/out-bill-no/plfk2020042013/cancel \ 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 }' 9
应答参数
200 OK
sub_mchid 选填 string(32)
【二级商户号】 微信支付分配的商户号,出资商户号
out_bill_no 必填 string(32)
【商户单号】 商户系统内部的商家单号,要求此参数只能由数字、大小写字母组成,在商户系统内部唯一
bill_id 必填 string(64)
【微信支付付款单号】 微信支付付款单号
state 必填 string
【付款状态】 付款状态
可选取值
ACCEPTED
: 已受理SUCCESS
: 已成功CLOSED
: 系统关闭(余额不足、转账失败等原因)。WAIT_USER_CONFIRM
: 预下单成功,等待用户确认CANCELING
: 商户撤销请求受理成功,该笔付款正在撤销中CANCELLED
: 付款撤销完成
cancel_accept_time 必填 string(32)
【撤销受理时间】 撤销受理成功时会返回,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE
应答示例
200 OK
1{ 2 "sub_mchid" : "1900001109", 3 "out_bill_no" : "plfk2020042013", 4 "bill_id" : "1330000071100999991182020050700019480001", 5 "state" : "SUCCESS", 6 "cancel_accept_time" : "2015-05-20T13:29:35+08:00" 7} 8
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |