查询商户影像件资料
更新时间:2026.07.14查询商户影像件资料
接口限频:接口维度100次/分钟
接口说明
支持商户:【普通商户】
请求方式:【GET】/v3/aggracct-bc/wb-channel/account/mch_media
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
query 查询参数
mchid 选填 string
【微信支付商户号】 当business_scene=GET_BY_MEDIA_ID时必填。
platform_trx_id 选填 string
【微信支付业务申请单号】 当business_scene=SJT_MICRO_PLUS_OPEN_ACCOUNT或者SJT_MICRO_PLUS_UPDATE_INFO时必填。
商家通小微+开户场景:填“微信开户申请单号”;商家通小微+资料更新:“资料更新请求单号”
business_scene 选填 string
【业务场景(必填)】
可选取值
SJT_MICRO_PLUS_OPEN_ACCOUNT: 商家通小微+开户场景SJT_MICRO_PLUS_UPDATE_INFO: 商家通小微+资料更新GET_BY_MEDIA_ID: 获取指定影像件资料
mch_media_type 选填 string
【影像件类型】 当business_scene=SJT_MICRO_PLUS_OPEN_ACCOUNT或者SJT_MICRO_PLUS_UPDATE_INFO时必填。
可选取值
ID_CARD_FRONT: 证件照片正面ID_CARD_BACK: 证件照片反面STORE_FRONT: 店面照片STORE_INTERIOR: 店内照片
media_id 选填 string
【影像件资料ID】 当business_scene=GET_BY_MEDIA_ID时必填。
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/aggracct-bc/wb-channel/account/mch_media?mchid=mchid_example&platform_trx_id=platform_trx_id_example&business_scene=SJT_MICRO_PLUS_OPEN_ACCOUNT&mch_media_type=ID_CARD_FRONT&media_id=media_id_example \ 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/merchant/4014931831 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 GetMchMedia { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/aggracct-bc/wb-channel/account/mch_media"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 32 GetMchMedia client = new GetMchMedia( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 GetMchMediaRequest request = new GetMchMediaRequest(); 41 request.mchid = "mchid_example"; 42 request.platformTrxId = "platformTrxId_example"; 43 request.businessScene = GetMchMediaBusinessScene.SJT_MICRO_PLUS_OPEN_ACCOUNT; 44 request.mchMediaType = MchMediaType.ID_CARD_FRONT; 45 request.mediaId = "mediaId_example"; 46 try { 47 GetMchMediaResponse response = client.run(request); 48 // TODO: 请求成功,继续业务逻辑 49 System.out.println(response); 50 } catch (WXPayUtility.ApiException e) { 51 // TODO: 请求失败,根据状态码执行不同的逻辑 52 e.printStackTrace(); 53 } 54 } 55 56 public GetMchMediaResponse run(GetMchMediaRequest request) { 57 String uri = PATH; 58 Map<String, Object> args = new HashMap<>(); 59 args.put("mchid", request.mchid); 60 args.put("platform_trx_id", request.platformTrxId); 61 args.put("business_scene", request.businessScene); 62 args.put("mch_media_type", request.mchMediaType); 63 args.put("media_id", request.mediaId); 64 String queryString = WXPayUtility.urlEncode(args); 65 if (!queryString.isEmpty()) { 66 uri = uri + "?" + queryString; 67 } 68 69 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 70 reqBuilder.addHeader("Accept", "application/json"); 71 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 72 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 73 reqBuilder.method(METHOD, null); 74 Request httpRequest = reqBuilder.build(); 75 76 // 发送HTTP请求 77 OkHttpClient client = new OkHttpClient.Builder().build(); 78 try (Response httpResponse = client.newCall(httpRequest).execute()) { 79 String respBody = WXPayUtility.extractBody(httpResponse); 80 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 81 // 2XX 成功,验证应答签名 82 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 83 httpResponse.headers(), respBody); 84 85 // 从HTTP应答报文构建返回数据 86 return WXPayUtility.fromJson(respBody, GetMchMediaResponse.class); 87 } else { 88 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 89 } 90 } catch (IOException e) { 91 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 92 } 93 } 94 95 private final String mchid; 96 private final String certificateSerialNo; 97 private final PrivateKey privateKey; 98 private final String wechatPayPublicKeyId; 99 private final PublicKey wechatPayPublicKey; 100 101 public GetMchMedia(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 102 this.mchid = mchid; 103 this.certificateSerialNo = certificateSerialNo; 104 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 105 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 106 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 107 } 108 109 public static class GetMchMediaRequest { 110 @SerializedName("mchid") 111 @Expose(serialize = false) 112 public String mchid; 113 114 @SerializedName("platform_trx_id") 115 @Expose(serialize = false) 116 public String platformTrxId; 117 118 @SerializedName("media_id") 119 @Expose(serialize = false) 120 public String mediaId; 121 122 @SerializedName("business_scene") 123 @Expose(serialize = false) 124 public GetMchMediaBusinessScene businessScene; 125 126 @SerializedName("mch_media_type") 127 @Expose(serialize = false) 128 public MchMediaType mchMediaType; 129 } 130 131 public static class GetMchMediaResponse { 132 @SerializedName("media_content") 133 public String mediaContent; 134 135 @SerializedName("media_type") 136 public String mediaType; 137 138 @SerializedName("media_sm3") 139 public String mediaSm3; 140 141 @SerializedName("key") 142 public String key; 143 144 @SerializedName("media_id") 145 public String mediaId; 146 } 147 148 public enum GetMchMediaBusinessScene { 149 @SerializedName("SJT_MICRO_PLUS_OPEN_ACCOUNT") 150 SJT_MICRO_PLUS_OPEN_ACCOUNT, 151 @SerializedName("SJT_MICRO_PLUS_UPDATE_INFO") 152 SJT_MICRO_PLUS_UPDATE_INFO, 153 @SerializedName("GET_BY_MEDIA_ID") 154 GET_BY_MEDIA_ID 155 } 156 157 public enum MchMediaType { 158 @SerializedName("ID_CARD_FRONT") 159 ID_CARD_FRONT, 160 @SerializedName("ID_CARD_BACK") 161 ID_CARD_BACK, 162 @SerializedName("STORE_FRONT") 163 STORE_FRONT, 164 @SerializedName("STORE_INTERIOR") 165 STORE_INTERIOR 166 } 167 168} 169
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/merchant/4015119334 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9) 10 11func main() { 12 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 13 config, err := wxpay_utility.CreateMchConfig( 14 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 15 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 16 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 17 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 18 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 19 ) 20 if err != nil { 21 fmt.Println(err) 22 return 23 } 24 25 request := &GetMchMediaRequest{ 26 Mchid: wxpay_utility.String("Mchid_example"), 27 PlatformTrxId: wxpay_utility.String("PlatformTrxId_example"), 28 BusinessScene: GETMCHMEDIABUSINESSSCENE_SJT_MICRO_PLUS_OPEN_ACCOUNT.Ptr(), 29 MchMediaType: MCHMEDIATYPE_ID_CARD_FRONT.Ptr(), 30 MediaId: wxpay_utility.String("MediaId_example"), 31 } 32 33 response, err := GetMchMedia(config, request) 34 if err != nil { 35 fmt.Printf("请求失败: %+v\n", err) 36 // TODO: 请求失败,根据状态码执行不同的处理 37 return 38 } 39 40 // TODO: 请求成功,继续业务逻辑 41 fmt.Printf("请求成功: %+v\n", response) 42} 43 44func GetMchMedia(config *wxpay_utility.MchConfig, request *GetMchMediaRequest) (response *GetMchMediaResponse, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "GET" 48 path = "/v3/aggracct-bc/wb-channel/account/mch_media" 49 ) 50 51 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 52 if err != nil { 53 return nil, err 54 } 55 query := reqUrl.Query() 56 if request.Mchid != nil { 57 query.Add("mchid", *request.Mchid) 58 } 59 if request.PlatformTrxId != nil { 60 query.Add("platform_trx_id", *request.PlatformTrxId) 61 } 62 if request.BusinessScene != nil { 63 query.Add("business_scene", fmt.Sprintf("%v", *request.BusinessScene)) 64 } 65 if request.MchMediaType != nil { 66 query.Add("mch_media_type", fmt.Sprintf("%v", *request.MchMediaType)) 67 } 68 if request.MediaId != nil { 69 query.Add("media_id", *request.MediaId) 70 } 71 reqUrl.RawQuery = query.Encode() 72 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 73 if err != nil { 74 return nil, err 75 } 76 httpRequest.Header.Set("Accept", "application/json") 77 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 78 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 79 if err != nil { 80 return nil, err 81 } 82 httpRequest.Header.Set("Authorization", authorization) 83 84 client := &http.Client{} 85 httpResponse, err := client.Do(httpRequest) 86 if err != nil { 87 return nil, err 88 } 89 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 90 if err != nil { 91 return nil, err 92 } 93 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 94 // 2XX 成功,验证应答签名 95 err = wxpay_utility.ValidateResponse( 96 config.WechatPayPublicKeyId(), 97 config.WechatPayPublicKey(), 98 &httpResponse.Header, 99 respBody, 100 ) 101 if err != nil { 102 return nil, err 103 } 104 response := &GetMchMediaResponse{} 105 if err := json.Unmarshal(respBody, response); err != nil { 106 return nil, err 107 } 108 109 return response, nil 110 } else { 111 return nil, wxpay_utility.NewApiException( 112 httpResponse.StatusCode, 113 httpResponse.Header, 114 respBody, 115 ) 116 } 117} 118 119type GetMchMediaRequest struct { 120 Mchid *string `json:"mchid,omitempty"` 121 PlatformTrxId *string `json:"platform_trx_id,omitempty"` 122 MediaId *string `json:"media_id,omitempty"` 123 BusinessScene *GetMchMediaBusinessScene `json:"business_scene,omitempty"` 124 MchMediaType *MchMediaType `json:"mch_media_type,omitempty"` 125} 126 127func (o *GetMchMediaRequest) MarshalJSON() ([]byte, error) { 128 type Alias GetMchMediaRequest 129 a := &struct { 130 Mchid *string `json:"mchid,omitempty"` 131 PlatformTrxId *string `json:"platform_trx_id,omitempty"` 132 MediaId *string `json:"media_id,omitempty"` 133 BusinessScene *GetMchMediaBusinessScene `json:"business_scene,omitempty"` 134 MchMediaType *MchMediaType `json:"mch_media_type,omitempty"` 135 *Alias 136 }{ 137 // 序列化时移除非 Body 字段 138 Mchid: nil, 139 PlatformTrxId: nil, 140 MediaId: nil, 141 BusinessScene: nil, 142 MchMediaType: nil, 143 Alias: (*Alias)(o), 144 } 145 return json.Marshal(a) 146} 147 148type GetMchMediaResponse struct { 149 MediaContent *string `json:"media_content,omitempty"` 150 MediaType *string `json:"media_type,omitempty"` 151 MediaSm3 *string `json:"media_sm3,omitempty"` 152 Key *string `json:"key,omitempty"` 153 MediaId *string `json:"media_id,omitempty"` 154} 155 156type GetMchMediaBusinessScene string 157 158func (e GetMchMediaBusinessScene) Ptr() *GetMchMediaBusinessScene { 159 return &e 160} 161 162const ( 163 GETMCHMEDIABUSINESSSCENE_SJT_MICRO_PLUS_OPEN_ACCOUNT GetMchMediaBusinessScene = "SJT_MICRO_PLUS_OPEN_ACCOUNT" 164 GETMCHMEDIABUSINESSSCENE_SJT_MICRO_PLUS_UPDATE_INFO GetMchMediaBusinessScene = "SJT_MICRO_PLUS_UPDATE_INFO" 165 GETMCHMEDIABUSINESSSCENE_GET_BY_MEDIA_ID GetMchMediaBusinessScene = "GET_BY_MEDIA_ID" 166) 167 168type MchMediaType string 169 170func (e MchMediaType) Ptr() *MchMediaType { 171 return &e 172} 173 174const ( 175 MCHMEDIATYPE_ID_CARD_FRONT MchMediaType = "ID_CARD_FRONT" 176 MCHMEDIATYPE_ID_CARD_BACK MchMediaType = "ID_CARD_BACK" 177 MCHMEDIATYPE_STORE_FRONT MchMediaType = "STORE_FRONT" 178 MCHMEDIATYPE_STORE_INTERIOR MchMediaType = "STORE_INTERIOR" 179) 180
应答参数
200 OK
media_content 选填 string
【文件内容】 原始图片文件 → zip压缩 → sm4加密 ->base64 (RFC4648)
media_type 选填 string
【文件类型】 jpg / png / bmp / jpeg
media_sm3 选填 string
【文件摘要】 普通SM3(针对zip计算摘要),用hex编码(小写)
key 选填 string
【sm4密钥】 SM4密钥
media_id 选填 string
【影像件资料ID】
应答示例
200 OK
1{ 2 "media_content" : "example_media_content", 3 "media_type" : "example_media_type", 4 "media_sm3" : "example_media_sm3", 5 "key" : "example_key", 6 "media_id" : "example_media_id" 7} 8
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
