查询门店主体匹配结果

更新时间:2025.05.09

查询门店主体匹配结果。该接口允许服务商查询之前发起的门店主体匹配批次结果,包括各门店统一社会信用代码是否存在满足条件的微信支付商户号。通过此接口可获取匹配结果详情,确认哪些门店可以使用企业支付功能。

接口说明

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

请求方式:【GET】/v3/webizpay/stores/entity-matches/{batch_id}

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

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

请求参数

Header  HTTP头参数

 Authorization  必填 string

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


 Accept  必填 string

请设置为application/json


path  路径参数

 batch_id  必填   string(32)

【微信支付主体匹配批次单号】 微信支付主体匹配批次单号,标记某一次响应商户主体匹配信息对应的处理单号,在微信支付体系下唯一。从发起门店主体匹配时微信支付的返回中获得。


query  查询参数

 sp_mchid  必填   string(32)

【服务商商户号】 是由微信支付系统生成并分配给每个服务商的唯一标识符,具体请参考服务商模式开发必要参数说明

请求示例

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 QueryEntityMatch {
26  private static String HOST = "https://api.mch.weixin.qq.com";
27  private static String METHOD = "GET";
28  private static String PATH = "/v3/webizpay/stores/entity-matches/{batch_id}";
29
30  public static void main(String[] args) {
31    // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340
32    QueryEntityMatch client = new QueryEntityMatch(
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    QueryEntityMatchRequest request = new QueryEntityMatchRequest();
41    request.batchId = "1030000071201xxxxx";
42    request.spMchid = "12341234";
43    try {
44      StoreQueryEntityMatchResponse 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 StoreQueryEntityMatchResponse run(QueryEntityMatchRequest request) {
55    String uri = PATH;
56    uri = uri.replace("{batch_id}", WXPayUtility.urlEncode(request.batchId));
57    Map<String, Object> args = new HashMap<>();
58    args.put("sp_mchid", request.spMchid);
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, StoreQueryEntityMatchResponse.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 QueryEntityMatch(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 QueryEntityMatchRequest {
102    @SerializedName("sp_mchid")
103    @Expose(serialize = false)
104    public String spMchid;
105  
106    @SerializedName("batch_id")
107    @Expose(serialize = false)
108    public String batchId;
109  }
110  
111  public static class StoreQueryEntityMatchResponse {
112    @SerializedName("sp_mchid")
113    public String spMchid;
114  
115    @SerializedName("out_batch_id")
116    public String outBatchId;
117  
118    @SerializedName("batch_id")
119    public String batchId;
120  
121    @SerializedName("state")
122    public BatchState state;
123  
124    @SerializedName("match_results")
125    public List<EntityMatchResult> matchResults;
126  }
127  
128  public enum BatchState {
129    @SerializedName("ACCEPTED")
130    ACCEPTED,
131    @SerializedName("IN_PROGRESS")
132    IN_PROGRESS,
133    @SerializedName("COMPLETED")
134    COMPLETED,
135    @SerializedName("CLOSED")
136    CLOSED
137  }
138  
139  public static class EntityMatchResult {
140    @SerializedName("organization_code")
141    public String organizationCode;
142  
143    @SerializedName("store_name")
144    public String storeName;
145  
146    @SerializedName("has_valid_mchid")
147    public Boolean hasValidMchid;
148  }
149  
150}
151

应答参数

200 OK

 sp_mchid  必填   string(32)

【服务商商户号】 服务商商户号,从商户发起匹配门店主体匹配时传入


 out_batch_id  必填   string(32)

【商户主体匹配批次单号】 商户主体匹配批次单号,从商户发起匹配门店主体匹配时传入


 batch_id  必填   string(32)

【微信支付主体匹配批次单号】 微信支付主体匹配批次单号,标记某一次响应商户主体匹配信息对应的处理单号,在微信支付体系下唯一。


 state  必填   string

【批次状态】 批次状态:已受理ACCEPTED、处理中IN_PROGRESS、已完成COMPLETED、已关闭CLOSED

可选取值

  • ACCEPTED:  已受理

  • IN_PROGRESS:  处理中

  • COMPLETED:  已完成

  • CLOSED:  已关闭


 match_results  选填   array[object]

【主体匹配明细列表】 主体匹配明细列表,若结果为空,列表长度为0

属性

应答示例

200 OK

1{
2  "sp_mchid" : "12341234",
3  "out_batch_id" : "batch12345678",
4  "batch_id" : "1030000071201xxxxx",
5  "state" : "ACCEPTED",
6  "match_results" : [
7    {
8      "organization_code" : "911100007109260000",
9      "store_name" : "微信小店",
10      "has_valid_mchid" : true
11    }
12  ]
13}
14

 

错误码

公共错误码

状态码

错误码

描述

解决方案

400

PARAM_ERROR

参数错误

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

400

INVALID_REQUEST

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

请参阅 接口规则

401

SIGN_ERROR

验证不通过

请参阅 签名常见问题

500

SYSTEM_ERROR

系统异常,请稍后重试

请稍后重试

 

 

更多技术问题
技术咨询
反馈
咨询
目录
置顶