-
Notifications
You must be signed in to change notification settings - Fork 160
/
groupClient.go
134 lines (96 loc) · 4.04 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
134
package shakeAround
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount/shakeAround/request"
"github.com/ArtisanCloud/PowerWeChat/v3/src/officialAccount/shakeAround/response"
)
type GroupClient struct {
BaseClient *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(ctx context.Context, name string) (*response.ResponseGroup, error) {
result := &response.ResponseGroup{}
params := &object.HashMap{
"group_name": name,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "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(ctx context.Context, groupID string, name string) (*response.ResponseGroup, error) {
result := &response.ResponseGroup{}
params := &object.HashMap{
"group_id": groupID,
"group_name": name,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "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(ctx context.Context, groupID string) (*response.ResponseGroup, error) {
result := &response.ResponseGroup{}
params := &object.HashMap{
"group_id": groupID,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "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(ctx context.Context, begin int, count int) (*response.ResponseGroupList, error) {
result := &response.ResponseGroupList{}
params := &object.HashMap{
"begin": begin,
"count": count,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "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(ctx context.Context, groupID int, begin int, count int) (*response.ResponseGroupDetail, error) {
result := &response.ResponseGroupDetail{}
params := &object.HashMap{
"group_id": groupID,
"begin": begin,
"count": count,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "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(ctx context.Context, groupID int, deviceIdentifiers []*request.RequestDeviceIdentifier) (*response.ResponseGroup, error) {
result := &response.ResponseGroup{}
params := &object.HashMap{
"group_id": groupID,
"device_identifiers": deviceIdentifiers,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "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(ctx context.Context, groupID int, deviceIdentifiers []*request.RequestDeviceIdentifier) (*response.ResponseGroup, error) {
result := &response.ResponseGroup{}
params := &object.HashMap{
"group_id": groupID,
"device_identifiers": deviceIdentifiers,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "shakearound/device/group/deletedevice", params, nil, nil, result)
return result, err
}