-
Notifications
You must be signed in to change notification settings - Fork 168
/
client.go
168 lines (116 loc) · 5.3 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package store
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/store/request"
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount/store/response"
)
type Client struct {
BaseClient *kernel.BaseClient
}
func NewClient(app kernel.ApplicationInterface) (*Client, error) {
baseClient, err := kernel.NewBaseClient(&app, nil)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}
// 拉取门店小程序类目
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) Categories(ctx context.Context) (*response.ResponseStoreCategory, error) {
result := &response.ResponseStoreCategory{}
_, err := comp.BaseClient.HttpGet(ctx, "wxa/get_merchant_category", nil, nil, result)
return result, err
}
// 从腾讯地图拉取省市区信息
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) Districts(ctx context.Context) (*response.ResponseStoreDistrict, error) {
result := &response.ResponseStoreDistrict{}
_, err := comp.BaseClient.HttpGet(ctx, "wxa/get_district", nil, nil, result)
return result, err
}
// 在腾讯地图中搜索门店
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) SearchFromMap(ctx context.Context, districtID int, keyword string) (*response.ResponseStoreSearchMapPIO, error) {
result := &response.ResponseStoreSearchMapPIO{}
params := &object.HashMap{
"districtid": districtID,
"keyword": keyword,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "wxa/search_map_poi", params, nil, nil, result)
return result, err
}
// 查询门店小程序审核结果
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) GetStatus(ctx context.Context) (*response.ResponseStoreGetStatus, error) {
result := &response.ResponseStoreGetStatus{}
_, err := comp.BaseClient.HttpGet(ctx, "wxa/get_merchant_audit_info", nil, nil, result)
return result, err
}
// 修改门店小程序信息
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) UpdateMerchant(ctx context.Context, mediaID int, intro string) (*response.ResponseStoreSearchMapPIO, error) {
result := &response.ResponseStoreSearchMapPIO{}
params := &object.HashMap{
"headimg_mediaid": mediaID,
"intro": intro,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "wxa/modify_merchant", params, nil, nil, result)
return result, err
}
// 在腾讯地图中创建门店
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) CreateFromMap(ctx context.Context, data *request.BaseInfo) (*response.ResponseStoreCreateFromMap, error) {
result := &response.ResponseStoreCreateFromMap{}
_, err := comp.BaseClient.HttpPostJson(ctx, "wxa/create_map_poi", data, nil, nil, result)
return result, err
}
// 添加门店
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) Create(ctx context.Context, data *request.RequestStoreCreate) (*response.ResponseStoreCreate, error) {
result := &response.ResponseStoreCreate{}
_, err := comp.BaseClient.HttpPostJson(ctx, "wxa/add_store", data, nil, nil, result)
return result, err
}
// 更新门店信息
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) Update(ctx context.Context, data *request.RequestStoreUpdate) (*response.ResponseStoreUpdate, error) {
result := &response.ResponseStoreUpdate{}
_, err := comp.BaseClient.HttpPostJson(ctx, "wxa/update_store", data, nil, nil, result)
return result, err
}
// 获取单个门店信息
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) Get(ctx context.Context, poiID int) (*response.ResponseStoreInfo, error) {
result := &response.ResponseStoreInfo{}
params := &object.HashMap{
"poi_id": poiID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "wxa/get_store_info", params, nil, nil, result)
return result, err
}
// 获取门店信息列表
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) List(ctx context.Context, offset int, limit int) (*response.ResponseStoreInfo, error) {
result := &response.ResponseStoreInfo{}
params := &object.HashMap{
"offset": offset,
"limit": limit,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "wxa/get_store_list", params, nil, nil, result)
return result, err
}
// 删除门店
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Shop_Miniprogram_Interface.html
func (comp *Client) Delete(ctx context.Context, poiID int) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
params := &object.HashMap{
"poi_id": poiID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "wxa/del_store", params, nil, nil, result)
return result, err
}