123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- // Copyright 2021 Tencent Inc. All rights reserved.
- //
- // 微信支付营销系统开放API
- //
- // 新增立减金api
- //
- // API version: 3.4.0
- // Code generated by WechatPay APIv3 Generator based on [OpenAPI Generator](https://openapi-generator.tech); DO NOT EDIT.
- package cashcoupons_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/cashcoupons"
- "git.nanodreamtech.com/sg/wechatpay-go/utils"
- )
- func ExampleCallBackUrlApiService_QueryCallback() {
- 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.CallBackUrlApiService{Client: client}
- resp, result, err := svc.QueryCallback(ctx,
- cashcoupons.QueryCallbackRequest{
- Mchid: core.String("9856888"),
- },
- )
- if err != nil {
- // 处理错误
- log.Printf("call QueryCallback err:%s", err)
- } else {
- // 处理返回结果
- log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
- }
- }
- func ExampleCallBackUrlApiService_SetCallback() {
- 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.CallBackUrlApiService{Client: client}
- resp, result, err := svc.SetCallback(ctx,
- cashcoupons.SetCallbackRequest{
- Mchid: core.String("9856888"),
- NotifyUrl: core.String("https://pay.weixin.qq.com"),
- Switch: core.Bool(true),
- },
- )
- if err != nil {
- // 处理错误
- log.Printf("call SetCallback err:%s", err)
- } else {
- // 处理返回结果
- log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
- }
- }
|