发起门店主体匹配
更新时间:2025.05.09发起门店主体匹配。该接口允许服务商批量查询门店主体是否已在微信支付开通相关支付产品,匹配结果可用于后续企业支付业务的开展。企业可通过此接口确认合作门店的支付能力,提前了解是否可以使用企业支付功能进行消费。
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/webizpay/stores/entity-matches
请求域名:【主域名】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
body 包体参数
sp_mchid 必填 string(32)
【服务商商户号】 是由微信支付系统生成并分配给每个服务商的唯一标识符,具体请参考服务商模式开发必要参数说明。
out_batch_id 必填 string(32)
【商户主体匹配批次单号】 商户主体匹配批次单号,要求6-32个字符内,只能是数字、大小写字母_-|* 且在同一个商户号下唯一。
match_details 选填 array[object]
【主体匹配明细列表】 主体匹配明细列表
| 属性 | |
organization_code 必填 string(32) 【门店统一社会信用代码】 门店统一社会信用代码 store_name 必填 string(256) 【门店名称】 门店名称,全称表述 product_type 必填 string 【需要查询的支付产品】 需要查询的支付产品,目前仅支持 CODEPAY 可选取值
|
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/webizpay/stores/entity-matches \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "sp_mchid" : "12341234", 8 "out_batch_id" : "batch12345678", 9 "match_details" : [ 10 { 11 "organization_code" : "91110000710926094P", 12 "store_name" : "微信小店", 13 "product_type" : "CODE_PAY" 14 } 15 ] 16 }' 17
需配合微信支付工具库 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 InitiateEntityMatch { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/webizpay/stores/entity-matches"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 InitiateEntityMatch client = new InitiateEntityMatch( 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 StoreInitiateEntityMatchRequest request = new StoreInitiateEntityMatchRequest(); 41 request.spMchid = "12341234"; 42 request.outBatchId = "batch12345678"; 43 request.matchDetails = new ArrayList<>(); 44 { 45 EntityMatchDetail matchDetailsItem = new EntityMatchDetail(); 46 matchDetailsItem.organizationCode = "91110000710926094P"; 47 matchDetailsItem.storeName = "微信小店"; 48 matchDetailsItem.productType = ProductType.CODE_PAY; 49 request.matchDetails.add(matchDetailsItem); 50 }; 51 try { 52 StoreInitiateEntityMatchResponse response = client.run(request); 53 // TODO: 请求成功,继续业务逻辑 54 System.out.println(response); 55 } catch (WXPayUtility.ApiException e) { 56 // TODO: 请求失败,根据状态码执行不同的逻辑 57 e.printStackTrace(); 58 } 59 } 60 61 public StoreInitiateEntityMatchResponse run(StoreInitiateEntityMatchRequest request) { 62 String uri = PATH; 63 String reqBody = WXPayUtility.toJson(request); 64 65 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 66 reqBuilder.addHeader("Accept", "application/json"); 67 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 68 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 69 reqBuilder.addHeader("Content-Type", "application/json"); 70 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 71 reqBuilder.method(METHOD, requestBody); 72 Request httpRequest = reqBuilder.build(); 73 74 // 发送HTTP请求 75 OkHttpClient client = new OkHttpClient.Builder().build(); 76 try (Response httpResponse = client.newCall(httpRequest).execute()) { 77 String respBody = WXPayUtility.extractBody(httpResponse); 78 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 79 // 2XX 成功,验证应答签名 80 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 81 httpResponse.headers(), respBody); 82 83 // 从HTTP应答报文构建返回数据 84 return WXPayUtility.fromJson(respBody, StoreInitiateEntityMatchResponse.class); 85 } else { 86 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 87 } 88 } catch (IOException e) { 89 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 90 } 91 } 92 93 private final String mchid; 94 private final String certificateSerialNo; 95 private final PrivateKey privateKey; 96 private final String wechatPayPublicKeyId; 97 private final PublicKey wechatPayPublicKey; 98 99 public InitiateEntityMatch(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 100 this.mchid = mchid; 101 this.certificateSerialNo = certificateSerialNo; 102 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 103 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 104 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 105 } 106 107 public static class StoreInitiateEntityMatchRequest { 108 @SerializedName("sp_mchid") 109 public String spMchid; 110 111 @SerializedName("out_batch_id") 112 public String outBatchId; 113 114 @SerializedName("match_details") 115 public List<EntityMatchDetail> matchDetails; 116 } 117 118 public static class StoreInitiateEntityMatchResponse { 119 @SerializedName("sp_mchid") 120 public String spMchid; 121 122 @SerializedName("out_batch_id") 123 public String outBatchId; 124 125 @SerializedName("batch_id") 126 public String batchId; 127 128 @SerializedName("time") 129 public String time; 130 131 @SerializedName("state") 132 public BatchState state; 133 } 134 135 public static class EntityMatchDetail { 136 @SerializedName("organization_code") 137 public String organizationCode; 138 139 @SerializedName("store_name") 140 public String storeName; 141 142 @SerializedName("product_type") 143 public ProductType productType; 144 } 145 146 public enum BatchState { 147 @SerializedName("ACCEPTED") 148 ACCEPTED, 149 @SerializedName("IN_PROGRESS") 150 IN_PROGRESS, 151 @SerializedName("COMPLETED") 152 COMPLETED, 153 @SerializedName("CLOSED") 154 CLOSED 155 } 156 157 public enum ProductType { 158 @SerializedName("CODE_PAY") 159 CODE_PAY, 160 @SerializedName("NONE") 161 NONE 162 } 163 164} 165
需配合微信支付工具库 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 "time" 11) 12 13func main() { 14 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 15 config, err := wxpay_utility.CreateMchConfig( 16 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 17 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 18 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 19 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 20 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 21 ) 22 if err != nil { 23 fmt.Println(err) 24 return 25 } 26 27 request := &StoreInitiateEntityMatchRequest{ 28 SpMchid: wxpay_utility.String("12341234"), 29 OutBatchId: wxpay_utility.String("batch12345678"), 30 MatchDetails: []EntityMatchDetail{EntityMatchDetail{ 31 OrganizationCode: wxpay_utility.String("91110000710926094P"), 32 StoreName: wxpay_utility.String("微信小店"), 33 ProductType: PRODUCTTYPE_CODE_PAY.Ptr(), 34 }}, 35 } 36 37 response, err := InitiateEntityMatch(config, request) 38 if err != nil { 39 fmt.Printf("请求失败: %+v\n", err) 40 // TODO: 请求失败,根据状态码执行不同的处理 41 return 42 } 43 44 // TODO: 请求成功,继续业务逻辑 45 fmt.Printf("请求成功: %+v\n", response) 46} 47 48func InitiateEntityMatch(config *wxpay_utility.MchConfig, request *StoreInitiateEntityMatchRequest) (response *StoreInitiateEntityMatchResponse, err error) { 49 const ( 50 host = "https://api.mch.weixin.qq.com" 51 method = "POST" 52 path = "/v3/webizpay/stores/entity-matches" 53 ) 54 55 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 56 if err != nil { 57 return nil, err 58 } 59 reqBody, err := json.Marshal(request) 60 if err != nil { 61 return nil, err 62 } 63 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 64 if err != nil { 65 return nil, err 66 } 67 httpRequest.Header.Set("Accept", "application/json") 68 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 69 httpRequest.Header.Set("Content-Type", "application/json") 70 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 71 if err != nil { 72 return nil, err 73 } 74 httpRequest.Header.Set("Authorization", authorization) 75 76 client := &http.Client{} 77 httpResponse, err := client.Do(httpRequest) 78 if err != nil { 79 return nil, err 80 } 81 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 82 if err != nil { 83 return nil, err 84 } 85 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 86 // 2XX 成功,验证应答签名 87 err = wxpay_utility.ValidateResponse( 88 config.WechatPayPublicKeyId(), 89 config.WechatPayPublicKey(), 90 &httpResponse.Header, 91 respBody, 92 ) 93 if err != nil { 94 return nil, err 95 } 96 response := &StoreInitiateEntityMatchResponse{} 97 if err := json.Unmarshal(respBody, response); err != nil { 98 return nil, err 99 } 100 101 return response, nil 102 } else { 103 return nil, wxpay_utility.NewApiException( 104 httpResponse.StatusCode, 105 httpResponse.Header, 106 respBody, 107 ) 108 } 109} 110 111type StoreInitiateEntityMatchRequest struct { 112 SpMchid *string `json:"sp_mchid,omitempty"` 113 OutBatchId *string `json:"out_batch_id,omitempty"` 114 MatchDetails []EntityMatchDetail `json:"match_details,omitempty"` 115} 116 117type StoreInitiateEntityMatchResponse struct { 118 SpMchid *string `json:"sp_mchid,omitempty"` 119 OutBatchId *string `json:"out_batch_id,omitempty"` 120 BatchId *string `json:"batch_id,omitempty"` 121 Time *time.Time `json:"time,omitempty"` 122 State *BatchState `json:"state,omitempty"` 123} 124 125type EntityMatchDetail struct { 126 OrganizationCode *string `json:"organization_code,omitempty"` 127 StoreName *string `json:"store_name,omitempty"` 128 ProductType *ProductType `json:"product_type,omitempty"` 129} 130 131type BatchState string 132 133func (e BatchState) Ptr() *BatchState { 134 return &e 135} 136 137const ( 138 BATCHSTATE_ACCEPTED BatchState = "ACCEPTED" 139 BATCHSTATE_IN_PROGRESS BatchState = "IN_PROGRESS" 140 BATCHSTATE_COMPLETED BatchState = "COMPLETED" 141 BATCHSTATE_CLOSED BatchState = "CLOSED" 142) 143 144type ProductType string 145 146func (e ProductType) Ptr() *ProductType { 147 return &e 148} 149 150const ( 151 PRODUCTTYPE_CODE_PAY ProductType = "CODE_PAY" 152 PRODUCTTYPE_NONE ProductType = "NONE" 153) 154
应答参数
200 OK
sp_mchid 必填 string(32)
【服务商商户号】 服务商商户号,商户请求时传入
out_batch_id 必填 string(32)
【商户主体匹配批次单号】 商户主体匹配批次单号,由商户发起门店信息匹配时传入
batch_id 必填 string(32)
【微信支付主体匹配批次单号】 微信支付主体匹配批次单号,标记某一次响应商户主体匹配信息对应的处理单号,在微信支付体系下唯一。
time 必填 string
【批次创建时间】 批次创建时间,微信支付处理完成此批次的时间。
遵循rfc3339标准格式:yyyy-MM-DDTHH:mm:ss+TIMEZONE。yyyy-MM-DD 表示年月日;T 字符用于分隔日期和时间部分;HH:mm:ss 表示具体的时分秒;TIMEZONE 表示时区(例如,+08:00 对应东八区时间,即北京时间)。
示例:2015-05-20T13:29:35+08:00 表示北京时间2015年5月20日13点29分35秒。
state 必填 string
【批次状态】 批次状态:已受理ACCEPTED、处理中IN_PROGRESS、已完成COMPLETED、已关闭CLOSED
可选取值
ACCEPTED: 已受理IN_PROGRESS: 处理中COMPLETED: 已完成CLOSED: 已关闭
应答示例
200 OK
1{ 2 "sp_mchid" : "12341234", 3 "out_batch_id" : "batch12345678", 4 "batch_id" : "1030000071201xxxxx", 5 "time" : "2023-06-08T10:34:56+08:00", 6 "state" : "ACCEPTED" 7} 8
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
