请求撤销保险理赔
更新时间: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)
【二级商户号】 微信支付分配的商户号,出资商户号
请求示例
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
需配合微信支付工具库 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 // TODO: 请求成功,继续业务逻辑 46 System.out.println(response); 47 } catch (WXPayUtility.ApiException e) { 48 // TODO: 请求失败,根据状态码执行不同的逻辑 49 e.printStackTrace(); 50 } 51 } 52 53 public CancelTransferResponse run(InsuranceClaimBillCancelRequest request) { 54 String uri = PATH; 55 uri = uri.replace("{out_bill_no}", WXPayUtility.urlEncode(request.outBillNo)); 56 String reqBody = WXPayUtility.toJson(request); 57 58 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 59 reqBuilder.addHeader("Accept", "application/json"); 60 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 61 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 62 reqBuilder.addHeader("Content-Type", "application/json"); 63 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 64 reqBuilder.method(METHOD, requestBody); 65 Request httpRequest = reqBuilder.build(); 66 67 // 发送HTTP请求 68 OkHttpClient client = new OkHttpClient.Builder().build(); 69 try (Response httpResponse = client.newCall(httpRequest).execute()) { 70 String respBody = WXPayUtility.extractBody(httpResponse); 71 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 72 // 2XX 成功,验证应答签名 73 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 74 httpResponse.headers(), respBody); 75 76 // 从HTTP应答报文构建返回数据 77 return WXPayUtility.fromJson(respBody, CancelTransferResponse.class); 78 } else { 79 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 80 } 81 } catch (IOException e) { 82 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 83 } 84 } 85 86 private final String mchid; 87 private final String certificateSerialNo; 88 private final PrivateKey privateKey; 89 private final String wechatPayPublicKeyId; 90 private final PublicKey wechatPayPublicKey; 91 92 public InsuranceClaimBillCancel(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 93 this.mchid = mchid; 94 this.certificateSerialNo = certificateSerialNo; 95 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 96 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 97 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 98 } 99 100 public static class InsuranceClaimBillCancelRequest { 101 @SerializedName("sub_mchid") 102 public String subMchid; 103 104 @SerializedName("out_bill_no") 105 @Expose(serialize = false) 106 public String outBillNo; 107 } 108 109 public static class CancelTransferResponse { 110 @SerializedName("sub_mchid") 111 public String subMchid; 112 113 @SerializedName("out_bill_no") 114 public String outBillNo; 115 116 @SerializedName("bill_id") 117 public String billId; 118 119 @SerializedName("state") 120 public TransferStatus state; 121 122 @SerializedName("cancel_accept_time") 123 public String cancelAcceptTime; 124 } 125 126 public enum TransferStatus { 127 @SerializedName("ACCEPTED") 128 ACCEPTED, 129 @SerializedName("SUCCESS") 130 SUCCESS, 131 @SerializedName("CLOSED") 132 CLOSED, 133 @SerializedName("WAIT_USER_CONFIRM") 134 WAIT_USER_CONFIRM, 135 @SerializedName("CANCELING") 136 CANCELING, 137 @SerializedName("CANCELLED") 138 CANCELLED 139 } 140 141} 142
需配合微信支付工具库 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 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 79 if err != nil { 80 return nil, err 81 } 82 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 83 // 2XX 成功,验证应答签名 84 err = wxpay_utility.ValidateResponse( 85 config.WechatPayPublicKeyId(), 86 config.WechatPayPublicKey(), 87 &httpResponse.Header, 88 respBody, 89 ) 90 if err != nil { 91 return nil, err 92 } 93 response := &CancelTransferResponse{} 94 if err := json.Unmarshal(respBody, response); err != nil { 95 return nil, err 96 } 97 98 return response, nil 99 } else { 100 return nil, wxpay_utility.NewApiException( 101 httpResponse.StatusCode, 102 httpResponse.Header, 103 respBody, 104 ) 105 } 106} 107 108type InsuranceClaimBillCancelRequest struct { 109 SubMchid *string `json:"sub_mchid,omitempty"` 110 OutBillNo *string `json:"out_bill_no,omitempty"` 111} 112 113func (o *InsuranceClaimBillCancelRequest) MarshalJSON() ([]byte, error) { 114 type Alias InsuranceClaimBillCancelRequest 115 a := &struct { 116 OutBillNo *string `json:"out_bill_no,omitempty"` 117 *Alias 118 }{ 119 // 序列化时移除非 Body 字段 120 OutBillNo: nil, 121 Alias: (*Alias)(o), 122 } 123 return json.Marshal(a) 124} 125 126type CancelTransferResponse struct { 127 SubMchid *string `json:"sub_mchid,omitempty"` 128 OutBillNo *string `json:"out_bill_no,omitempty"` 129 BillId *string `json:"bill_id,omitempty"` 130 State *TransferStatus `json:"state,omitempty"` 131 CancelAcceptTime *time.Time `json:"cancel_accept_time,omitempty"` 132} 133 134type TransferStatus string 135 136func (e TransferStatus) Ptr() *TransferStatus { 137 return &e 138} 139 140const ( 141 TRANSFERSTATUS_ACCEPTED TransferStatus = "ACCEPTED" 142 TRANSFERSTATUS_SUCCESS TransferStatus = "SUCCESS" 143 TRANSFERSTATUS_CLOSED TransferStatus = "CLOSED" 144 TRANSFERSTATUS_WAIT_USER_CONFIRM TransferStatus = "WAIT_USER_CONFIRM" 145 TRANSFERSTATUS_CANCELING TransferStatus = "CANCELING" 146 TRANSFERSTATUS_CANCELLED TransferStatus = "CANCELLED" 147) 148
应答参数
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
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
