123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- // 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"
- "time"
- "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 ExampleBusiFavorApiService_CouponCodeInfo() {
- 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.BusiFavorApiService{Client: client}
- resp, result, err := svc.CouponCodeInfo(ctx,
- merchantexclusivecoupon.CouponCodeInfoRequest{
- StockId: core.String("98065001"),
- CouponCode: core.String("ABC1234567"),
- Appid: core.String("wx1234567889999"),
- },
- )
- if err != nil {
- // 处理错误
- log.Printf("call CouponCodeInfo err:%s", err)
- } else {
- // 处理返回结果
- log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
- }
- }
- func ExampleBusiFavorApiService_CreateBusifavorStock() {
- 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.BusiFavorApiService{Client: client}
- resp, result, err := svc.CreateBusifavorStock(ctx,
- merchantexclusivecoupon.CreateBusifavorStockRequest{
- StockName: core.String("8月1日活动券"),
- BelongMerchant: core.String("10000098"),
- Comment: core.String("活动使用"),
- GoodsName: core.String("填写商家券可适用的商品或服务"),
- StockType: merchantexclusivecoupon.BUSIFAVORSTOCKTYPE_NORMAL.Ptr(),
- CouponUseRule: &merchantexclusivecoupon.CouponUseRule{
- CouponAvailableTime: &merchantexclusivecoupon.FavorAvailableTime{
- AvailableBeginTime: core.Time(time.Now()),
- AvailableEndTime: core.Time(time.Now()),
- AvailableDayAfterReceive: core.Int64(3),
- AvailableWeek: &merchantexclusivecoupon.AvailableWeek{
- WeekDay: []int64{int64(1)},
- AvailableDayTime: []merchantexclusivecoupon.AvailableCurrentDayTime{merchantexclusivecoupon.AvailableCurrentDayTime{
- BeginTime: core.Int64(3600),
- EndTime: core.Int64(86399),
- }},
- },
- IrregularyAvaliableTime: []merchantexclusivecoupon.IrregularAvailableTime{merchantexclusivecoupon.IrregularAvailableTime{
- BeginTime: core.Time(time.Now()),
- EndTime: core.Time(time.Now()),
- }},
- WaitDaysAfterReceive: core.Int64(7),
- },
- FixedNormalCoupon: &merchantexclusivecoupon.FixedValueStockMsg{
- DiscountAmount: core.Int64(5),
- TransactionMinimum: core.Int64(100),
- },
- DiscountCoupon: &merchantexclusivecoupon.DiscountMsg{
- DiscountPercent: core.Int64(88),
- TransactionMinimum: core.Int64(100),
- },
- ExchangeCoupon: &merchantexclusivecoupon.ExchangeMsg{
- ExchangePrice: core.Int64(100),
- TransactionMinimum: core.Int64(100),
- },
- UseMethod: merchantexclusivecoupon.COUPONUSEMETHOD_OFF_LINE.Ptr(),
- MiniProgramsAppid: core.String("wx23232232323"),
- MiniProgramsPath: core.String("/path/index/index"),
- },
- StockSendRule: &merchantexclusivecoupon.StockSendRule{
- MaxAmount: core.Int64(100000),
- MaxCoupons: core.Int64(100),
- MaxCouponsPerUser: core.Int64(5),
- MaxAmountByDay: core.Int64(1000),
- MaxCouponsByDay: core.Int64(100),
- NaturalPersonLimit: core.Bool(false),
- PreventApiAbuse: core.Bool(false),
- Transferable: core.Bool(false),
- Shareable: core.Bool(false),
- },
- OutRequestNo: core.String("100002322019090134234sfdf"),
- CustomEntrance: &merchantexclusivecoupon.CustomEntrance{
- MiniProgramsInfo: &merchantexclusivecoupon.MiniAppInfo{
- MiniProgramsAppid: core.String("wx234545656765876"),
- MiniProgramsPath: core.String("/path/index/index"),
- EntranceWords: core.String("欢迎选购"),
- GuidingWords: core.String("获取更多优惠"),
- },
- Appid: core.String("wx324345hgfhfghfg"),
- HallId: core.String("233455656"),
- StoreId: core.String("233554655"),
- CodeDisplayMode: merchantexclusivecoupon.CODEDISPLAYMODE_NOT_SHOW.Ptr(),
- },
- DisplayPatternInfo: &merchantexclusivecoupon.DisplayPatternInfo{
- Description: core.String("xxx门店可用"),
- MerchantLogoUrl: core.String("https://xxx"),
- MerchantName: core.String("微信支付"),
- BackgroundColor: core.String("xxxxx"),
- CouponImageUrl: core.String("图片cdn地址"),
- FinderInfo: &merchantexclusivecoupon.FinderInfo{
- FinderId: core.String("sph6Rngt2T4RlUf"),
- FinderVideoId: core.String("export/UzFfAgtgekIEAQAAAAAAb4MgnPInmAAAAAstQy6ubaLX4KHWvLEZgBPEwIEgVnk9HIP-zNPgMJofG6tpdGPJNg_ojtEjoT94"),
- FinderVideoCoverImageUrl: core.String("https://wxpaylogo.qpic.cn/xxx"),
- },
- },
- CouponCodeMode: merchantexclusivecoupon.COUPONCODEMODE_WECHATPAY_MODE.Ptr(),
- NotifyConfig: &merchantexclusivecoupon.NotifyConfig{
- NotifyAppid: core.String("wx23232232323"),
- },
- Subsidy: core.Bool(false),
- },
- )
- if err != nil {
- // 处理错误
- log.Printf("call CreateBusifavorStock err:%s", err)
- } else {
- // 处理返回结果
- log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
- }
- }
- func ExampleBusiFavorApiService_DeleteCouponCode() {
- 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.BusiFavorApiService{Client: client}
- resp, result, err := svc.DeleteCouponCode(ctx,
- merchantexclusivecoupon.DeleteCouponCodeRequest{
- StockId: core.String("98065001"),
- CouponCode: core.String("ABC9588201"),
- DeleteRequestNo: core.String("100002322019090134234sfdf"),
- },
- )
- if err != nil {
- // 处理错误
- log.Printf("call DeleteCouponCode err:%s", err)
- } else {
- // 处理返回结果
- log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
- }
- }
- func ExampleBusiFavorApiService_ModifyBudget() {
- 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.BusiFavorApiService{Client: client}
- resp, result, err := svc.ModifyBudget(ctx,
- merchantexclusivecoupon.ModifyBudgetRequest{
- StockId: core.String("98065001"),
- TargetMaxCoupons: core.Int64(3000),
- CurrentMaxCoupons: core.Int64(500),
- TargetMaxCouponsByDay: core.Int64(500),
- CurrentMaxCouponsByDay: core.Int64(300),
- ModifyBudgetRequestNo: core.String("1002600620019090123143254436"),
- },
- )
- if err != nil {
- // 处理错误
- log.Printf("call ModifyBudget err:%s", err)
- } else {
- // 处理返回结果
- log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
- }
- }
- func ExampleBusiFavorApiService_ModifyStockInfo() {
- 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.BusiFavorApiService{Client: client}
- result, err := svc.ModifyStockInfo(ctx,
- merchantexclusivecoupon.ModifyStockInfoRequest{
- StockId: core.String("101156451224"),
- CustomEntrance: &merchantexclusivecoupon.ModifyCustomEntrance{
- MiniProgramsInfo: &merchantexclusivecoupon.ModifyMiniAppInfo{
- MiniProgramsAppid: core.String("wx234545656765876"),
- MiniProgramsPath: core.String("/path/index/index"),
- EntranceWords: core.String("欢迎选购"),
- GuidingWords: core.String("获取更多优惠"),
- },
- Appid: core.String("wx324345hgfhfghfg"),
- HallId: core.String("233455656"),
- CodeDisplayMode: merchantexclusivecoupon.CODEDISPLAYMODE_NOT_SHOW.Ptr(),
- },
- StockName: core.String("8月1日活动券"),
- Comment: core.String("活动使用"),
- GoodsName: core.String("xxx商品使用"),
- OutRequestNo: core.String("6122352020010133287985742"),
- DisplayPatternInfo: &merchantexclusivecoupon.DisplayPatternInfo{
- Description: core.String("xxx门店可用"),
- MerchantLogoUrl: core.String("https://xxx"),
- MerchantName: core.String("微信支付"),
- BackgroundColor: core.String("xxxxx"),
- CouponImageUrl: core.String("图片cdn地址"),
- FinderInfo: &merchantexclusivecoupon.FinderInfo{
- FinderId: core.String("sph6Rngt2T4RlUf"),
- FinderVideoId: core.String("export/UzFfAgtgekIEAQAAAAAAb4MgnPInmAAAAAstQy6ubaLX4KHWvLEZgBPEwIEgVnk9HIP-zNPgMJofG6tpdGPJNg_ojtEjoT94"),
- FinderVideoCoverImageUrl: core.String("https://wxpaylogo.qpic.cn/xxx"),
- },
- },
- CouponUseRule: &merchantexclusivecoupon.ModifyCouponUseRule{
- UseMethod: merchantexclusivecoupon.COUPONUSEMETHOD_OFF_LINE.Ptr(),
- MiniProgramsAppid: core.String("wx23232232323"),
- MiniProgramsPath: core.String("/path/index/index"),
- },
- StockSendRule: &merchantexclusivecoupon.ModifyStockSendRule{
- NaturalPersonLimit: core.Bool(false),
- PreventApiAbuse: core.Bool(false),
- },
- NotifyConfig: &merchantexclusivecoupon.NotifyConfig{
- NotifyAppid: core.String("wx23232232323"),
- },
- Subsidy: core.Bool(true),
- },
- )
- if err != nil {
- // 处理错误
- log.Printf("call ModifyStockInfo err:%s", err)
- } else {
- // 处理返回结果
- log.Printf("status=%d", result.Response.StatusCode)
- }
- }
- func ExampleBusiFavorApiService_QueryCouponCodeList() {
- 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.BusiFavorApiService{Client: client}
- resp, result, err := svc.QueryCouponCodeList(ctx,
- merchantexclusivecoupon.QueryCouponCodeListRequest{
- StockId: core.String("98065001"),
- Limit: core.Int64(100),
- Offset: core.Int64(10),
- Appid: core.String("wx1234567889999"),
- Status: merchantexclusivecoupon.COUPONCODESTATUS_AVAILABLE.Ptr(),
- },
- )
- if err != nil {
- // 处理错误
- log.Printf("call QueryCouponCodeList err:%s", err)
- } else {
- // 处理返回结果
- log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
- }
- }
- func ExampleBusiFavorApiService_QueryStock() {
- 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.BusiFavorApiService{Client: client}
- resp, result, err := svc.QueryStock(ctx,
- merchantexclusivecoupon.QueryStockRequest{
- StockId: core.String("100088"),
- },
- )
- if err != nil {
- // 处理错误
- log.Printf("call QueryStock err:%s", err)
- } else {
- // 处理返回结果
- log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
- }
- }
- func ExampleBusiFavorApiService_UploadCouponCode() {
- 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.BusiFavorApiService{Client: client}
- resp, result, err := svc.UploadCouponCode(ctx,
- merchantexclusivecoupon.UploadCouponCodeRequest{
- StockId: core.String("98065001"),
- CouponCodeList: []string{"ABC9588200"},
- UploadRequestNo: core.String("100002322019090134234sfdf"),
- },
- )
- if err != nil {
- // 处理错误
- log.Printf("call UploadCouponCode err:%s", err)
- } else {
- // 处理返回结果
- log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
- }
- }
|