分页查询子商户名下的交易拦截记录

更新时间:2025.05.21

通过该接口可用于分页查询子商户名下的交易拦截记录

接口说明

支持商户:【普通服务商】

请求方式:【GET】/v3/transaction-block/transaction-block-records/sub-mchid/{sub_mchid}

请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点

     【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看

请求参数

Header  HTTP头参数

 Authorization  必填 string

请参考签名认证生成认证信息


 Accept  必填 string

请设置为application/json


path  路径参数

 sub_mchid  必填   string(32)

【子商户号】 由服务商为子商户进件后获取,具体请参考服务商模式开发必要参数说明


query  查询参数

 limit  必填   integer

【最大资源条数】 该次请求可返回的最大资源条数,不超过10


 offset  选填   integer

【请求资源起始位置】 该次请求资源的起始位置

请求示例

Java
Go
curl

需配合微信支付工具库 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 ListTransactionBlockRecords {
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/sub-mchid/{sub_mchid}";
29
30  public static void main(String[] args) {
31    // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340
32    ListTransactionBlockRecords client = new ListTransactionBlockRecords(
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    ListTransactionBlockRecordsRequest request = new ListTransactionBlockRecordsRequest();
41    request.subMchid = "123000110";
42    request.limit = 5L;
43    request.offset = 10L;
44    try {
45      ListTransactionBlockRecordsResponse 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 ListTransactionBlockRecordsResponse run(ListTransactionBlockRecordsRequest request) {
56    String uri = PATH;
57    uri = uri.replace("{sub_mchid}", WXPayUtility.urlEncode(request.subMchid));
58    Map<String, Object> args = new HashMap<>();
59    args.put("limit", request.limit);
60    args.put("offset", request.offset);
61    uri = uri + "?" + WXPayUtility.urlEncode(args);
62
63    Request.Builder reqBuilder = new Request.Builder().url(HOST + uri);
64    reqBuilder.addHeader("Accept", "application/json");
65    reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId);
66    reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null));
67    reqBuilder.method(METHOD, null);
68    Request httpRequest = reqBuilder.build();
69
70    // 发送HTTP请求
71    OkHttpClient client = new OkHttpClient.Builder().build();
72    try (Response httpResponse = client.newCall(httpRequest).execute()) {
73      String respBody = WXPayUtility.extractBody(httpResponse);
74      if (httpResponse.code() >= 200 && httpResponse.code() < 300) {
75        // 2XX 成功,验证应答签名
76        WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey,
77            httpResponse.headers(), respBody);
78
79        // 从HTTP应答报文构建返回数据
80        return WXPayUtility.fromJson(respBody, ListTransactionBlockRecordsResponse.class);
81      } else {
82        throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers());
83      }
84    } catch (IOException e) {
85      throw new UncheckedIOException("Sending request to " + uri + " failed.", e);
86    }
87  }
88
89  private final String mchid;
90  private final String certificateSerialNo;
91  private final PrivateKey privateKey;
92  private final String wechatPayPublicKeyId;
93  private final PublicKey wechatPayPublicKey;
94
95  public ListTransactionBlockRecords(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) {
96    this.mchid = mchid;
97    this.certificateSerialNo = certificateSerialNo;
98    this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath);
99    this.wechatPayPublicKeyId = wechatPayPublicKeyId;
100    this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath);
101  }
102
103  public static class ListTransactionBlockRecordsRequest {
104    @SerializedName("sub_mchid")
105    @Expose(serialize = false)
106    public String subMchid;
107  
108    @SerializedName("limit")
109    @Expose(serialize = false)
110    public Long limit;
111  
112    @SerializedName("offset")
113    @Expose(serialize = false)
114    public Long offset;
115  }
116  
117  public static class ListTransactionBlockRecordsResponse {
118    @SerializedName("data")
119    public List<TransactionBlockRecordsEntity> data;
120  
121    @SerializedName("offset")
122    public Long offset;
123  
124    @SerializedName("limit")
125    public Long limit;
126  
127    @SerializedName("total_count")
128    public Long totalCount;
129  }
130  
131  public static class TransactionBlockRecordsEntity {
132    @SerializedName("block_record_id")
133    public String blockRecordId;
134  
135    @SerializedName("block_time")
136    public String blockTime;
137  
138    @SerializedName("block_reason")
139    public String blockReason;
140  
141    @SerializedName("number_of_block")
142    public EnumTypeNumberOfBlockDesc numberOfBlock;
143  
144    @SerializedName("recover_way")
145    public EnumTypeRecoverWay recoverWay;
146  
147    @SerializedName("requested_item_info")
148    public String requestedItemInfo;
149  }
150  
151  public enum EnumTypeNumberOfBlockDesc {
152    @SerializedName("LESS_THAN_TWENTY")
153    LESS_THAN_TWENTY,
154    @SerializedName("LESS_THAN_ONE_HUNDRED")
155    LESS_THAN_ONE_HUNDRED,
156    @SerializedName("LESS_THAN_ONE_THOUSAND")
157    LESS_THAN_ONE_THOUSAND,
158    @SerializedName("OVER_ONE_THOUSAND")
159    OVER_ONE_THOUSAND
160  }
161  
162  public enum EnumTypeRecoverWay {
163    @SerializedName("SUBMIT_INFORMATION")
164    SUBMIT_INFORMATION
165  }
166  
167}
168

应答参数

200 OK

 data  选填   array[object]

【交易拦截记录详情列表】 交易拦截记录的详情列表,查询结果不为空时返回

属性

 offset  选填   integer

【请求资源起始位置】 该次请求资源的起始位置,查询结果不为空时返回


 limit  选填   integer

【最大资源条数】 该次请求可返回的最大资源条数,查询结果不为空时返回


 total_count  选填   integer

【资源总条数】 可选返回,资源总条数。当offset=0或者当前查询为空时返回总条数

应答示例

200 OK

1{
2  "data" : [
3    {
4      "block_record_id" : "23400",
5      "block_time" : "2018-06-08T10:34:56+08:00",
6      "block_reason" : "涉嫌信用卡套现",
7      "number_of_block" : "LESS_THAN_TWENTY",
8      "recover_way" : "SUBMIT_INFORMATION",
9      "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] }"
10    }
11  ],
12  "offset" : 10,
13  "limit" : 5,
14  "total_count" : 1234
15}
16

 

错误码

公共错误码

状态码

错误码

描述

解决方案

400

PARAM_ERROR

参数错误

请根据错误提示正确传入参数

400

INVALID_REQUEST

HTTP 请求不符合微信支付 APIv3 接口规则

请参阅 接口规则

401

SIGN_ERROR

验证不通过

请参阅 签名常见问题

500

SYSTEM_ERROR

系统异常,请稍后重试

请稍后重试

业务错误码

状态码

错误码

描述

解决方案

400

INVALID_REQUEST

此接口仅对部分合作伙伴开放,当前商户号未开放

等待微信支付向当前商户号开放此能力

 

 

反馈
咨询
目录
置顶