查询子商户交易拦截记录详情
更新时间:2025.05.21通过该接口可用于查询子商户交易拦截记录详情
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/transaction-block/transaction-block-records/{block_record_id}
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
block_record_id 必填 string(64)
【交易拦截记录ID】 交易拦截记录的主键,唯一定义此资源的标识
query 查询参数
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 QueryTransactionBlockRecord { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/transaction-block/transaction-block-records/{block_record_id}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 QueryTransactionBlockRecord client = new QueryTransactionBlockRecord( 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 QueryTransactionBlockRecordRequest request = new QueryTransactionBlockRecordRequest(); 41 request.blockRecordId = "123400"; 42 request.subMchid = "123000110"; 43 try { 44 TransactionBlockRecordsEntity 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 TransactionBlockRecordsEntity run(QueryTransactionBlockRecordRequest request) { 55 String uri = PATH; 56 uri = uri.replace("{block_record_id}", WXPayUtility.urlEncode(request.blockRecordId)); 57 Map<String, Object> args = new HashMap<>(); 58 args.put("sub_mchid", request.subMchid); 59 uri = uri + "?" + WXPayUtility.urlEncode(args); 60 61 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 62 reqBuilder.addHeader("Accept", "application/json"); 63 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 64 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 65 reqBuilder.method(METHOD, null); 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, TransactionBlockRecordsEntity.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 QueryTransactionBlockRecord(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 QueryTransactionBlockRecordRequest { 102 @SerializedName("sub_mchid") 103 @Expose(serialize = false) 104 public String subMchid; 105 106 @SerializedName("block_record_id") 107 @Expose(serialize = false) 108 public String blockRecordId; 109 } 110 111 public static class TransactionBlockRecordsEntity { 112 @SerializedName("block_record_id") 113 public String blockRecordId; 114 115 @SerializedName("block_time") 116 public String blockTime; 117 118 @SerializedName("block_reason") 119 public String blockReason; 120 121 @SerializedName("number_of_block") 122 public EnumTypeNumberOfBlockDesc numberOfBlock; 123 124 @SerializedName("recover_way") 125 public EnumTypeRecoverWay recoverWay; 126 127 @SerializedName("requested_item_info") 128 public String requestedItemInfo; 129 } 130 131 public enum EnumTypeNumberOfBlockDesc { 132 @SerializedName("LESS_THAN_TWENTY") 133 LESS_THAN_TWENTY, 134 @SerializedName("LESS_THAN_ONE_HUNDRED") 135 LESS_THAN_ONE_HUNDRED, 136 @SerializedName("LESS_THAN_ONE_THOUSAND") 137 LESS_THAN_ONE_THOUSAND, 138 @SerializedName("OVER_ONE_THOUSAND") 139 OVER_ONE_THOUSAND 140 } 141 142 public enum EnumTypeRecoverWay { 143 @SerializedName("SUBMIT_INFORMATION") 144 SUBMIT_INFORMATION 145 } 146 147} 148
需配合微信支付工具库 wxpay_utility 使用,请参考 Go
1package main 2 3import ( 4 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9 "strings" 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 := &QueryTransactionBlockRecordRequest{ 27 SubMchid: wxpay_utility.String("123000110"), 28 BlockRecordId: wxpay_utility.String("123400"), 29 } 30 31 response, err := QueryTransactionBlockRecord(config, request) 32 if err != nil { 33 fmt.Printf("请求失败: %+v\n", err) 34 // TODO: 请求失败,根据状态码执行不同的处理 35 return 36 } 37 38 // TODO: 请求成功,继续业务逻辑 39 fmt.Printf("请求成功: %+v\n", response) 40} 41 42func QueryTransactionBlockRecord(config *wxpay_utility.MchConfig, request *QueryTransactionBlockRecordRequest) (response *TransactionBlockRecordsEntity, err error) { 43 const ( 44 host = "https://api.mch.weixin.qq.com" 45 method = "GET" 46 path = "/v3/transaction-block/transaction-block-records/{block_record_id}" 47 ) 48 49 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 50 if err != nil { 51 return nil, err 52 } 53 reqUrl.Path = strings.Replace(reqUrl.Path, "{block_record_id}", url.PathEscape(*request.BlockRecordId), -1) 54 query := reqUrl.Query() 55 query.Add("sub_mchid", *request.SubMchid) 56 reqUrl.RawQuery = query.Encode() 57 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 58 if err != nil { 59 return nil, err 60 } 61 httpRequest.Header.Set("Accept", "application/json") 62 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 63 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 64 if err != nil { 65 return nil, err 66 } 67 httpRequest.Header.Set("Authorization", authorization) 68 69 client := &http.Client{} 70 httpResponse, err := client.Do(httpRequest) 71 if err != nil { 72 return nil, err 73 } 74 75 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 76 if err != nil { 77 return nil, err 78 } 79 80 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 81 // 2XX 成功,验证应答签名 82 err = wxpay_utility.ValidateResponse( 83 config.WechatPayPublicKeyId(), 84 config.WechatPayPublicKey(), 85 &httpResponse.Header, 86 respBody, 87 ) 88 if err != nil { 89 return nil, err 90 } 91 92 if err := json.Unmarshal(respBody, response); err != nil { 93 return nil, err 94 } 95 96 return response, nil 97 } else { 98 return nil, wxpay_utility.NewApiException( 99 httpResponse.StatusCode, 100 httpResponse.Header, 101 respBody, 102 ) 103 } 104} 105 106type QueryTransactionBlockRecordRequest struct { 107 SubMchid *string `json:"sub_mchid,omitempty"` 108 BlockRecordId *string `json:"block_record_id,omitempty"` 109} 110 111func (o *QueryTransactionBlockRecordRequest) MarshalJSON() ([]byte, error) { 112 type Alias QueryTransactionBlockRecordRequest 113 a := &struct { 114 SubMchid *string `json:"sub_mchid,omitempty"` 115 BlockRecordId *string `json:"block_record_id,omitempty"` 116 *Alias 117 }{ 118 // 序列化时移除非 Body 字段 119 SubMchid: nil, 120 BlockRecordId: nil, 121 Alias: (*Alias)(o), 122 } 123 return json.Marshal(a) 124} 125 126type TransactionBlockRecordsEntity struct { 127 BlockRecordId *string `json:"block_record_id,omitempty"` 128 BlockTime *string `json:"block_time,omitempty"` 129 BlockReason *string `json:"block_reason,omitempty"` 130 NumberOfBlock *EnumTypeNumberOfBlockDesc `json:"number_of_block,omitempty"` 131 RecoverWay *EnumTypeRecoverWay `json:"recover_way,omitempty"` 132 RequestedItemInfo *string `json:"requested_item_info,omitempty"` 133} 134 135type EnumTypeNumberOfBlockDesc string 136 137func (e EnumTypeNumberOfBlockDesc) Ptr() *EnumTypeNumberOfBlockDesc { 138 return &e 139} 140 141const ( 142 ENUMTYPENUMBEROFBLOCKDESC_LESS_THAN_TWENTY EnumTypeNumberOfBlockDesc = "LESS_THAN_TWENTY" 143 ENUMTYPENUMBEROFBLOCKDESC_LESS_THAN_ONE_HUNDRED EnumTypeNumberOfBlockDesc = "LESS_THAN_ONE_HUNDRED" 144 ENUMTYPENUMBEROFBLOCKDESC_LESS_THAN_ONE_THOUSAND EnumTypeNumberOfBlockDesc = "LESS_THAN_ONE_THOUSAND" 145 ENUMTYPENUMBEROFBLOCKDESC_OVER_ONE_THOUSAND EnumTypeNumberOfBlockDesc = "OVER_ONE_THOUSAND" 146) 147 148type EnumTypeRecoverWay string 149 150func (e EnumTypeRecoverWay) Ptr() *EnumTypeRecoverWay { 151 return &e 152} 153 154const ( 155 ENUMTYPERECOVERWAY_SUBMIT_INFORMATION EnumTypeRecoverWay = "SUBMIT_INFORMATION" 156) 157
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/transaction-block/transaction-block-records/123400?sub_mchid=123000110 \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" 5
应答参数
200 OK
block_record_id 选填 string(64)
【交易拦截记录ID】 拦截记录查询成功时返回,交易拦截记录的主键,唯一定义此资源的标识
block_time 选填 string(64)
【拦截时间】 拦截记录查询成功时返回,遵循rfc3339标准格式:yyyy-MM-DDThh:mm:ss+TIMEZONE
block_reason 选填 string(1024)
【拦截原因】 拦截记录查询成功时返回,描述交易被拦截的原因
number_of_block 选填 string
【拦截笔数】 拦截记录查询成功时返回,交易拦截的笔数
可选取值
LESS_THAN_TWENTY
: 拦截笔数小于20LESS_THAN_ONE_HUNDRED
: 拦截笔数小于100LESS_THAN_ONE_THOUSAND
: 拦截笔数小于1000OVER_ONE_THOUSAND
: 拦截笔数大于等于1000
recover_way 选填 string
【解除管控方式】 拦截记录查询成功时返回,解除管控的方法
可选取值
SUBMIT_INFORMATION
: 按要求提交资料,审核通过后解脱
requested_item_info 选填 string(32000000)
【要求提交的资料】 拦截记录查询成功时返回,要求提交的资料及其校验规则,JSON格式,详见资料说明文档
应答示例
200 OK
1{ 2 "block_record_id" : "23400", 3 "block_time" : "2018-06-08T10:34:56+08:00", 4 "block_reason" : "涉嫌信用卡套现", 5 "number_of_block" : "LESS_THAN_TWENTY", 6 "recover_way" : "SUBMIT_INFORMATION", 7 "requested_item_info" : "{ \t\"record_fields\": [{ \t\t\t\"item_id\": \"100004\", \t\t\t\"field_name\": \"legal_person_card_id\", \t\t\t\"name\": \"企业法人身份证号\", \t\t\t\"type\": 1, \t\t\t\"tips\": \"\", \t\t\t\"placeholder\": \"请输入企业法人身份证号\", \t\t\t\"tooltip\": \"需要填写完整身份证号\", \t\t\t\"required\": 1, \t\t\t\"string_check_rule\": { \t\t\t\t\"min_string_length\": 1, \t\t\t\t\"max_string_length\": 50, \t\t\t\t\"validator\": \"idcard\" \t\t\t}, \t\t\t\"need_encrypt\": true \t\t}, \t\t{ \t\t\t\"item_id\": \"100005\", \t\t\t\"field_name\": \"legal_person_cert_type\", \t\t\t\"name\": \"企业法人证件类型\", \t\t\t\"type\": 4, \t\t\t\"tips\": \"\", \t\t\t\"placeholder\": \"请选择证件类型\", \t\t\t\"tooltip\": \"\", \t\t\t\"required\": 0, \t\t\t\"enum_check_rule\": { \t\t\t\t\"min_list_length\": 1, \t\t\t\t\"max_list_length\": 1, \t\t\t\t\"enum_values\": [\"大陆居民身份证\", \"港澳台通行证\"] \t\t\t}, \t\t\t\"need_encrypt\": false \t\t}, \t\t{ \t\t\t\"item_id\": \"100006\", \t\t\t\"field_name\": \"inland_cert_card_image\", \t\t\t\"name\": \"大陆居民身份证照片\", \t\t\t\"type\": 2, \t\t\t\"tips\": \"请上传图片\", \t\t\t\"placeholder\": \"\", \t\t\t\"tooltip\": \"需要正面和反面两张照片\", \t\t\t\"required\": 1, \t\t\t\"need_encrypt\": false, \t\t\t\"file_check_rule\": { \t\t\t\t\"min_list_length\": 2, \t\t\t\t\"max_list_length\": 2, \t\t\t\t\"enum_file_exts\": [\"png\", \"jpg\", \"jpeg\"], \t\t\t\t\"max_file_size\": 5 \t\t\t}, \t\t\t\"relations\": [{ \t\t\t\t\"source_key\": 100005, \t\t\t\t\"source_value\": \"大陆居民身份证\" \t\t\t}] \t\t} \t] }" 8} 9
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | INVALID_REQUEST | 此接口仅对部分合作伙伴开放,当前商户号未开放 | 等待微信支付向当前商户号开放此能力 |