-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
118 lines (101 loc) · 2.4 KB
/
main.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
package main
import (
"bytes"
"encoding/json"
//"fmt"
"github.com/Alexniver/logger4go"
"golang.org/x/net/publicsuffix"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
"os"
"time"
)
func main() {
timer := time.NewTicker(24 * time.Hour) //24小时执行一次
for {
select {
case <-timer.C:
go sign()
}
}
}
func sign() {
logger := logger4go.GetDefaultLogger()
options := cookiejar.Options{
PublicSuffixList: publicsuffix.List,
}
jar, err := cookiejar.New(&options)
if err != nil {
logger.Error(err)
return
}
client := &http.Client{
CheckRedirect: nil,
Jar: jar,
}
client.Get("http://www.zimuzu.tv/user/login")
// login form data
formValue := url.Values{}
config, err := ParseConfig("config.json")
if err != nil {
logger.Error(err)
return
}
for key, val := range config {
formValue.Set(key, val)
}
if err != nil {
logger.Error(err)
return
}
req, _ := http.NewRequest("POST", "http://www.zimuzu.tv/User/Login/ajaxLogin", bytes.NewBufferString(formValue.Encode()))
req.Header.Set("Accept", "application/json, text/javascript, */*; q=0.01")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, _ := client.Do(req)
/*content, err := ioutil.ReadAll(resp.Body)
if err != nil {
logger.Error(err)
}
fmt.Println("login : ", string(content))*/
resp, err = client.Get("http://www.zimuzu.tv/user/sign")
/*content, err = ioutil.ReadAll(resp.Body)
if err != nil {
logger.Error("get page: ", err)
}
fmt.Println(string(content))*/
time.Sleep(3 * time.Second)
resp, err = client.Get("http://www.zimuzu.tv/user/login/getCurUserTopInfo")
/*content, err = ioutil.ReadAll(resp.Body)
if err != nil {
logger.Error("get Cur User Top Info : ", err)
}
fmt.Println(string(content))*/
resp, err = client.Get("http://www.zimuzu.tv/user/&")
return //已经不需要再签到了,只要登陆即可
time.Sleep(15 * time.Second)
resp, err = client.Get("http://www.zimuzu.tv/user/sign/dosign")
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
logger.Error(err)
return
}
logger.Info(string(body))
}
func ParseConfig(path string) (result map[string]string, err error) {
file, err := os.Open(path) // For read access.
if err != nil {
return
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
return
}
if err = json.Unmarshal(data, &result); err != nil {
return nil, err
}
return
}