查询已生效交易连接名片规则
更新时间:2025.10.30服务商可调用该接口查询品牌下已生效的交易连接名片规则列表。
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/brand/card/card-links
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
query 查询参数
brand_id 必填 string(20)
【品牌ID】 1、商家进驻微信支付品牌商家后获得的品牌ID,作为品牌唯一标识符;
2、数字,长度不超过 20 个字符。
payment_scene 选填 string
【交易场景类型】 交易场景类型是指微信支付提供的帮助商家在不同场景中快速收款的工具(如小程序支付、付款码支付等)。
不同类型的交易场景下,建立交易连接名片规则依据的账号类型不同:
1、当交易场景类型填 MINI_PROGRAM、APP 时, appid 字段必填;
2、当交易场景类型填 PAYMENT_SCORE 时,service_id 字段必填;
3、当交易场景类型填 PAYMENT_CODE 时, card_link_mchid 字段必填;
请选择交易场景类型,不填默认查询所有场景已生效的账号信息。
可选取值
MINI_PROGRAM: 小程序支付:用户在品牌的小程序中选择商品下单,跳转微信支付确认验密页面,完成支付,详细可查看产品介绍APP: APP 支付:用户在品牌的App中选择商品下单,跳转到微信支付确认验密页面,完成支付,详细可查看产品介绍PAYMENT_SCORE: 支付分支付:微信支付分提供先使用服务,再付款的能力,如免押金借用充电宝、电商先用后付等,详细可查看产品介绍PAYMENT_CODE: 付款码支付:用户线下展示付款码,商户收银员用扫码设备扫描用户的付款码,用户确认支付,详细可查看场景介绍
page_index 选填 integer
【查询页码】 查询页码。从1开始,不传默认返回首页数据。
page_size 选填 integer
【查询页大小】 查询页大小。单次拉取的数据条数上限,不填默认为20,最大值50。
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/brand/card/card-links?brand_id=123456&payment_scene=MINI_PROGRAM&page_index=1&page_size=10 \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" 5
需配合微信支付工具库 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 QueryActiveCardLinkList { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/brand/card/card-links"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 QueryActiveCardLinkList client = new QueryActiveCardLinkList( 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 QueryActiveCardLinkListRequest request = new QueryActiveCardLinkListRequest(); 41 request.brandId = "123456"; 42 request.paymentScene = PaymentScene.MINI_PROGRAM; 43 request.pageIndex = 1L; 44 request.pageSize = 10L; 45 try { 46 QueryActiveCardLinkListResponse response = client.run(request); 47 // TODO: 请求成功,继续业务逻辑 48 System.out.println(response); 49 } catch (WXPayUtility.ApiException e) { 50 // TODO: 请求失败,根据状态码执行不同的逻辑 51 e.printStackTrace(); 52 } 53 } 54 55 public QueryActiveCardLinkListResponse run(QueryActiveCardLinkListRequest request) { 56 String uri = PATH; 57 Map<String, Object> args = new HashMap<>(); 58 args.put("brand_id", request.brandId); 59 args.put("payment_scene", request.paymentScene); 60 args.put("page_index", request.pageIndex); 61 args.put("page_size", request.pageSize); 62 String queryString = WXPayUtility.urlEncode(args); 63 if (!queryString.isEmpty()) { 64 uri = uri + "?" + queryString; 65 } 66 67 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 68 reqBuilder.addHeader("Accept", "application/json"); 69 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 70 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 71 reqBuilder.method(METHOD, null); 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, QueryActiveCardLinkListResponse.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 QueryActiveCardLinkList(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 QueryActiveCardLinkListRequest { 108 @SerializedName("brand_id") 109 @Expose(serialize = false) 110 public String brandId; 111 112 @SerializedName("page_index") 113 @Expose(serialize = false) 114 public Long pageIndex; 115 116 @SerializedName("page_size") 117 @Expose(serialize = false) 118 public Long pageSize; 119 120 @SerializedName("payment_scene") 121 @Expose(serialize = false) 122 public PaymentScene paymentScene; 123 } 124 125 public static class QueryActiveCardLinkListResponse { 126 @SerializedName("brand_id") 127 public String brandId; 128 129 @SerializedName("total_num") 130 public Long totalNum; 131 132 @SerializedName("active_link_list") 133 public List<ActiveCardLink> activeLinkList; 134 135 @SerializedName("page_index") 136 public Long pageIndex; 137 138 @SerializedName("page_size") 139 public Long pageSize; 140 } 141 142 public enum PaymentScene { 143 @SerializedName("MINI_PROGRAM") 144 MINI_PROGRAM, 145 @SerializedName("APP") 146 APP, 147 @SerializedName("PAYMENT_SCORE") 148 PAYMENT_SCORE, 149 @SerializedName("PAYMENT_CODE") 150 PAYMENT_CODE 151 } 152 153 public static class ActiveCardLink { 154 @SerializedName("payment_scene") 155 public PaymentScene paymentScene; 156 157 @SerializedName("appid_list") 158 public List<String> appidList; 159 160 @SerializedName("card_link_mchid") 161 public String cardLinkMchid; 162 163 @SerializedName("service_id") 164 public String serviceId; 165 } 166 167} 168
需配合微信支付工具库 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) 10 11func main() { 12 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 13 config, err := wxpay_utility.CreateMchConfig( 14 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 15 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 16 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 17 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 18 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 19 ) 20 if err != nil { 21 fmt.Println(err) 22 return 23 } 24 25 request := &QueryActiveCardLinkListRequest{ 26 BrandId: wxpay_utility.String("123456"), 27 PaymentScene: PAYMENTSCENE_MINI_PROGRAM.Ptr(), 28 PageIndex: wxpay_utility.Int64(1), 29 PageSize: wxpay_utility.Int64(10), 30 } 31 32 response, err := QueryActiveCardLinkList(config, request) 33 if err != nil { 34 fmt.Printf("请求失败: %+v\n", err) 35 // TODO: 请求失败,根据状态码执行不同的处理 36 return 37 } 38 39 // TODO: 请求成功,继续业务逻辑 40 fmt.Printf("请求成功: %+v\n", response) 41} 42 43func QueryActiveCardLinkList(config *wxpay_utility.MchConfig, request *QueryActiveCardLinkListRequest) (response *QueryActiveCardLinkListResponse, err error) { 44 const ( 45 host = "https://api.mch.weixin.qq.com" 46 method = "GET" 47 path = "/v3/brand/card/card-links" 48 ) 49 50 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 51 if err != nil { 52 return nil, err 53 } 54 query := reqUrl.Query() 55 if request.BrandId != nil { 56 query.Add("brand_id", *request.BrandId) 57 } 58 if request.PaymentScene != nil { 59 query.Add("payment_scene", fmt.Sprintf("%v", *request.PaymentScene)) 60 } 61 if request.PageIndex != nil { 62 query.Add("page_index", fmt.Sprintf("%v", *request.PageIndex)) 63 } 64 if request.PageSize != nil { 65 query.Add("page_size", fmt.Sprintf("%v", *request.PageSize)) 66 } 67 reqUrl.RawQuery = query.Encode() 68 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 69 if err != nil { 70 return nil, err 71 } 72 httpRequest.Header.Set("Accept", "application/json") 73 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 74 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 75 if err != nil { 76 return nil, err 77 } 78 httpRequest.Header.Set("Authorization", authorization) 79 80 client := &http.Client{} 81 httpResponse, err := client.Do(httpRequest) 82 if err != nil { 83 return nil, err 84 } 85 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 86 if err != nil { 87 return nil, err 88 } 89 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 90 // 2XX 成功,验证应答签名 91 err = wxpay_utility.ValidateResponse( 92 config.WechatPayPublicKeyId(), 93 config.WechatPayPublicKey(), 94 &httpResponse.Header, 95 respBody, 96 ) 97 if err != nil { 98 return nil, err 99 } 100 response := &QueryActiveCardLinkListResponse{} 101 if err := json.Unmarshal(respBody, response); err != nil { 102 return nil, err 103 } 104 105 return response, nil 106 } else { 107 return nil, wxpay_utility.NewApiException( 108 httpResponse.StatusCode, 109 httpResponse.Header, 110 respBody, 111 ) 112 } 113} 114 115type QueryActiveCardLinkListRequest struct { 116 BrandId *string `json:"brand_id,omitempty"` 117 PageIndex *int64 `json:"page_index,omitempty"` 118 PageSize *int64 `json:"page_size,omitempty"` 119 PaymentScene *PaymentScene `json:"payment_scene,omitempty"` 120} 121 122func (o *QueryActiveCardLinkListRequest) MarshalJSON() ([]byte, error) { 123 type Alias QueryActiveCardLinkListRequest 124 a := &struct { 125 BrandId *string `json:"brand_id,omitempty"` 126 PageIndex *int64 `json:"page_index,omitempty"` 127 PageSize *int64 `json:"page_size,omitempty"` 128 PaymentScene *PaymentScene `json:"payment_scene,omitempty"` 129 *Alias 130 }{ 131 // 序列化时移除非 Body 字段 132 BrandId: nil, 133 PageIndex: nil, 134 PageSize: nil, 135 PaymentScene: nil, 136 Alias: (*Alias)(o), 137 } 138 return json.Marshal(a) 139} 140 141type QueryActiveCardLinkListResponse struct { 142 BrandId *string `json:"brand_id,omitempty"` 143 TotalNum *int64 `json:"total_num,omitempty"` 144 ActiveLinkList []ActiveCardLink `json:"active_link_list,omitempty"` 145 PageIndex *int64 `json:"page_index,omitempty"` 146 PageSize *int64 `json:"page_size,omitempty"` 147} 148 149type PaymentScene string 150 151func (e PaymentScene) Ptr() *PaymentScene { 152 return &e 153} 154 155const ( 156 PAYMENTSCENE_MINI_PROGRAM PaymentScene = "MINI_PROGRAM" 157 PAYMENTSCENE_APP PaymentScene = "APP" 158 PAYMENTSCENE_PAYMENT_SCORE PaymentScene = "PAYMENT_SCORE" 159 PAYMENTSCENE_PAYMENT_CODE PaymentScene = "PAYMENT_CODE" 160) 161 162type ActiveCardLink struct { 163 PaymentScene *PaymentScene `json:"payment_scene,omitempty"` 164 AppidList []string `json:"appid_list,omitempty"` 165 CardLinkMchid *string `json:"card_link_mchid,omitempty"` 166 ServiceId *string `json:"service_id,omitempty"` 167} 168
应答参数
200 OK
brand_id 必填 string(20)
【品牌ID】 1、商家进驻微信支付品牌商家后获得的品牌ID,作为品牌唯一标识符;
2、数字,长度不超过 20 个字符。
total_num 必填 integer
【总个数】 符合查询条件的已生效交易连接名片场景总数。
active_link_list 选填 array[object]
【已生效连接列表】 返回符合查询条件的已生效交易连接名片列表。
| 属性 | |
payment_scene 必填 string 【交易场景类型】 交易场景类型是指微信支付提供的帮助商家在不同场景中快速收款的工具(如小程序支付、付款码支付等)。 可选取值
appid_list 选填 array[string(20)] 【公众账号ID列表】 公众账号ID也称 AppID,是(微信开放平台、微信公众平台)为开发者提供的一个唯一标识,用于识别开发者的应用程序(APP、小程序、公众号)。 card_link_mchid 选填 string(20) 【商户号】 商户号是商户在商户平台申请的唯一身份标识,微信支付通过商户号确认商户身份。 service_id 选填 string(50) 【服务ID】 支付分服务ID是商户支付分服务的唯一标识,由32位数字组成。支付分产品权限申请审核通过后,微信支付运营会向商户提供支付分服务ID。 |
page_index 选填 integer
【查询页码】 查询页码。从1开始,不传默认返回首页数据。
page_size 选填 integer
【查询页大小】 查询页大小。单次拉取的数据条数上限,不填默认为20,最大值50。
应答示例
200 OK
1{ 2 "brand_id" : "123456", 3 "total_num" : 1, 4 "active_link_list" : [ 5 { 6 "payment_scene" : "MINI_PROGRAM", 7 "appid_list" : [ 8 "abcd111111" 9 ], 10 "card_link_mchid" : "111222333", 11 "service_id" : "00005000000000548218251086296300" 12 } 13 ], 14 "page_index" : 1, 15 "page_size" : 10 16} 17
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
