123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- // Copyright 2021 Tencent Inc. All rights reserved.
- //
- // 营销商家券对外API
- //
- // No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
- //
- // API version: 0.0.11
- // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
- package merchantexclusivecoupon_test
- import (
- "context"
- "log"
- "git.nanodreamtech.com/sg/wechatpay-go/core"
- "git.nanodreamtech.com/sg/wechatpay-go/core/option"
- "git.nanodreamtech.com/sg/wechatpay-go/services/merchantexclusivecoupon"
- "git.nanodreamtech.com/sg/wechatpay-go/utils"
- )
- func ExampleCouponApiService_AssociateTradeInfo() {
- 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)
- }
- }
- func ExampleCouponApiService_DeactivateCoupon() {
- 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)
- }
- }
- func ExampleCouponApiService_DisassociateTradeInfo() {
- 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)
- }
- }
- func ExampleCouponApiService_ListCouponsByFilter() {
- 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)
- }
- }
- func ExampleCouponApiService_QueryCoupon() {
- 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)
- }
- }
- func ExampleCouponApiService_ReturnCoupon() {
- 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)
- }
- }
- func ExampleCouponApiService_SendCoupon() {
- 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)
- }
- }
- func ExampleCouponApiService_SendGovCard() {
- 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)
- }
- }
- func ExampleCouponApiService_UseCoupon() {
- 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)
- }
- }
|