获取微信分付曝光建议
更新时间:2025.09.29获取微信分付曝光建议
接口说明
支持商户:【普通服务商】 【平台商户】
请求方式:【POST】/v3/pay/instal/partner/exposure
请求域名:【主域名】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)
【服务商商户号】 是由微信支付系统生成并分配给每个服务商的唯一标识符,具体请参考服务商模式开发必要参数说明。
sp_appid 必填 string(32)
【服务商AppID】 是服务商在微信开放平台(移动应用)或公众平台(公众号/小程序)上申请的一个唯一标识。需确保该sp_appid与sp_mchid有绑定关系,具体请参考服务商模式开发必要参数说明。
sub_mchid 选填 string(32)
【子商户号/二级商户号】 如果是子商户参与商户贴息,必传子商户号;如果是服务商参与商户贴息,不应传子商户号。具体请参考服务商模式开发必要参数说明。
sub_appid 选填 string(32)
【子商户/二级商户应用ID】 子商户/二级商户在微信开放平台(移动应用)或公众平台(公众号/小程序)上申请的一个唯一标识。需确保该sub_appid与sub_mchid有绑定关系,具体请参考服务商模式开发必要参数说明。
user_id 必填 object
【用户ID】 微信用户的唯一标识
| 属性 | |
user_id_type 必填 string 【用户ID的类型】 如果是服务商的OpenID,填 可选取值
sp_openid 选填 string(128) 【用户服务标识】 用户在服务商AppID下的唯一标识。获取方式详见参数说明。sp_openid和sub_openid只传其中之一。 sub_openid 选填 string(128) 【用户子标识】 用户在子商户AppID下的唯一标识。获取方式详见参数说明。sp_openid和sub_openid只传其中之一。若传sub_openid,则必填sub_appid。 |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/pay/instal/partner/exposure \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "sp_mchid" : "2600015869", 8 "sp_appid" : "wxa9d9651ae82ec4b9", 9 "sub_mchid" : "2600015869", 10 "sub_appid" : "wxa9d9651ae82ec4b9", 11 "user_id" : { 12 "user_id_type" : "SP_OPENID", 13 "sp_openid" : "oLTPCuEfSOSZA6X5uR_JxNKjrGLg", 14 "sub_openid" : "oLTPCuEfSOSZA6X5uR_JxNKjrGLg" 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 GetPartnerExposureRecommendation { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/pay/instal/partner/exposure"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 GetPartnerExposureRecommendation client = new GetPartnerExposureRecommendation( 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 GetPartnerExposureRecommendationRequest request = new GetPartnerExposureRecommendationRequest(); 41 request.spMchid = "2600015869"; 42 request.spAppid = "wxa9d9651ae82ec4b9"; 43 request.subMchid = "2600015869"; 44 request.subAppid = "wxa9d9651ae82ec4b9"; 45 request.userId = new UserId(); 46 request.userId.userIdType = UserIdType.SP_OPENID; 47 request.userId.spOpenid = "oLTPCuEfSOSZA6X5uR_JxNKjrGLg"; 48 request.userId.subOpenid = "oLTPCuEfSOSZA6X5uR_JxNKjrGLg"; 49 try { 50 ExposureRecommendation response = client.run(request); 51 // TODO: 请求成功,继续业务逻辑 52 System.out.println(response); 53 } catch (WXPayUtility.ApiException e) { 54 // TODO: 请求失败,根据状态码执行不同的逻辑 55 e.printStackTrace(); 56 } 57 } 58 59 public ExposureRecommendation run(GetPartnerExposureRecommendationRequest request) { 60 String uri = PATH; 61 String reqBody = WXPayUtility.toJson(request); 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, reqBody)); 67 reqBuilder.addHeader("Content-Type", "application/json"); 68 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 69 reqBuilder.method(METHOD, requestBody); 70 Request httpRequest = reqBuilder.build(); 71 72 // 发送HTTP请求 73 OkHttpClient client = new OkHttpClient.Builder().build(); 74 try (Response httpResponse = client.newCall(httpRequest).execute()) { 75 String respBody = WXPayUtility.extractBody(httpResponse); 76 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 77 // 2XX 成功,验证应答签名 78 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 79 httpResponse.headers(), respBody); 80 81 // 从HTTP应答报文构建返回数据 82 return WXPayUtility.fromJson(respBody, ExposureRecommendation.class); 83 } else { 84 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 85 } 86 } catch (IOException e) { 87 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 88 } 89 } 90 91 private final String mchid; 92 private final String certificateSerialNo; 93 private final PrivateKey privateKey; 94 private final String wechatPayPublicKeyId; 95 private final PublicKey wechatPayPublicKey; 96 97 public GetPartnerExposureRecommendation(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 98 this.mchid = mchid; 99 this.certificateSerialNo = certificateSerialNo; 100 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 101 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 102 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 103 } 104 105 public static class GetPartnerExposureRecommendationRequest { 106 @SerializedName("sp_mchid") 107 public String spMchid; 108 109 @SerializedName("sp_appid") 110 public String spAppid; 111 112 @SerializedName("sub_mchid") 113 public String subMchid; 114 115 @SerializedName("sub_appid") 116 public String subAppid; 117 118 @SerializedName("user_id") 119 public UserId userId; 120 } 121 122 public static class ExposureRecommendation { 123 @SerializedName("recommend_exposure") 124 public Boolean recommendExposure; 125 126 @SerializedName("repayment_info") 127 public List<RepaymentInfo> repaymentInfo; 128 } 129 130 public static class UserId { 131 @SerializedName("user_id_type") 132 public UserIdType userIdType; 133 134 @SerializedName("sp_openid") 135 public String spOpenid; 136 137 @SerializedName("sub_openid") 138 public String subOpenid; 139 } 140 141 public static class RepaymentInfo { 142 @SerializedName("repayment_type") 143 public RepaymentType repaymentType; 144 145 @SerializedName("exist_cash_off_coupon") 146 public Boolean existCashOffCoupon; 147 } 148 149 public enum UserIdType { 150 @SerializedName("UNKNOWN_USER_ID_TYPE") 151 UNKNOWN_USER_ID_TYPE, 152 @SerializedName("OPENID") 153 OPENID, 154 @SerializedName("SP_OPENID") 155 SP_OPENID, 156 @SerializedName("SUB_OPENID") 157 SUB_OPENID 158 } 159 160 public enum RepaymentType { 161 @SerializedName("REPAYMENT_DAILY") 162 REPAYMENT_DAILY, 163 @SerializedName("REPAYMENT_INSTALL_3") 164 REPAYMENT_INSTALL_3, 165 @SerializedName("REPAYMENT_INSTALL_6") 166 REPAYMENT_INSTALL_6, 167 @SerializedName("REPAYMENT_INSTALL_12") 168 REPAYMENT_INSTALL_12, 169 @SerializedName("REPAYMENT_INSTALL_24") 170 REPAYMENT_INSTALL_24 171 } 172 173} 174
需配合微信支付工具库 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) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &GetPartnerExposureRecommendationRequest{ 27 SpMchid: wxpay_utility.String("2600015869"), 28 SpAppid: wxpay_utility.String("wxa9d9651ae82ec4b9"), 29 SubMchid: wxpay_utility.String("2600015869"), 30 SubAppid: wxpay_utility.String("wxa9d9651ae82ec4b9"), 31 UserId: &UserId{ 32 UserIdType: USERIDTYPE_SP_OPENID.Ptr(), 33 SpOpenid: wxpay_utility.String("oLTPCuEfSOSZA6X5uR_JxNKjrGLg"), 34 SubOpenid: wxpay_utility.String("oLTPCuEfSOSZA6X5uR_JxNKjrGLg"), 35 }, 36 } 37 38 response, err := GetPartnerExposureRecommendation(config, request) 39 if err != nil { 40 fmt.Printf("请求失败: %+v\n", err) 41 // TODO: 请求失败,根据状态码执行不同的处理 42 return 43 } 44 45 // TODO: 请求成功,继续业务逻辑 46 fmt.Printf("请求成功: %+v\n", response) 47} 48 49func GetPartnerExposureRecommendation(config *wxpay_utility.MchConfig, request *GetPartnerExposureRecommendationRequest) (response *ExposureRecommendation, err error) { 50 const ( 51 host = "https://api.mch.weixin.qq.com" 52 method = "POST" 53 path = "/v3/pay/instal/partner/exposure" 54 ) 55 56 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 57 if err != nil { 58 return nil, err 59 } 60 reqBody, err := json.Marshal(request) 61 if err != nil { 62 return nil, err 63 } 64 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 65 if err != nil { 66 return nil, err 67 } 68 httpRequest.Header.Set("Accept", "application/json") 69 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 70 httpRequest.Header.Set("Content-Type", "application/json") 71 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 72 if err != nil { 73 return nil, err 74 } 75 httpRequest.Header.Set("Authorization", authorization) 76 77 client := &http.Client{} 78 httpResponse, err := client.Do(httpRequest) 79 if err != nil { 80 return nil, err 81 } 82 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 83 if err != nil { 84 return nil, err 85 } 86 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 87 // 2XX 成功,验证应答签名 88 err = wxpay_utility.ValidateResponse( 89 config.WechatPayPublicKeyId(), 90 config.WechatPayPublicKey(), 91 &httpResponse.Header, 92 respBody, 93 ) 94 if err != nil { 95 return nil, err 96 } 97 response := &ExposureRecommendation{} 98 if err := json.Unmarshal(respBody, response); err != nil { 99 return nil, err 100 } 101 102 return response, nil 103 } else { 104 return nil, wxpay_utility.NewApiException( 105 httpResponse.StatusCode, 106 httpResponse.Header, 107 respBody, 108 ) 109 } 110} 111 112type GetPartnerExposureRecommendationRequest struct { 113 SpMchid *string `json:"sp_mchid,omitempty"` 114 SpAppid *string `json:"sp_appid,omitempty"` 115 SubMchid *string `json:"sub_mchid,omitempty"` 116 SubAppid *string `json:"sub_appid,omitempty"` 117 UserId *UserId `json:"user_id,omitempty"` 118} 119 120type ExposureRecommendation struct { 121 RecommendExposure *bool `json:"recommend_exposure,omitempty"` 122 RepaymentInfo []RepaymentInfo `json:"repayment_info,omitempty"` 123} 124 125type UserId struct { 126 UserIdType *UserIdType `json:"user_id_type,omitempty"` 127 SpOpenid *string `json:"sp_openid,omitempty"` 128 SubOpenid *string `json:"sub_openid,omitempty"` 129} 130 131type RepaymentInfo struct { 132 RepaymentType *RepaymentType `json:"repayment_type,omitempty"` 133 ExistCashOffCoupon *bool `json:"exist_cash_off_coupon,omitempty"` 134} 135 136type UserIdType string 137 138func (e UserIdType) Ptr() *UserIdType { 139 return &e 140} 141 142const ( 143 USERIDTYPE_UNKNOWN_USER_ID_TYPE UserIdType = "UNKNOWN_USER_ID_TYPE" 144 USERIDTYPE_OPENID UserIdType = "OPENID" 145 USERIDTYPE_SP_OPENID UserIdType = "SP_OPENID" 146 USERIDTYPE_SUB_OPENID UserIdType = "SUB_OPENID" 147) 148 149type RepaymentType string 150 151func (e RepaymentType) Ptr() *RepaymentType { 152 return &e 153} 154 155const ( 156 REPAYMENTTYPE_REPAYMENT_DAILY RepaymentType = "REPAYMENT_DAILY" 157 REPAYMENTTYPE_REPAYMENT_INSTALL_3 RepaymentType = "REPAYMENT_INSTALL_3" 158 REPAYMENTTYPE_REPAYMENT_INSTALL_6 RepaymentType = "REPAYMENT_INSTALL_6" 159 REPAYMENTTYPE_REPAYMENT_INSTALL_12 RepaymentType = "REPAYMENT_INSTALL_12" 160 REPAYMENTTYPE_REPAYMENT_INSTALL_24 RepaymentType = "REPAYMENT_INSTALL_24" 161) 162
应答参数
200 OK
recommend_exposure 必填 boolean
【是否建议曝光微信分付】 是否建议曝光微信分付
repayment_info 选填 array[object]
【还款信息】 每种还款方式对应的优惠信息。仅当商户有适用的优惠信息时返回。
| 属性 | |
repayment_type 必填 string 【还款方式】 还款方式 可选取值
exist_cash_off_coupon 必填 boolean 【是否存在平台优惠】 使用微信分付支付时该商户是否有可用的平台优惠。 |
应答示例
200 OK
1{ 2 "recommend_exposure" : true, 3 "repayment_info" : [ 4 { 5 "repayment_type" : "REPAYMENT_INSTALL_12", 6 "exist_cash_off_coupon" : true 7 } 8 ] 9} 10
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示

