StockApi.md 33 KB

cashcoupons/StockApi

所有URI均基于微信支付 API 地址: https://api.mch.weixin.qq.com

方法名 HTTP 请求 描述
CreateCouponStock Post /v3/marketing/favor/coupon-stocks 创建代金券批次
ListAvailableMerchants Get /v3/marketing/favor/stocks/{stock_id}/merchants 查询代金券可用商户
ListAvailableSingleitems Get /v3/marketing/favor/stocks/{stock_id}/items 查询可核销商品编码
ListStocks Get /v3/marketing/favor/stocks 条件查询批次列表
PauseStock Post /v3/marketing/favor/stocks/{stock_id}/pause 暂停批次
QueryStock Get /v3/marketing/favor/stocks/{stock_id} 查询批次详情
RefundFlow Get /v3/marketing/favor/stocks/{stock_id}/refund-flow 下载批次退款明细
RestartStock Post /v3/marketing/favor/stocks/{stock_id}/restart 重启批次
StartStock Post /v3/marketing/favor/stocks/{stock_id}/start 激活开启批次
StopStock Post /v3/marketing/favor/stocks/{stock_id}/stop 终止批次
UseFlow Get /v3/marketing/favor/stocks/{stock_id}/use-flow 下载批次核销明细

CreateCouponStock

CreateCouponStockResponse CreateCouponStock(CreateCouponStockRequest)

创建代金券批次

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.CreateCouponStock(ctx,
		cashcoupons.CreateCouponStockRequest{
			StockName:          core.String("微信支付代金券批次"),
			Comment:            core.String("零售批次"),
			BelongMerchant:     core.String("98568865"),
			AvailableBeginTime: core.String("2015-05-20T13:29:35.120+08:00"),
			AvailableEndTime:   core.String("2015-05-20T13:29:35.120+08:00"),
			StockUseRule: &cashcoupons.StockRule{
				MaxCoupons:         core.Int64(100),
				MaxAmount:          core.Int64(5000),
				MaxAmountByDay:     core.Int64(400),
				MaxCouponsPerUser:  core.Int64(3),
				NaturalPersonLimit: core.Bool(false),
				PreventApiAbuse:    core.Bool(false),
			},
			PatternInfo: &cashcoupons.PatternInfo{
				Description:      core.String("微信支付营销代金券"),
				MerchantLogo:     core.String("CDN地址"),
				MerchantName:     core.String("微信支付"),
				BackgroundColor:  cashcoupons.BACKGROUNDCOLOR_COLOR010.Ptr(),
				CouponImage:      core.String("图片cdn地址"),
				JumpTarget:       cashcoupons.JUMPTARGET_PAYMENT_CODE.Ptr(),
				MiniProgramAppid: core.String("wx23232232323"),
				MiniProgramPath:  core.String("/path/index/index"),
			},
			CouponUseRule: &cashcoupons.CouponRule{
				CouponAvailableTime: &cashcoupons.FavorAvailableTime{
					FixAvailableTime: &cashcoupons.FixedAvailableTime{
						AvailableWeekDay: []int64{int64(1)},
						BeginTime:        core.Int64(0),
						EndTime:          core.Int64(3600),
					},
					SecondDayAvailable:        core.Bool(false),
					AvailableTimeAfterReceive: core.Int64(1440),
				},
				FixedNormalCoupon: &cashcoupons.FixedValueStockMsg{
					CouponAmount:       core.Int64(100),
					TransactionMinimum: core.Int64(100),
				},
				GoodsTag:           []string{"123321"},
				TradeType:          []cashcoupons.TradeType{cashcoupons.TRADETYPE_MICROAPP},
				CombineUse:         core.Bool(false),
				AvailableItems:     []string{"123321"},
				UnavailableItems:   []string{"789987"},
				AvailableMerchants: []string{"9856000"},
				LimitCard: &cashcoupons.CardLimitation{
					Name: core.String("精粹白金"),
					Bin:  []string{"62542688"},
				},
				LimitPay: []string{"BCZ_DEBIT"},
			},
			NoCash:       core.Bool(false),
			StockType:    core.String("NORMAL"),
			OutRequestNo: core.String("example_out_request_no"),
			ExtInfo:      core.String("{'exinfo1':'1234','exinfo2':'3456'}"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call CreateCouponStock err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req CreateCouponStockRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *CreateCouponStockResponse 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]

ListAvailableMerchants

AvailableMerchantCollection ListAvailableMerchants(ListAvailableMerchantsRequest)

查询代金券可用商户

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.ListAvailableMerchants(ctx,
		cashcoupons.ListAvailableMerchantsRequest{
			Offset:            core.Int64(10),
			Limit:             core.Int64(10),
			StockCreatorMchid: core.String("9865000"),
			StockId:           core.String("9865000"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call ListAvailableMerchants err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req ListAvailableMerchantsRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *AvailableMerchantCollection 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]

ListAvailableSingleitems

AvailableSingleitemCollection ListAvailableSingleitems(ListAvailableSingleitemsRequest)

查询可核销商品编码

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.ListAvailableSingleitems(ctx,
		cashcoupons.ListAvailableSingleitemsRequest{
			Offset:            core.Int64(10),
			Limit:             core.Int64(10),
			StockCreatorMchid: core.String("9865000"),
			StockId:           core.String("9865000"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call ListAvailableSingleitems err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req ListAvailableSingleitemsRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *AvailableSingleitemCollection 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]

ListStocks

StockCollection ListStocks(ListStocksRequest)

条件查询批次列表

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.ListStocks(ctx,
		cashcoupons.ListStocksRequest{
			Offset:            core.Int64(1),
			Limit:             core.Int64(8),
			StockCreatorMchid: core.String("9856888"),
			CreateStartTime:   core.String("2015-05-20T13:29:35.120+08:00"),
			CreateEndTime:     core.String("2015-05-20T13:29:35.120+08:00"),
			Status:            core.String("paused"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call ListStocks err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req ListStocksRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *StockCollection 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]

PauseStock

PauseStockResponse PauseStock(PauseStockRequest)

暂停批次

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.PauseStock(ctx,
		cashcoupons.PauseStockRequest{
			StockId:           core.String("实例值"),
			StockCreatorMchid: core.String("8965000"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call PauseStock err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req PauseStockRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *PauseStockResponse 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]

QueryStock

Stock QueryStock(QueryStockRequest)

查询批次详情

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.QueryStock(ctx,
		cashcoupons.QueryStockRequest{
			StockId:           core.String("9856888"),
			StockCreatorMchid: core.String("123456"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call QueryStock err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req QueryStockRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *Stock 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]

RefundFlow

RefundFlowResponse RefundFlow(RefundFlowRequest)

下载批次退款明细

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.RefundFlow(ctx,
		cashcoupons.RefundFlowRequest{
			StockId: core.String("9865000"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call RefundFlow err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req RefundFlowRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *RefundFlowResponse 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]

RestartStock

RestartStockResponse RestartStock(RestartStockRequest)

重启批次

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.RestartStock(ctx,
		cashcoupons.RestartStockRequest{
			StockId:           core.String("8965000"),
			StockCreatorMchid: core.String("9865000"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call RestartStock err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req RestartStockRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *RestartStockResponse 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]

StartStock

StartStockResponse StartStock(StartStockRequest)

激活开启批次

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.StartStock(ctx,
		cashcoupons.StartStockRequest{
			StockId:           core.String("9856000"),
			StockCreatorMchid: core.String("8956000"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call StartStock err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req StartStockRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *StartStockResponse 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]

StopStock

StopStockResponse StopStock(StopStockRequest)

终止批次

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.StopStock(ctx,
		cashcoupons.StopStockRequest{
			StockId:           core.String("8695000"),
			StockCreatorMchid: core.String("9865000"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call StopStock err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req StopStockRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *StopStockResponse 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]

UseFlow

UseFlowResponse UseFlow(UseFlowRequest)

下载批次核销明细

调用示例

package main

import (
	"context"
	"log"

	"git.nanodreamtech.com/sg/wechatpay-go/core"
	"git.nanodreamtech.com/sg/wechatpay-go/services/cashcoupons"
	"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 := cashcoupons.StockApiService{Client: client}
	resp, result, err := svc.UseFlow(ctx,
		cashcoupons.UseFlowRequest{
			StockId: core.String("9865000"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call UseFlow err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}

参数列表

参数名 参数类型 参数描述
ctx context.Context Golang 上下文,可用于日志、请求取消、请求跟踪等功能
req UseFlowRequest API cashcoupons 所定义的本接口需要的所有参数,包括Path/Query/Body 3类参数

返回结果

Name Type Description
resp *UseFlowResponse 结构化的接口返回结果
result *core.APIResult 本次 API 访问的请求与应答信息
err error 本次 API 访问中发生的错误,当且仅当 API 失败时存在

[返回顶部] [返回接口列表] [返回类型列表] [返回服务README]