forked from eatmoreapple/openwechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmode.go
67 lines (55 loc) · 1.81 KB
/
mode.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
package openwechat
import (
"net/http"
"net/url"
"strconv"
"time"
)
type Mode interface {
GetLoginUUID(client *Client) (*http.Response, error)
GetLoginInfo(client *Client, path string) (*http.Response, error)
}
var (
Normal Mode = normalMode{}
Desktop Mode = desktopMode{}
)
type normalMode struct{}
func (n normalMode) GetLoginUUID(client *Client) (*http.Response, error) {
path, _ := url.Parse(jslogin)
params := url.Values{}
redirectUrl, _ := url.Parse(webwxnewloginpage)
params.Add("redirect_uri", redirectUrl.String())
params.Add("appid", appId)
params.Add("fun", "new")
params.Add("lang", "zh_CN")
params.Add("_", strconv.FormatInt(time.Now().UnixNano()/1e6, 10))
path.RawQuery = params.Encode()
req, _ := http.NewRequest(http.MethodGet, path.String(), nil)
return client.Do(req)
}
func (n normalMode) GetLoginInfo(client *Client, path string) (*http.Response, error) {
req, _ := http.NewRequest(http.MethodGet, path, nil)
return client.Do(req)
}
type desktopMode struct{}
func (n desktopMode) GetLoginUUID(client *Client) (*http.Response, error) {
path, _ := url.Parse(jslogin)
params := url.Values{}
redirectUrl, _ := url.Parse(webwxnewloginpage)
p := url.Values{"mod": {"desktop"}}
redirectUrl.RawQuery = p.Encode()
params.Add("redirect_uri", redirectUrl.String())
params.Add("appid", appId)
params.Add("fun", "new")
params.Add("lang", "zh_CN")
params.Add("_", strconv.FormatInt(time.Now().UnixNano()/1e6, 10))
path.RawQuery = params.Encode()
req, _ := http.NewRequest(http.MethodGet, path.String(), nil)
return client.Do(req)
}
func (n desktopMode) GetLoginInfo(client *Client, path string) (*http.Response, error) {
req, _ := http.NewRequest(http.MethodGet, path, nil)
req.Header.Add("client-version", uosPatchClientVersion)
req.Header.Add("extspam", uosPatchExtspam)
return client.Do(req)
}