获取商品券事件通知地址
更新时间:2025.08.04服务商可以通过本接口查询商品券相关事件的回调地址,该地址配置为服务商维度配置,该服务商下的所有商品券相关事件均会通知到该地址。
前置条件:服务商已经配置商品券事件通知地址
频率限制:20/s
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/marketing/partner/product-coupon/notify-configs
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
请求示例
curl
Java
Go
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/marketing/partner/product-coupon/notify-configs \ 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 GetNotifyConfig { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/marketing/partner/product-coupon/notify-configs"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 GetNotifyConfig client = new GetNotifyConfig( 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 try { 41 GetNotifyConfigResponse response = client.run(); 42 // TODO: 请求成功,继续业务逻辑 43 System.out.println(response); 44 } catch (WXPayUtility.ApiException e) { 45 // TODO: 请求失败,根据状态码执行不同的逻辑 46 e.printStackTrace(); 47 } 48 } 49 50 public GetNotifyConfigResponse run() { 51 String uri = PATH; 52 53 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 54 reqBuilder.addHeader("Accept", "application/json"); 55 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 56 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 57 reqBuilder.method(METHOD, null); 58 Request httpRequest = reqBuilder.build(); 59 60 // 发送HTTP请求 61 OkHttpClient client = new OkHttpClient.Builder().build(); 62 try (Response httpResponse = client.newCall(httpRequest).execute()) { 63 String respBody = WXPayUtility.extractBody(httpResponse); 64 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 65 // 2XX 成功,验证应答签名 66 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 67 httpResponse.headers(), respBody); 68 69 // 从HTTP应答报文构建返回数据 70 return WXPayUtility.fromJson(respBody, GetNotifyConfigResponse.class); 71 } else { 72 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 73 } 74 } catch (IOException e) { 75 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 76 } 77 } 78 79 private final String mchid; 80 private final String certificateSerialNo; 81 private final PrivateKey privateKey; 82 private final String wechatPayPublicKeyId; 83 private final PublicKey wechatPayPublicKey; 84 85 public GetNotifyConfig(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 86 this.mchid = mchid; 87 this.certificateSerialNo = certificateSerialNo; 88 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 89 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 90 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 91 } 92 93 public static class GetNotifyConfigResponse { 94 @SerializedName("notify_url") 95 public String notifyUrl; 96 97 @SerializedName("update_time") 98 public String updateTime; 99 } 100 101} 102
需配合微信支付工具库 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 "time" 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 response, err := GetNotifyConfig(config) 27 if err != nil { 28 fmt.Printf("请求失败: %+v\n", err) 29 // TODO: 请求失败,根据状态码执行不同的处理 30 return 31 } 32 33 // TODO: 请求成功,继续业务逻辑 34 fmt.Printf("请求成功: %+v\n", response) 35} 36 37func GetNotifyConfig(config *wxpay_utility.MchConfig) (response *GetNotifyConfigResponse, err error) { 38 const ( 39 host = "https://api.mch.weixin.qq.com" 40 method = "GET" 41 path = "/v3/marketing/partner/product-coupon/notify-configs" 42 ) 43 44 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 45 if err != nil { 46 return nil, err 47 } 48 if err != nil { 49 return nil, err 50 } 51 httpRequest.Header.Set("Accept", "application/json") 52 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 53 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 54 if err != nil { 55 return nil, err 56 } 57 httpRequest.Header.Set("Authorization", authorization) 58 59 client := &http.Client{} 60 httpResponse, err := client.Do(httpRequest) 61 if err != nil { 62 return nil, err 63 } 64 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 65 if err != nil { 66 return nil, err 67 } 68 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 69 // 2XX 成功,验证应答签名 70 err = wxpay_utility.ValidateResponse( 71 config.WechatPayPublicKeyId(), 72 config.WechatPayPublicKey(), 73 &httpResponse.Header, 74 respBody, 75 ) 76 if err != nil { 77 return nil, err 78 } 79 response := &GetNotifyConfigResponse{} 80 if err := json.Unmarshal(respBody, response); err != nil { 81 return nil, err 82 } 83 84 return response, nil 85 } else { 86 return nil, wxpay_utility.NewApiException( 87 httpResponse.StatusCode, 88 httpResponse.Header, 89 respBody, 90 ) 91 } 92} 93 94type GetNotifyConfigResponse struct { 95 NotifyUrl *string `json:"notify_url,omitempty"` 96 UpdateTime *time.Time `json:"update_time,omitempty"` 97} 98
应答参数
200 OK
notify_url 必填 string
【通知URL地址】 服务商通过设置商品券事件通知接口设置的用于接收商品券事件通知的URL地址,原样返回
update_time 必填 string
【更新时间】 遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
应答示例
200 OK
1{ 2 "notify_url" : "https://www.example.com/notify", 3 "update_time" : "2025-01-01T00:00+08:00" 4} 5
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
文档是否有帮助
