Skip to content

Commit

Permalink
新增代金券SDK (#193)
Browse files Browse the repository at this point in the history
* Add files via upload

add cashcoupons example

* Add files via upload

add cashcoupons sdk

* Update README.md

add cashcoupons
  • Loading branch information
alanfc666 authored Jun 28, 2023
1 parent 8de3748 commit 0a40cf6
Show file tree
Hide file tree
Showing 73 changed files with 9,110 additions and 1 deletion.
17 changes: 17 additions & 0 deletions docs/cashcoupons/AvailableMerchantCollection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# AvailableMerchantCollection

## 属性列表

名称 | 类型 | 描述 | 补充说明
------------ | ------------- | ------------- | -------------
**TotalCount** | **int64** | 可用商户总数量 |
**Data** | **[]string** | 可用商户列表 | [可选]
**Offset** | **int64** | 分页页码 |
**Limit** | **int64** | 分页大小 |
**StockId** | **string** | 批次号 |

[\[返回类型列表\]](README.md#类型列表)
[\[返回接口列表\]](README.md#接口列表)
[\[返回服务README\]](README.md)


17 changes: 17 additions & 0 deletions docs/cashcoupons/AvailableSingleitemCollection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# AvailableSingleitemCollection

## 属性列表

名称 | 类型 | 描述 | 补充说明
------------ | ------------- | ------------- | -------------
**TotalCount** | **int64** | 可用单品编码总数 |
**Data** | **[]string** | 可用单品编码 | [可选]
**Offset** | **int64** | 分页页码 |
**Limit** | **int64** | 分页大小 |
**StockId** | **string** | 批次号 |

[\[返回类型列表\]](README.md#类型列表)
[\[返回接口列表\]](README.md#接口列表)
[\[返回服务README\]](README.md)


39 changes: 39 additions & 0 deletions docs/cashcoupons/BackgroundColor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# BackgroundColor

## 枚举


* `COLOR010` (value: `"COLOR010"`)

* `COLOR020` (value: `"COLOR020"`)

* `COLOR030` (value: `"COLOR030"`)

* `COLOR040` (value: `"COLOR040"`)

* `COLOR050` (value: `"COLOR050"`)

* `COLOR060` (value: `"COLOR060"`)

* `COLOR070` (value: `"COLOR070"`)

* `COLOR080` (value: `"COLOR080"`)

* `COLOR081` (value: `"COLOR081"`)

* `COLOR082` (value: `"COLOR082"`)

* `COLOR090` (value: `"COLOR090"`)

* `COLOR100` (value: `"COLOR100"`)

* `COLOR101` (value: `"COLOR101"`)

* `COLOR102` (value: `"COLOR102"`)


[\[返回类型列表\]](README.md#类型列表)
[\[返回接口列表\]](README.md#接口列表)
[\[返回服务README\]](README.md)


178 changes: 178 additions & 0 deletions docs/cashcoupons/CallBackUrlApi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# cashcoupons/CallBackUrlApi

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

方法名 | HTTP 请求 | 描述
------------- | ------------- | -------------
[**QueryCallback**](#querycallback) | **Get** /v3/marketing/favor/callbacks | 查询代金券消息通知地址
[**SetCallback**](#setcallback) | **Post** /v3/marketing/favor/callbacks | 设置代金券消息通知地址



## QueryCallback

> Callback QueryCallback(QueryCallbackRequest)
查询代金券消息通知地址



### 调用示例

```go
package main

import (
"context"
"log"

"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
"github.com/wechatpay-apiv3/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.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)
}
}
```

### 参数列表
参数名 | 参数类型 | 参数描述
------------- | ------------- | -------------
**ctx** | **context.Context** | Golang 上下文,可用于日志、请求取消、请求跟踪等功能|
**req** | [**QueryCallbackRequest**](QueryCallbackRequest.md) | API `cashcoupons` 所定义的本接口需要的所有参数,包括`Path`/`Query`/`Body` 3类参数|

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

[\[返回顶部\]](#cashcouponscallbackurlapi)
[\[返回接口列表\]](README.md#接口列表)
[\[返回类型列表\]](README.md#类型列表)
[\[返回服务README\]](README.md)


## SetCallback

> SetCallbackResponse SetCallback(SetCallbackRequest)
设置代金券消息通知地址



### 调用示例

```go
package main

import (
"context"
"log"

"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
"github.com/wechatpay-apiv3/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.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)
}
}
```

### 参数列表
参数名 | 参数类型 | 参数描述
------------- | ------------- | -------------
**ctx** | **context.Context** | Golang 上下文,可用于日志、请求取消、请求跟踪等功能|
**req** | [**SetCallbackRequest**](SetCallbackRequest.md) | API `cashcoupons` 所定义的本接口需要的所有参数,包括`Path`/`Query`/`Body` 3类参数|

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

[\[返回顶部\]](#cashcouponscallbackurlapi)
[\[返回接口列表\]](README.md#接口列表)
[\[返回类型列表\]](README.md#类型列表)
[\[返回服务README\]](README.md)

14 changes: 14 additions & 0 deletions docs/cashcoupons/Callback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Callback

## 属性列表

名称 | 类型 | 描述 | 补充说明
------------ | ------------- | ------------- | -------------
**NotifyUrl** | **string** | 通知地址 |
**Mchid** | **string** | 商户号 |

[\[返回类型列表\]](README.md#类型列表)
[\[返回接口列表\]](README.md#接口列表)
[\[返回服务README\]](README.md)


14 changes: 14 additions & 0 deletions docs/cashcoupons/CardLimitation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# CardLimitation

## 属性列表

名称 | 类型 | 描述 | 补充说明
------------ | ------------- | ------------- | -------------
**Name** | **string** | 当批次指定支付方式为银行卡且配置了指定银行卡信息,该字段必填,最多4个中文字符。并将在微信支付收银台中展示给用户。 |
**Bin** | **[]string** | 当批次指定支付方式为银行卡且配置了指定银行卡信息,该字段必填,按json格式。特殊规则:单个卡BIN的字符长度为[6,9],条目个数限制为[1,10] |

[\[返回类型列表\]](README.md#类型列表)
[\[返回接口列表\]](README.md#接口列表)
[\[返回服务README\]](README.md)


25 changes: 25 additions & 0 deletions docs/cashcoupons/Coupon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Coupon

## 属性列表

名称 | 类型 | 描述 | 补充说明
------------ | ------------- | ------------- | -------------
**StockCreatorMchid** | **string** | 微信为创建方商户分配的商户号 |
**StockId** | **string** | 批次id |
**CutToMessage** | [**CutTypeMsg**](CutTypeMsg.md) | 单品优惠特定信息 | [可选]
**CouponName** | **string** | 代金券名称 |
**Status** | **string** | 代金券状态:SENDED-可用,USED-已实扣,EXPIRED-已过期 |
**Description** | **string** | 代金券描述说明字段 |
**CreateTime** | **string** | 领券时间 |
**CouponType** | **string** | NORMAL-满减券;CUT_TO-减至券 |
**NoCash** | **bool** | true-是;false-否 |
**AvailableBeginTime** | **string** | 可用开始时间 |
**AvailableEndTime** | **string** | 可用结束时间 |
**Singleitem** | **bool** | TRUE-是;FALSE-否 |
**NormalCouponInformation** | [**FixedValueStockMsg**](FixedValueStockMsg.md) | 普通满减券面额、门槛信息 | [可选]

[\[返回类型列表\]](README.md#类型列表)
[\[返回接口列表\]](README.md#接口列表)
[\[返回服务README\]](README.md)


Loading

0 comments on commit 0a40cf6

Please sign in to comment.