-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcic.go
220 lines (208 loc) · 5.63 KB
/
lcic.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package AossGoSdk
import (
"encoding/json"
"errors"
jsoniter "github.com/json-iterator/go"
"github.com/tobycroft/Calc"
Net "github.com/tobycroft/TuuzNet"
"time"
)
type Lcic struct {
Name string
Token string
}
type lcicStructCreateUser struct {
Code int `json:"code"`
Data LcicStructCreateUser `json:"data"`
Echo string `json:"echo"`
}
type LcicStructCreateUser struct {
UserId string `json:"UserId"`
Token string `json:"Token"`
}
// Lcic_CreateUser Name:用户在直播间的显示名称 | OriginId:用户在你系统中的标识符 | Avatar:用户头像url地址
func (self *Lcic) Lcic_CreateUser(Name, OriginId, Avatar interface{}) (LcicStructCreateUser, error) {
ts := time.Now().Unix()
param := map[string]any{
"Name": Name,
"OriginId": OriginId,
"Avatar": Avatar,
"ts": ts,
"name": self.Name,
"sign": Calc.Md5(self.Token + Calc.Any2String(ts)),
}
ret, err := Net.Post(baseUrls+"/v1/lcic/user/auto", map[string]interface{}{
"token": self.Name,
}, param, nil, nil)
//fmt.Println(ret, err)
if err != nil {
return LcicStructCreateUser{}, err
} else {
var resp ret_std
err = jsoniter.UnmarshalFromString(ret, &resp)
if err != nil {
return LcicStructCreateUser{}, errors.New(ret)
}
if resp.Code == 0 {
var dat lcicStructCreateUser
err = jsoniter.UnmarshalFromString(ret, &dat)
if err != nil {
return LcicStructCreateUser{}, errors.New(ret)
}
return dat.Data, nil
} else {
return LcicStructCreateUser{}, errors.New(resp.Echo)
}
}
}
type lcicStructCreateRoom struct {
Code int `json:"code"`
Data LcicStructCreateRoom `json:"data"`
Echo string `json:"echo"`
}
type LcicStructCreateRoom struct {
RoomId int `json:"RoomId"`
}
// Lcic_RoomCreate TeacherId:老师ID | StartTime:开始时间int | EndTime:结束时间int | Name:房间名称
func (self *Lcic) Lcic_RoomCreate(TeacherId, StartTime, EndTime, Name interface{}) (LcicStructCreateRoom, error) {
ts := time.Now().Unix()
param := map[string]any{
"Name": Name,
"TeacherId": TeacherId,
"StartTime": StartTime,
"EndTime": EndTime,
"ts": ts,
"name": self.Name,
"sign": Calc.Md5(self.Token + Calc.Any2String(ts)),
}
ret, err := Net.Post(baseUrls+"/v1/lcic/room/create", map[string]interface{}{
"token": self.Name,
}, param, nil, nil)
//fmt.Println(ret, err)
if err != nil {
return LcicStructCreateRoom{}, err
} else {
var resp ret_std
err = jsoniter.UnmarshalFromString(ret, &resp)
if err != nil {
return LcicStructCreateRoom{}, errors.New(ret)
}
if resp.Code == 0 {
var dat lcicStructCreateRoom
err = jsoniter.UnmarshalFromString(ret, &dat)
if err != nil {
return LcicStructCreateRoom{}, errors.New(ret)
}
return dat.Data, nil
} else {
return LcicStructCreateRoom{}, errors.New(resp.Echo)
}
}
}
// Lcic_RoomModify RoomId:房间ID | TeacherId:老师ID | StartTime:开始时间int | EndTime:结束时间int | Name:房间名称
func (self *Lcic) Lcic_RoomModify(RoomId, TeacherId, StartTime, EndTime, Name interface{}) (bool, error) {
ts := time.Now().Unix()
param := map[string]any{
"RoomId": RoomId,
"Name": Name,
"TeacherId": TeacherId,
"StartTime": StartTime,
"EndTime": EndTime,
"ts": ts,
"name": self.Name,
"sign": Calc.Md5(self.Token + Calc.Any2String(ts)),
}
ret, err := Net.Post(baseUrls+"/v1/lcic/room/create", map[string]interface{}{
"token": self.Name,
}, param, nil, nil)
//fmt.Println(ret, err)
if err != nil {
return false, err
} else {
var rs ret_std
errs := json.Unmarshal([]byte(ret), &rs)
if errs != nil {
return false, errs
} else {
//fmt.Println(rs)
if rs.Code == 0 {
return true, nil
} else {
return false, errors.New(rs.Echo)
}
}
}
}
// Lcic_RoomDelete RoomId:房间ID
func (self *Lcic) Lcic_RoomDelete(RoomId interface{}) (bool, error) {
ts := time.Now().Unix()
param := map[string]any{
"RoomId": RoomId,
"ts": ts,
"name": self.Name,
"sign": Calc.Md5(self.Token + Calc.Any2String(ts)),
}
ret, err := Net.Post(baseUrls+"/v1/lcic/room/delete", map[string]interface{}{
"token": self.Name,
}, param, nil, nil)
//fmt.Println(ret, err)
if err != nil {
return false, err
} else {
var rs ret_std
errs := json.Unmarshal([]byte(ret), &rs)
if errs != nil {
return false, errs
} else {
//fmt.Println(rs)
if rs.Code == 0 {
return true, nil
} else {
return false, errors.New(rs.Echo)
}
}
}
}
type lcicStructLinkUrl struct {
Code int `json:"code"`
Data LcicStructLinkUrl `json:"data"`
Echo string `json:"echo"`
}
type LcicStructLinkUrl struct {
Web string `json:"web"`
Pc string `json:"pc"`
}
// Lcic_LinkUrl OriginId:学生id | TeacherId:老师id
func (self *Lcic) Lcic_LinkUrl(OriginId, TeacherId interface{}) (LcicStructLinkUrl, error) {
ts := time.Now().Unix()
param := map[string]any{
"OriginId": OriginId,
"TeacherId": TeacherId,
"ts": ts,
"name": self.Name,
"sign": Calc.Md5(self.Token + Calc.Any2String(ts)),
}
ret, err := Net.Post(baseUrls+"/v1/lcic/room/delete", map[string]interface{}{
"token": self.Name,
}, param, nil, nil)
//fmt.Println(ret, err)
if err != nil {
return LcicStructLinkUrl{}, err
} else {
var resp ret_std
err = jsoniter.UnmarshalFromString(ret, &resp)
if err != nil {
return LcicStructLinkUrl{}, errors.New(ret)
}
if resp.Code == 0 {
var dat lcicStructLinkUrl
err = jsoniter.UnmarshalFromString(ret, &dat)
if err != nil {
return LcicStructLinkUrl{}, errors.New(ret)
}
return dat.Data, nil
} else {
return LcicStructLinkUrl{}, errors.New(resp.Echo)
}
}
}