-
Notifications
You must be signed in to change notification settings - Fork 151
/
client.go
112 lines (81 loc) · 3.01 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
package poi
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/poi/request"
"github.com/ArtisanCloud/PowerWeChat/v2/src/officialAccount/poi/response"
)
type Client struct {
*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_Store_Interface.html
func (comp *Client) Get(poiID int) (*response.ResponsePOIGet, error) {
result := &response.ResponsePOIGet{}
_, err := comp.HttpPostJson("cgi-bin/poi/getpoi", &object.HashMap{"poi_id": poiID}, nil, nil, result)
return result, err
}
// 查询门店列表
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Store_Interface.html
func (comp *Client) List(offset int, limit int) (*response.ResponsePOIList, error) {
result := &response.ResponsePOIList{}
params := &object.HashMap{
"begin": offset,
"limit": limit,
}
_, err := comp.HttpPostJson("cgi-bin/poi/getpoilist", params, nil, nil, result)
return result, err
}
// 查询门店列表
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Store_Interface.html
func (comp *Client) Create(data *request.BusinessInfo) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
params := &object.HashMap{
"business": &object.HashMap{
"base_info": data,
},
}
_, err := comp.HttpPostJson("cgi-bin/poi/addpoi", params, nil, nil, result)
return result, err
}
// 查询门店列表并获取POI ID
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Store_Interface.html
func (comp *Client) CreateAndGetID(data *request.BusinessInfo) (int, error) {
result, err := comp.Create(data)
poi, err := comp.DetectAndCastResponseToType(result, response2.TYPE_MAP)
if err != nil {
return 0, err
}
mapPOI := poi.(*object.HashMap)
poiID := (*mapPOI)["poi_id"].(int)
return poiID, err
}
// 修改门店服务信息
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Store_Interface.html
func (comp *Client) Update(data *request.BusinessInfo) (*response2.ResponseOfficialAccount, error) {
result := &response2.ResponseOfficialAccount{}
params := &object.HashMap{
"business": &object.HashMap{
"base_info": data,
},
}
_, err := comp.HttpPostJson("cgi-bin/poi/updatepoi", params, nil, nil, result)
return result, err
}
// 删除门店
// https://developers.weixin.qq.com/doc/offiaccount/WeChat_Stores/WeChat_Store_Interface.html
func (comp *Client) Delete(poiID int) (*response.ResponsePOIGet, error) {
result := &response.ResponsePOIGet{}
_, err := comp.HttpPostJson("cgi-bin/poi/delpoi", &object.HashMap{"poi_id": poiID}, nil, nil, result)
return result, err
}