-
Notifications
You must be signed in to change notification settings - Fork 147
/
client.go
110 lines (76 loc) · 2.87 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
package card
import (
"github.com/ArtisanCloud/PowerLibs/v2/object"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
response2 "github.com/ArtisanCloud/PowerWeChat/v2/src/kernel/response"
"github.com/ArtisanCloud/PowerWeChat/v2/src/officialAccount/card/request"
"github.com/ArtisanCloud/PowerWeChat/v2/src/officialAccount/card/response"
"strings"
)
type Client struct {
*kernel.BaseClient
URL string
TicketCacheKey string
TicketCachePrefix string
}
func NewClient(app kernel.ApplicationInterface) *Client {
client := &Client{
BaseClient: kernel.NewBaseClient(&app, nil),
}
client.TicketCachePrefix = "powerwechat.official_account.card.api_ticket."
return client
}
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(param *request.RequestCardCreate) (*response.ResponseCardCreate, error) {
result := &response.ResponseCardCreate{}
_, err := comp.HttpPostJson("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(cardID string) (*response.ResponseCardGet, error) {
result := &response.ResponseCardGet{}
param := object.HashMap{
"card_id": cardID,
}
_, err := comp.HttpPostJson("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(offset int, count int, statusList string) (*response.ResponseCardList, error) {
result := &response.ResponseCardList{}
param := object.HashMap{
"offset": offset,
"count": count,
"status_list": statusList,
}
_, err := comp.HttpPostJson("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(cardID string, cardType string, card request.CardInterface) (*response.ResponseCardUpdate, error) {
result := &response.ResponseCardUpdate{}
param := object.HashMap{
"card_id": cardID,
strings.ToLower(cardType): card,
}
_, err := comp.HttpPostJson("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(cardID string) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
param := object.HashMap{
"card_id": cardID,
}
_, err := comp.HttpPostJson("card/delete", param, nil, nil, result)
return result, err
}