所有URI均基于微信支付 API 地址: https://api.mch.weixin.qq.com
方法名 | HTTP 请求 | 描述 |
---|---|---|
AssociateTradeInfo | Post /v3/marketing/busifavor/coupons/associate | 关联订单信息 |
DeactivateCoupon | Post /v3/marketing/busifavor/coupons/deactivate | 使券失效 |
DisassociateTradeInfo | Post /v3/marketing/busifavor/coupons/disassociate | 取消关联订单信息 |
ListCouponsByFilter | Get /v3/marketing/busifavor/users/{openid}/coupons | 根据过滤条件查询用户的券 |
QueryCoupon | Get /v3/marketing/busifavor/users/{openid}/coupons/{coupon_code}/appids/{appid} | 查询用户券详情 |
ReturnCoupon | Post /v3/marketing/busifavor/coupons/return | 申请退券 |
SendCoupon | Post /v3/marketing/busifavor/coupons/send | 向用户发券 |
SendGovCard | Post /v3/marketing/busifavor/coupons/{card_id}/send | 发放政府消费卡 |
UseCoupon | Post /v3/marketing/busifavor/coupons/use | 核销用户的券 |
AssociateTradeInfoResponse AssociateTradeInfo(AssociateTradeInfoRequest)
关联订单信息
package main
import (
"context"
"log"
"git.nanodreamtech.com/sg/wechatpay-go/core"
"git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
"git.nanodreamtech.com/sg/wechatpay-go/utils"
)
func main() {
var (
mchID string = "190000****" // 商户号
mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
)
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
if err != nil {
log.Printf("load merchant private key error:%s", err)
return
}
ctx := context.Background()
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Printf("new wechat pay client err:%s", err)
return
}
svc := merchantexclusivecoupon.CouponApiService{Client: client}
resp, result, err := svc.AssociateTradeInfo(ctx,
merchantexclusivecoupon.AssociateTradeInfoRequest{
StockId: core.String("100088"),
CouponCode: core.String("sxxe34343434"),
OutTradeNo: core.String("MCH_102233445"),
OutRequestNo: core.String("1002600620019090123143254435"),
},
)
if err != nil {
// 处理错误
log.Printf("call AssociateTradeInfo err:%s", err)
} else {
// 处理返回结果
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
}
}
参数名 | 参数类型 | 参数描述 |
---|---|---|
ctx | context.Context | Golang 上下文,可用于日志、请求取消、请求跟踪等功能 |
req | AssociateTradeInfoRequest | API merchantexclusivecoupon 所定义的本接口需要的所有参数,包括Path /Query /Body 3类参数 |
Name | Type | Description |
---|---|---|
resp | *AssociateTradeInfoResponse | 结构化的接口返回结果 |
result | *core.APIResult | 本次 API 访问的请求与应答信息 |
err | error | 本次 API 访问中发生的错误,当且仅当 API 失败时存在 |
[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]
DeactivateCouponResponse DeactivateCoupon(DeactivateCouponRequest)
使券失效
package main
import (
"context"
"log"
"git.nanodreamtech.com/sg/wechatpay-go/core"
"git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
"git.nanodreamtech.com/sg/wechatpay-go/utils"
)
func main() {
var (
mchID string = "190000****" // 商户号
mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
)
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
if err != nil {
log.Printf("load merchant private key error:%s", err)
return
}
ctx := context.Background()
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Printf("new wechat pay client err:%s", err)
return
}
svc := merchantexclusivecoupon.CouponApiService{Client: client}
resp, result, err := svc.DeactivateCoupon(ctx,
merchantexclusivecoupon.DeactivateCouponRequest{
CouponCode: core.String("sxxe34343434"),
StockId: core.String("1234567891"),
DeactivateRequestNo: core.String("1002600620019090123143254436"),
DeactivateReason: core.String("此券使用时间设置错误"),
},
)
if err != nil {
// 处理错误
log.Printf("call DeactivateCoupon err:%s", err)
} else {
// 处理返回结果
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
}
}
参数名 | 参数类型 | 参数描述 |
---|---|---|
ctx | context.Context | Golang 上下文,可用于日志、请求取消、请求跟踪等功能 |
req | DeactivateCouponRequest | API merchantexclusivecoupon 所定义的本接口需要的所有参数,包括Path /Query /Body 3类参数 |
Name | Type | Description |
---|---|---|
resp | *DeactivateCouponResponse | 结构化的接口返回结果 |
result | *core.APIResult | 本次 API 访问的请求与应答信息 |
err | error | 本次 API 访问中发生的错误,当且仅当 API 失败时存在 |
[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]
DisassociateTradeInfoResponse DisassociateTradeInfo(DisassociateTradeInfoRequest)
取消关联订单信息
package main
import (
"context"
"log"
"git.nanodreamtech.com/sg/wechatpay-go/core"
"git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
"git.nanodreamtech.com/sg/wechatpay-go/utils"
)
func main() {
var (
mchID string = "190000****" // 商户号
mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
)
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
if err != nil {
log.Printf("load merchant private key error:%s", err)
return
}
ctx := context.Background()
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Printf("new wechat pay client err:%s", err)
return
}
svc := merchantexclusivecoupon.CouponApiService{Client: client}
resp, result, err := svc.DisassociateTradeInfo(ctx,
merchantexclusivecoupon.DisassociateTradeInfoRequest{
StockId: core.String("100088"),
CouponCode: core.String("213dsadfsa"),
OutTradeNo: core.String("treads8a9f980"),
OutRequestNo: core.String("fdsafdsafdsa231321"),
},
)
if err != nil {
// 处理错误
log.Printf("call DisassociateTradeInfo err:%s", err)
} else {
// 处理返回结果
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
}
}
参数名 | 参数类型 | 参数描述 |
---|---|---|
ctx | context.Context | Golang 上下文,可用于日志、请求取消、请求跟踪等功能 |
req | DisassociateTradeInfoRequest | API merchantexclusivecoupon 所定义的本接口需要的所有参数,包括Path /Query /Body 3类参数 |
Name | Type | Description |
---|---|---|
resp | *DisassociateTradeInfoResponse | 结构化的接口返回结果 |
result | *core.APIResult | 本次 API 访问的请求与应答信息 |
err | error | 本次 API 访问中发生的错误,当且仅当 API 失败时存在 |
[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]
CouponListResponse ListCouponsByFilter(ListCouponsByFilterRequest)
根据过滤条件查询用户的券
package main
import (
"context"
"log"
"git.nanodreamtech.com/sg/wechatpay-go/core"
"git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
"git.nanodreamtech.com/sg/wechatpay-go/utils"
)
func main() {
var (
mchID string = "190000****" // 商户号
mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
)
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
if err != nil {
log.Printf("load merchant private key error:%s", err)
return
}
ctx := context.Background()
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Printf("new wechat pay client err:%s", err)
return
}
svc := merchantexclusivecoupon.CouponApiService{Client: client}
resp, result, err := svc.ListCouponsByFilter(ctx,
merchantexclusivecoupon.ListCouponsByFilterRequest{
Openid: core.String("2323dfsdf342342"),
Appid: core.String("wx233544546545989"),
StockId: core.String("100088"),
CreatorMerchant: core.String("1000000001"),
BelongMerchant: core.String("1000000002"),
SenderMerchant: core.String("1000000003"),
Offset: core.Int64(0),
Limit: core.Int64(20),
CouponState: merchantexclusivecoupon.COUPONSTATUS_SENDED.Ptr(),
},
)
if err != nil {
// 处理错误
log.Printf("call ListCouponsByFilter err:%s", err)
} else {
// 处理返回结果
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
}
}
参数名 | 参数类型 | 参数描述 |
---|---|---|
ctx | context.Context | Golang 上下文,可用于日志、请求取消、请求跟踪等功能 |
req | ListCouponsByFilterRequest | API merchantexclusivecoupon 所定义的本接口需要的所有参数,包括Path /Query /Body 3类参数 |
Name | Type | Description |
---|---|---|
resp | *CouponListResponse | 结构化的接口返回结果 |
result | *core.APIResult | 本次 API 访问的请求与应答信息 |
err | error | 本次 API 访问中发生的错误,当且仅当 API 失败时存在 |
[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]
CouponEntity QueryCoupon(QueryCouponRequest)
查询用户券详情
package main
import (
"context"
"log"
"git.nanodreamtech.com/sg/wechatpay-go/core"
"git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
"git.nanodreamtech.com/sg/wechatpay-go/utils"
)
func main() {
var (
mchID string = "190000****" // 商户号
mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
)
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
if err != nil {
log.Printf("load merchant private key error:%s", err)
return
}
ctx := context.Background()
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Printf("new wechat pay client err:%s", err)
return
}
svc := merchantexclusivecoupon.CouponApiService{Client: client}
resp, result, err := svc.QueryCoupon(ctx,
merchantexclusivecoupon.QueryCouponRequest{
CouponCode: core.String("123446565767"),
Appid: core.String("wx233544546545989"),
Openid: core.String("2323dfsdf342342"),
},
)
if err != nil {
// 处理错误
log.Printf("call QueryCoupon err:%s", err)
} else {
// 处理返回结果
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
}
}
参数名 | 参数类型 | 参数描述 |
---|---|---|
ctx | context.Context | Golang 上下文,可用于日志、请求取消、请求跟踪等功能 |
req | QueryCouponRequest | API merchantexclusivecoupon 所定义的本接口需要的所有参数,包括Path /Query /Body 3类参数 |
Name | Type | Description |
---|---|---|
resp | *CouponEntity | 结构化的接口返回结果 |
result | *core.APIResult | 本次 API 访问的请求与应答信息 |
err | error | 本次 API 访问中发生的错误,当且仅当 API 失败时存在 |
[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]
ReturnCouponResponse ReturnCoupon(ReturnCouponRequest)
申请退券
package main
import (
"context"
"log"
"git.nanodreamtech.com/sg/wechatpay-go/core"
"git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
"git.nanodreamtech.com/sg/wechatpay-go/utils"
)
func main() {
var (
mchID string = "190000****" // 商户号
mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
)
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
if err != nil {
log.Printf("load merchant private key error:%s", err)
return
}
ctx := context.Background()
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Printf("new wechat pay client err:%s", err)
return
}
svc := merchantexclusivecoupon.CouponApiService{Client: client}
resp, result, err := svc.ReturnCoupon(ctx,
merchantexclusivecoupon.ReturnCouponRequest{
CouponCode: core.String("sxxe34343434"),
StockId: core.String("1234567891"),
ReturnRequestNo: core.String("1002600620019090123143254436"),
},
)
if err != nil {
// 处理错误
log.Printf("call ReturnCoupon err:%s", err)
} else {
// 处理返回结果
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
}
}
参数名 | 参数类型 | 参数描述 |
---|---|---|
ctx | context.Context | Golang 上下文,可用于日志、请求取消、请求跟踪等功能 |
req | ReturnCouponRequest | API merchantexclusivecoupon 所定义的本接口需要的所有参数,包括Path /Query /Body 3类参数 |
Name | Type | Description |
---|---|---|
resp | *ReturnCouponResponse | 结构化的接口返回结果 |
result | *core.APIResult | 本次 API 访问的请求与应答信息 |
err | error | 本次 API 访问中发生的错误,当且仅当 API 失败时存在 |
[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]
SendCouponResponse SendCoupon(SendCouponRequest)
向用户发券
package main
import (
"context"
"log"
"git.nanodreamtech.com/sg/wechatpay-go/core"
"git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
"git.nanodreamtech.com/sg/wechatpay-go/utils"
)
func main() {
var (
mchID string = "190000****" // 商户号
mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
)
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
if err != nil {
log.Printf("load merchant private key error:%s", err)
return
}
ctx := context.Background()
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Printf("new wechat pay client err:%s", err)
return
}
svc := merchantexclusivecoupon.CouponApiService{Client: client}
resp, result, err := svc.SendCoupon(ctx,
merchantexclusivecoupon.SendCouponRequest{
Openid: core.String("xsd3434454567676"),
Appid: core.String("wx1234567889999"),
StockId: core.String("12312354"),
OutRequestNo: core.String("2335465"),
CouponCode: core.String("202007019999"),
},
)
if err != nil {
// 处理错误
log.Printf("call SendCoupon err:%s", err)
} else {
// 处理返回结果
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
}
}
参数名 | 参数类型 | 参数描述 |
---|---|---|
ctx | context.Context | Golang 上下文,可用于日志、请求取消、请求跟踪等功能 |
req | SendCouponRequest | API merchantexclusivecoupon 所定义的本接口需要的所有参数,包括Path /Query /Body 3类参数 |
Name | Type | Description |
---|---|---|
resp | *SendCouponResponse | 结构化的接口返回结果 |
result | *core.APIResult | 本次 API 访问的请求与应答信息 |
err | error | 本次 API 访问中发生的错误,当且仅当 API 失败时存在 |
[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]
CouponSendGovCardResponse SendGovCard(SendGovCardRequest)
发放政府消费卡
package main
import (
"context"
"log"
"git.nanodreamtech.com/sg/wechatpay-go/core"
"git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
"git.nanodreamtech.com/sg/wechatpay-go/utils"
)
func main() {
var (
mchID string = "190000****" // 商户号
mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
)
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
if err != nil {
log.Printf("load merchant private key error:%s", err)
return
}
ctx := context.Background()
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Printf("new wechat pay client err:%s", err)
return
}
svc := merchantexclusivecoupon.CouponApiService{Client: client}
resp, result, err := svc.SendGovCard(ctx,
merchantexclusivecoupon.SendGovCardRequest{
CardId: core.String("pIJMr5MMiIkO_93VtPyIiEk2DZ4w"),
Appid: core.String("wxc0b84a53ed8e8d29"),
Openid: core.String("obLatjhnqgy2syxrXVM3MJirbkdI"),
OutRequestNo: core.String("oTYhjfdsahnssddj_0136"),
SendTime: core.String("2019-12-31T13:29:35+08:00"),
},
)
if err != nil {
// 处理错误
log.Printf("call SendGovCard err:%s", err)
} else {
// 处理返回结果
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
}
}
参数名 | 参数类型 | 参数描述 |
---|---|---|
ctx | context.Context | Golang 上下文,可用于日志、请求取消、请求跟踪等功能 |
req | SendGovCardRequest | API merchantexclusivecoupon 所定义的本接口需要的所有参数,包括Path /Query /Body 3类参数 |
Name | Type | Description |
---|---|---|
resp | *CouponSendGovCardResponse | 结构化的接口返回结果 |
result | *core.APIResult | 本次 API 访问的请求与应答信息 |
err | error | 本次 API 访问中发生的错误,当且仅当 API 失败时存在 |
[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]
UseCouponResponse UseCoupon(UseCouponRequest)
核销用户的券
package main
import (
"context"
"log"
"git.nanodreamtech.com/sg/wechatpay-go/core"
"git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
"git.nanodreamtech.com/sg/wechatpay-go/utils"
)
func main() {
var (
mchID string = "190000****" // 商户号
mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号
mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥
)
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem")
if err != nil {
log.Printf("load merchant private key error:%s", err)
return
}
ctx := context.Background()
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key),
}
client, err := core.NewClient(ctx, opts...)
if err != nil {
log.Printf("new wechat pay client err:%s", err)
return
}
svc := merchantexclusivecoupon.CouponApiService{Client: client}
resp, result, err := svc.UseCoupon(ctx,
merchantexclusivecoupon.UseCouponRequest{
CouponCode: core.String("sxxe34343434"),
StockId: core.String("100088"),
Appid: core.String("wx1234567889999"),
UseTime: core.String("2015-05-20T13:29:35+08:00"),
UseRequestNo: core.String("1002600620019090123143254435"),
Openid: core.String("xsd3434454567676"),
},
)
if err != nil {
// 处理错误
log.Printf("call UseCoupon err:%s", err)
} else {
// 处理返回结果
log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
}
}
参数名 | 参数类型 | 参数描述 |
---|---|---|
ctx | context.Context | Golang 上下文,可用于日志、请求取消、请求跟踪等功能 |
req | UseCouponRequest | API merchantexclusivecoupon 所定义的本接口需要的所有参数,包括Path /Query /Body 3类参数 |
Name | Type | Description |
---|---|---|
resp | *UseCouponResponse | 结构化的接口返回结果 |
result | *core.APIResult | 本次 API 访问的请求与应答信息 |
err | error | 本次 API 访问中发生的错误,当且仅当 API 失败时存在 |