获取微信分付曝光建议
更新时间:2025.09.29获取微信分付曝光建议
接口频率:每个商户限流200/s,上线前必须与微信支付运营确认
接口耗时:200ms
接口说明
支持商户:【普通商户】
请求方式:【POST】/v3/pay/instal/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 包体参数
mchid 必填 string(32)
【商户号】 是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式请参考普通商户模式开发必要参数说明。
appid 必填 string(32)
【商户AppID】 由微信生成的应用ID,全局唯一。是商户在微信开放平台(移动应用)或公众平台(公众号/小程序)上申请的一个唯一标识。需确保该appid与mchid有绑定关系,具体请参考普通商户模式开发必要参数说明。请求基础下单接口时请注意AppID的应用属性,例如公众号场景下,需使用应用属性为公众号的AppID。
user_id_type 必填 string
【用户ID的类型】 只能填OPENID。
可选取值
UNKNOWN_USER_ID_TYPE: 未知类型OPENID: 普通商户的OpenIDSP_OPENID: 服务商的OpenIDSUB_OPENID: 子商户的OpenID
openid 选填 string(128)
【用户标识】 用户在商户appid下的唯一标识。详见OpenID获取。若user_id_type为OPENID,则填此字段。
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/pay/instal/exposure \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "mchid" : "2600015869", 8 "appid" : "wxa9d9651ae82ec4b9", 9 "user_id_type" : "OPENID", 10 "openid" : "oLTPCuEfSOSZA6X5uR_JxNKjrGLg" 11 }' 12
需配合微信支付工具库 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 GetExposureRecommendation { 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/exposure"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 32 GetExposureRecommendation client = new GetExposureRecommendation( 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 GetExposureRecommendationRequest request = new GetExposureRecommendationRequest(); 41 request.mchid = "2600015869"; 42 request.appid = "wxa9d9651ae82ec4b9"; 43 request.userIdType = UserIdType.OPENID; 44 request.openid = "oLTPCuEfSOSZA6X5uR_JxNKjrGLg"; 45 try { 46 ExposureRecommendation 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 ExposureRecommendation run(GetExposureRecommendationRequest request) { 56 String uri = PATH; 57 String reqBody = WXPayUtility.toJson(request); 58 59 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 60 reqBuilder.addHeader("Accept", "application/json"); 61 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 62 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 63 reqBuilder.addHeader("Content-Type", "application/json"); 64 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 65 reqBuilder.method(METHOD, requestBody); 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, ExposureRecommendation.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 GetExposureRecommendation(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 GetExposureRecommendationRequest { 102 @SerializedName("mchid") 103 public String mchid; 104 105 @SerializedName("appid") 106 public String appid; 107 108 @SerializedName("user_id_type") 109 public UserIdType userIdType; 110 111 @SerializedName("openid") 112 public String openid; 113 } 114 115 public static class ExposureRecommendation { 116 @SerializedName("recommend_exposure") 117 public Boolean recommendExposure; 118 119 @SerializedName("repayment_info") 120 public List<RepaymentInfo> repaymentInfo; 121 } 122 123 public enum UserIdType { 124 @SerializedName("UNKNOWN_USER_ID_TYPE") 125 UNKNOWN_USER_ID_TYPE, 126 @SerializedName("OPENID") 127 OPENID, 128 @SerializedName("SP_OPENID") 129 SP_OPENID, 130 @SerializedName("SUB_OPENID") 131 SUB_OPENID 132 } 133 134 public static class RepaymentInfo { 135 @SerializedName("repayment_type") 136 public RepaymentType repaymentType; 137 138 @SerializedName("exist_cash_off_coupon") 139 public Boolean existCashOffCoupon; 140 } 141 142 public enum RepaymentType { 143 @SerializedName("REPAYMENT_DAILY") 144 REPAYMENT_DAILY, 145 @SerializedName("REPAYMENT_INSTALL_3") 146 REPAYMENT_INSTALL_3, 147 @SerializedName("REPAYMENT_INSTALL_6") 148 REPAYMENT_INSTALL_6, 149 @SerializedName("REPAYMENT_INSTALL_12") 150 REPAYMENT_INSTALL_12, 151 @SerializedName("REPAYMENT_INSTALL_24") 152 REPAYMENT_INSTALL_24 153 } 154 155} 156
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/merchant/4015119334 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 10) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &GetExposureRecommendationRequest{ 27 Mchid: wxpay_utility.String("2600015869"), 28 Appid: wxpay_utility.String("wxa9d9651ae82ec4b9"), 29 UserIdType: USERIDTYPE_OPENID.Ptr(), 30 Openid: wxpay_utility.String("oLTPCuEfSOSZA6X5uR_JxNKjrGLg"), 31 } 32 33 response, err := GetExposureRecommendation(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 GetExposureRecommendation(config *wxpay_utility.MchConfig, request *GetExposureRecommendationRequest) (response *ExposureRecommendation, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "POST" 48 path = "/v3/pay/instal/exposure" 49 ) 50 51 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 52 if err != nil { 53 return nil, err 54 } 55 reqBody, err := json.Marshal(request) 56 if err != nil { 57 return nil, err 58 } 59 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 60 if err != nil { 61 return nil, err 62 } 63 httpRequest.Header.Set("Accept", "application/json") 64 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 65 httpRequest.Header.Set("Content-Type", "application/json") 66 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 67 if err != nil { 68 return nil, err 69 } 70 httpRequest.Header.Set("Authorization", authorization) 71 72 client := &http.Client{} 73 httpResponse, err := client.Do(httpRequest) 74 if err != nil { 75 return nil, err 76 } 77 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 78 if err != nil { 79 return nil, err 80 } 81 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 82 // 2XX 成功,验证应答签名 83 err = wxpay_utility.ValidateResponse( 84 config.WechatPayPublicKeyId(), 85 config.WechatPayPublicKey(), 86 &httpResponse.Header, 87 respBody, 88 ) 89 if err != nil { 90 return nil, err 91 } 92 response := &ExposureRecommendation{} 93 if err := json.Unmarshal(respBody, response); err != nil { 94 return nil, err 95 } 96 97 return response, nil 98 } else { 99 return nil, wxpay_utility.NewApiException( 100 httpResponse.StatusCode, 101 httpResponse.Header, 102 respBody, 103 ) 104 } 105} 106 107type GetExposureRecommendationRequest struct { 108 Mchid *string `json:"mchid,omitempty"` 109 Appid *string `json:"appid,omitempty"` 110 UserIdType *UserIdType `json:"user_id_type,omitempty"` 111 Openid *string `json:"openid,omitempty"` 112} 113 114type ExposureRecommendation struct { 115 RecommendExposure *bool `json:"recommend_exposure,omitempty"` 116 RepaymentInfo []RepaymentInfo `json:"repayment_info,omitempty"` 117} 118 119type UserIdType string 120 121func (e UserIdType) Ptr() *UserIdType { 122 return &e 123} 124 125const ( 126 USERIDTYPE_UNKNOWN_USER_ID_TYPE UserIdType = "UNKNOWN_USER_ID_TYPE" 127 USERIDTYPE_OPENID UserIdType = "OPENID" 128 USERIDTYPE_SP_OPENID UserIdType = "SP_OPENID" 129 USERIDTYPE_SUB_OPENID UserIdType = "SUB_OPENID" 130) 131 132type RepaymentInfo struct { 133 RepaymentType *RepaymentType `json:"repayment_type,omitempty"` 134 ExistCashOffCoupon *bool `json:"exist_cash_off_coupon,omitempty"` 135} 136 137type RepaymentType string 138 139func (e RepaymentType) Ptr() *RepaymentType { 140 return &e 141} 142 143const ( 144 REPAYMENTTYPE_REPAYMENT_DAILY RepaymentType = "REPAYMENT_DAILY" 145 REPAYMENTTYPE_REPAYMENT_INSTALL_3 RepaymentType = "REPAYMENT_INSTALL_3" 146 REPAYMENTTYPE_REPAYMENT_INSTALL_6 RepaymentType = "REPAYMENT_INSTALL_6" 147 REPAYMENTTYPE_REPAYMENT_INSTALL_12 RepaymentType = "REPAYMENT_INSTALL_12" 148 REPAYMENTTYPE_REPAYMENT_INSTALL_24 RepaymentType = "REPAYMENT_INSTALL_24" 149) 150
应答参数
折叠全部参数
200 OK
recommend_exposure 必填 boolean
【是否建议曝光微信分付】 是否建议曝光微信分付
repayment_info 选填 array[object]
【还款信息】 用户可享受的平台优惠信息(例如:该用户有分付12期的立减优惠,则返回12期平台优惠信息),用户是否有优惠由平台的活动决定。该字段仅当用户有可享受的平台优惠时返回。
| 属性 | |
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
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
