-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapi.go
More file actions
92 lines (83 loc) · 1.74 KB
/
api.go
File metadata and controls
92 lines (83 loc) · 1.74 KB
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
package main
import (
"net/http"
"net/url"
"bytes"
"errors"
"encoding/json"
)
type LoginResponse struct {
Ok bool
Message string
Session_id string
}
type HeartBeatResponse struct {
Ok bool
SystemNotification SystemNotification
Self Self
Message string
}
type SystemNotification struct {
Show bool
Link string
Download_link string
Version string
Message string
}
type Self struct {
Ssconfigs []Ssconfig
}
type Ssconfig struct {
Id string
Kcp bool
Port int
State int
Method string
Server string
Remarks string
Password string
Fast_open bool
Server_port string
}
func post(route string, fields url.Values) ([]byte, error) {
resp, err := http.PostForm(API_HOST + route, fields)
if err != nil {
return nil, err
}
defer resp.Body.Close()
buf := new(bytes.Buffer)
buf.ReadFrom(resp.Body)
return buf.Bytes(), nil
}
func RalletsLogin(username string, password string) (*LoginResponse, error) {
fields := url.Values{}
fields.Set("username_or_email", username)
fields.Set("login_password", password)
fields.Set("DEVICE_TYPE", DEVICE_TYPE)
data, err := post("/login", fields)
if err != nil {
return nil, err
}
var resp LoginResponse
json.Unmarshal(data, &resp)
if !resp.Ok {
return nil, errors.New(resp.Message)
}
return &resp, nil
}
func RalletsHeartBeat(sessionId string) (*HeartBeatResponse, error) {
fields := url.Values{}
fields.Set("session_id", sessionId)
fields.Set("VERSION", VERSION)
fields.Set("DEVICE_TYPE", DEVICE_TYPE)
data, err := post("/rallets_notification", fields)
if err != nil {
return nil, err
}
var resp HeartBeatResponse
json.Unmarshal(data, &resp)
if !resp.Ok {
return nil, errors.New(resp.Message)
}
return &resp, nil
}