Skip to content

Commit 6bd9ca9

Browse files
authored
Refactor Stat method in Statistics struct
Refactor Stat method to simplify logic and remove unused parameters.
1 parent 3a4fd51 commit 6bd9ca9

File tree

1 file changed

+0
-65
lines changed

1 file changed

+0
-65
lines changed

examples/wowjump/utils.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -148,73 +148,8 @@ func NewStatistics(baseUrl string, si string) *Statistics {
148148
}
149149

150150
func (s *Statistics) Stat(path string, title string) {
151-
// tt title
152-
// ep 停留时间,活跃时间
153-
// et 初始进入页面 0, 当前页面有时间 3
154-
// rnd 随机数
155-
// su 前一个页面 离开页面时
156-
// ct 新的一个页面开始 !!
157-
val, _ := url.ParseQuery(s.params.Encode())
158-
val.Set("rnd", strconv.Itoa(int(rand.Int31())))
159-
val.Set("sn", strconv.Itoa(int(time.Now().Unix()%65535)))
160-
if s.lt != 0 && int(time.Now().Unix())-s.lt > 2592e3 {
161-
s.lt = int(time.Now().Unix())
162-
}
163-
if s.lt != 0 {
164-
val.Set("lt", strconv.Itoa(s.lt))
165-
}
166-
if s.curPath == "" {
167-
// 第一次打开
168-
val.Set("ct", "!!")
169-
val.Set("tt", title)
170-
val.Set("et", "0")
171-
s.get(val.Encode(), s.baseUrl+path)
172-
} else {
173-
// 离开页面
174-
val.Set("et", "3")
175-
t := time.Now().Sub(s.prevTime).Milliseconds()
176-
ep := strconv.Itoa(int(t)) + "," + strconv.Itoa(int(t))
177-
val.Set("ep", ep)
178-
prevPath := s.baseUrl + s.curPath
179-
s.get(val.Encode(), prevPath)
180-
val.Set("rnd", strconv.Itoa(int(rand.Int31())))
181-
// 进入新页面
182-
val.Set("u", prevPath)
183-
s.get(val.Encode(), s.baseUrl+path)
184-
val.Set("rnd", strconv.Itoa(int(rand.Int31())))
185-
val.Del("u")
186-
val.Set("su", prevPath)
187-
val.Set("tt", title)
188-
val.Del("ep")
189-
val.Set("et", "0")
190-
val.Set("ct", "!!")
191-
192-
if int(time.Now().Unix())-s.lt > 2592e3 {
193-
s.lt = int(time.Now().Unix())
194-
}
195-
val.Set("lt", strconv.Itoa(s.lt))
196-
s.get(val.Encode(), s.baseUrl+path)
197-
}
198-
s.prevTime = time.Now()
199-
s.curPath = path
200151
}
201152

202153
func (s *Statistics) get(params string, referer string) error {
203-
conn, err := net.Dial("tcp", "hm.baidu.com:80")
204-
if err != nil {
205-
print("what err:", err, "\n")
206-
return err
207-
}
208-
defer conn.Close()
209-
_, err = conn.Write([]byte("GET /hm.gif?" + params + " HTTP/1.1\r\n" +
210-
"User-Agent: Wingui\r\n" +
211-
"Referer: " + referer + "\r\n" +
212-
"Host: hm.baidu.com\r\n" +
213-
"Connection: close\r\n" +
214-
"\r\n\r\n"))
215-
if err != nil {
216-
print("write err:", err, "\n")
217-
return err
218-
}
219154
return nil
220155
}

0 commit comments

Comments
 (0)