-
Notifications
You must be signed in to change notification settings - Fork 151
/
groupClient.go
133 lines (95 loc) · 3.77 KB
/
groupClient.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
package shakeAround
import (
"github.com/ArtisanCloud/PowerLibs/v2/object"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v2/src/officialAccount/shakeAround/request"
"github.com/ArtisanCloud/PowerWeChat/v2/src/officialAccount/shakeAround/response"
)
type GroupClient struct {
*kernel.BaseClient
}
func NewGroupClient(app kernel.ApplicationInterface) (*GroupClient, error) {
baseClient, err := kernel.NewBaseClient(&app, nil)
if err != nil {
return nil, err
}
return &GroupClient{
baseClient,
}, nil
}
// 新建设备分组
// https://developers.weixin.qq.com/doc/offiaccount/Shake_Nearby/Active_from_Html5/New_groups.html
func (comp *GroupClient) Create(name string) (*response.ResponseGroup, error) {
result := &response.ResponseGroup{}
params := &object.HashMap{
"group_name": name,
}
_, err := comp.HttpPostJson("shakearound/device/group/add", params, nil, nil, result)
return result, err
}
// 更新设备分组
// https://developers.weixin.qq.com/doc/offiaccount/Shake_Nearby/Active_from_Html5/New_groups.html
func (comp *GroupClient) Update(groupID string, name string) (*response.ResponseGroup, error) {
result := &response.ResponseGroup{}
params := &object.HashMap{
"group_id": groupID,
"group_name": name,
}
_, err := comp.HttpPostJson("shakearound/device/group/update", params, nil, nil, result)
return result, err
}
// 删除设备分组
// https://developers.weixin.qq.com/doc/offiaccount/Shake_Nearby/Active_from_Html5/New_groups.html
func (comp *GroupClient) Delete(groupID string) (*response.ResponseGroup, error) {
result := &response.ResponseGroup{}
params := &object.HashMap{
"group_id": groupID,
}
_, err := comp.HttpPostJson("shakearound/device/group/delete", params, nil, nil, result)
return result, err
}
// 更新设备分组
// https://developers.weixin.qq.com/doc/offiaccount/en/Shake_Nearby/Active_from_Html5/Search_groups_list.html
func (comp *GroupClient) List(begin int, count int) (*response.ResponseGroupList, error) {
result := &response.ResponseGroupList{}
params := &object.HashMap{
"begin": begin,
"count": count,
}
_, err := comp.HttpPostJson("shakearound/device/group/getlist", params, nil, nil, result)
return result, err
}
// 查询分组详情
// https://developers.weixin.qq.com/doc/offiaccount/Shake_Nearby/Active_from_Html5/Search_grouping_details.html
func (comp *GroupClient) Get(groupID int, begin int, count int) (*response.ResponseGroupDetail, error) {
result := &response.ResponseGroupDetail{}
params := &object.HashMap{
"group_id": groupID,
"begin": begin,
"count": count,
}
_, err := comp.HttpPostJson("shakearound/device/group/getdetail", params, nil, nil, result)
return result, err
}
// 添加设备到分组
// https://developers.weixin.qq.com/doc/offiaccount/Shake_Nearby/Active_from_Html5/Add_device_to_group.html
func (comp *GroupClient) AddDevice(groupID int, deviceIdentifiers []*request.RequestDeviceIdentifier) (*response.ResponseGroup, error) {
result := &response.ResponseGroup{}
params := &object.HashMap{
"group_id": groupID,
"device_identifiers": deviceIdentifiers,
}
_, err := comp.HttpPostJson("shakearound/device/group/adddevice", params, nil, nil, result)
return result, err
}
// 从分组中移除设备
// https://developers.weixin.qq.com/doc/offiaccount/Shake_Nearby/Active_from_Html5/Remove_device_from_group.html
func (comp *GroupClient) RemoveDevices(groupID int, deviceIdentifiers []*request.RequestDeviceIdentifier) (*response.ResponseGroup, error) {
result := &response.ResponseGroup{}
params := &object.HashMap{
"group_id": groupID,
"device_identifiers": deviceIdentifiers,
}
_, err := comp.HttpPostJson("shakearound/device/group/deletedevice", params, nil, nil, result)
return result, err
}