-
Notifications
You must be signed in to change notification settings - Fork 145
/
client.go
127 lines (88 loc) · 3.56 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package card
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
response2 "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/response"
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount/card/request"
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount/card/response"
"strings"
)
type Client struct {
*kernel.BaseClient
URL string
TicketCacheKey string
TicketCachePrefix string
}
func NewClient(app kernel.ApplicationInterface) (*Client, error) {
baseClient, err := kernel.NewBaseClient(&app, nil)
if err != nil {
return nil, err
}
client := &Client{
BaseClient: baseClient,
}
client.TicketCachePrefix = "powerwechat.official_account.card.api_ticket."
return client, nil
}
func (comp *Client) Colors() {
}
func (comp *Client) Categories() {
}
// 创建卡券
// https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Create_a_Coupon_Voucher_or_Card.html
func (comp *Client) Create(ctx context.Context, param *request.RequestCardCreate) (*response.ResponseCardCreate, error) {
result := &response.ResponseCardCreate{}
_, err := comp.BaseClient.HttpPostJson(ctx, "card/create", param, nil, nil, result)
return result, err
}
// 查看卡券详情
// https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#2
func (comp *Client) Get(ctx context.Context, cardID string) (*response.ResponseCardGet, error) {
result := &response.ResponseCardGet{}
param := object.HashMap{
"card_id": cardID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "card/get", param, nil, nil, result)
return result, err
}
// 批量查询卡券列表
// https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#2
func (comp *Client) List(ctx context.Context, offset int, count int, statusList string) (*response.ResponseCardList, error) {
result := &response.ResponseCardList{}
param := object.HashMap{
"offset": offset,
"count": count,
"status_list": statusList,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "card/batchget", param, nil, nil, result)
return result, err
}
// 更改卡券信息接口
// https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#2
func (comp *Client) Update(ctx context.Context, cardID string, cardType string, card interface{}) (*response.ResponseCardUpdate, error) {
result := &response.ResponseCardUpdate{}
param := object.HashMap{
"card_id": cardID,
strings.ToLower(cardType): card,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "card/update", param, nil, nil, result)
return result, err
}
// 删除卡券接口
// https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Managing_Coupons_Vouchers_and_Cards.html#2
func (comp *Client) Delete(ctx context.Context, cardID string) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
param := object.HashMap{
"card_id": cardID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "card/delete", param, nil, nil, result)
return result, err
}
// 创建二维码接口
// https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Distributing_Coupons_Vouchers_and_Cards.html#0
func (comp *Client) CreateQrCode(ctx context.Context, param request.RequestCreateQrCode) (*response.ResponseCreateQrCode, error) {
result := &response.ResponseCreateQrCode{}
_, err := comp.BaseClient.HttpPostJson(ctx, "card/qrcode/create", param, nil, nil, result)
return result, err
}