:pencli2: 修改mode行为
This commit is contained in:
parent
58fd3a752c
commit
3cff50f83b
2
bot.go
2
bot.go
@ -360,7 +360,7 @@ func NewBot() *Bot {
|
|||||||
// DefaultBot 默认的Bot的构造方法,
|
// DefaultBot 默认的Bot的构造方法,
|
||||||
// mode不传入默认为openwechat.Normal,详情见mode
|
// mode不传入默认为openwechat.Normal,详情见mode
|
||||||
// bot := openwechat.DefaultBot(openwechat.Desktop)
|
// bot := openwechat.DefaultBot(openwechat.Desktop)
|
||||||
func DefaultBot(modes ...mode) *Bot {
|
func DefaultBot(modes ...Mode) *Bot {
|
||||||
bot := NewBot()
|
bot := NewBot()
|
||||||
if len(modes) > 0 {
|
if len(modes) > 0 {
|
||||||
bot.Caller.Client.SetMode(modes[0])
|
bot.Caller.Client.SetMode(modes[0])
|
||||||
|
@ -402,7 +402,7 @@ func (c *Caller) WebWxRenameChatRoom(request *BaseRequest, info *LoginInfo, newT
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetMode 设置Client的模式
|
// SetMode 设置Client的模式
|
||||||
func (c *Client) SetMode(mode mode) {
|
func (c *Client) SetMode(mode Mode) {
|
||||||
c.mode = mode
|
c.mode = mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
client.go
38
client.go
@ -41,7 +41,7 @@ type Client struct {
|
|||||||
HttpHooks HttpHooks
|
HttpHooks HttpHooks
|
||||||
*http.Client
|
*http.Client
|
||||||
Domain WechatDomain
|
Domain WechatDomain
|
||||||
mode mode
|
mode Mode
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
cookies map[string][]*http.Cookie
|
cookies map[string][]*http.Cookie
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ func DefaultClient() *Client {
|
|||||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||||
return http.ErrUseLastResponse
|
return http.ErrUseLastResponse
|
||||||
},
|
},
|
||||||
Jar: jar,
|
Jar: jar,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
}
|
}
|
||||||
c := NewClient(client)
|
c := NewClient(client)
|
||||||
@ -113,22 +113,7 @@ func (c *Client) GetCookieMap() map[string][]*http.Cookie {
|
|||||||
|
|
||||||
// GetLoginUUID 获取登录的uuid
|
// GetLoginUUID 获取登录的uuid
|
||||||
func (c *Client) GetLoginUUID() (*http.Response, error) {
|
func (c *Client) GetLoginUUID() (*http.Response, error) {
|
||||||
path, _ := url.Parse(jslogin)
|
return c.mode.GetLoginUUID(c)
|
||||||
params := url.Values{}
|
|
||||||
redirectUrl, _ := url.Parse(webwxnewloginpage)
|
|
||||||
if c.mode == Desktop {
|
|
||||||
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 c.Do(req)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLoginQrcode 获取登录的二维吗
|
// GetLoginQrcode 获取登录的二维吗
|
||||||
@ -154,12 +139,7 @@ func (c *Client) CheckLogin(uuid string) (*http.Response, error) {
|
|||||||
|
|
||||||
// GetLoginInfo 请求获取LoginInfo
|
// GetLoginInfo 请求获取LoginInfo
|
||||||
func (c *Client) GetLoginInfo(path string) (*http.Response, error) {
|
func (c *Client) GetLoginInfo(path string) (*http.Response, error) {
|
||||||
req, _ := http.NewRequest(http.MethodGet, path, nil)
|
return c.mode.GetLoginInfo(c, path)
|
||||||
if c.mode == Desktop {
|
|
||||||
req.Header.Add("client-version", uosPatchClientVersion)
|
|
||||||
req.Header.Add("extspam", uosPatchExtspam)
|
|
||||||
}
|
|
||||||
return c.Do(req)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebInit 请求获取初始化信息
|
// WebInit 请求获取初始化信息
|
||||||
@ -203,12 +183,12 @@ func (c *Client) WebWxStatusNotify(request *BaseRequest, response *WebInitRespon
|
|||||||
func (c *Client) SyncCheck(request *BaseRequest, info *LoginInfo, response *WebInitResponse) (*http.Response, error) {
|
func (c *Client) SyncCheck(request *BaseRequest, info *LoginInfo, response *WebInitResponse) (*http.Response, error) {
|
||||||
path, _ := url.Parse(c.Domain.SyncHost() + synccheck)
|
path, _ := url.Parse(c.Domain.SyncHost() + synccheck)
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("r", strconv.FormatInt(time.Now().UnixNano() / 1e6, 10))
|
params.Add("r", strconv.FormatInt(time.Now().UnixNano()/1e6, 10))
|
||||||
params.Add("skey", info.SKey)
|
params.Add("skey", info.SKey)
|
||||||
params.Add("sid", info.WxSid)
|
params.Add("sid", info.WxSid)
|
||||||
params.Add("uin", strconv.FormatInt(info.WxUin, 10))
|
params.Add("uin", strconv.FormatInt(info.WxUin, 10))
|
||||||
params.Add("deviceid", request.DeviceID)
|
params.Add("deviceid", request.DeviceID)
|
||||||
params.Add("_", strconv.FormatInt(time.Now().UnixNano() / 1e6, 10))
|
params.Add("_", strconv.FormatInt(time.Now().UnixNano()/1e6, 10))
|
||||||
var syncKeyStringSlice = make([]string, response.SyncKey.Count)
|
var syncKeyStringSlice = make([]string, response.SyncKey.Count)
|
||||||
// 将SyncKey里面的元素按照特定的格式拼接起来
|
// 将SyncKey里面的元素按照特定的格式拼接起来
|
||||||
for index, item := range response.SyncKey.List {
|
for index, item := range response.SyncKey.List {
|
||||||
@ -226,7 +206,7 @@ func (c *Client) SyncCheck(request *BaseRequest, info *LoginInfo, response *WebI
|
|||||||
func (c *Client) WebWxGetContact(info *LoginInfo) (*http.Response, error) {
|
func (c *Client) WebWxGetContact(info *LoginInfo) (*http.Response, error) {
|
||||||
path, _ := url.Parse(c.Domain.BaseHost() + webwxgetcontact)
|
path, _ := url.Parse(c.Domain.BaseHost() + webwxgetcontact)
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("r", strconv.FormatInt(time.Now().UnixNano() / 1e6, 10))
|
params.Add("r", strconv.FormatInt(time.Now().UnixNano()/1e6, 10))
|
||||||
params.Add("skey", info.SKey)
|
params.Add("skey", info.SKey)
|
||||||
params.Add("req", "0")
|
params.Add("req", "0")
|
||||||
path.RawQuery = params.Encode()
|
path.RawQuery = params.Encode()
|
||||||
@ -239,7 +219,7 @@ func (c *Client) WebWxBatchGetContact(members Members, request *BaseRequest) (*h
|
|||||||
path, _ := url.Parse(c.Domain.BaseHost() + webwxbatchgetcontact)
|
path, _ := url.Parse(c.Domain.BaseHost() + webwxbatchgetcontact)
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("type", "ex")
|
params.Add("type", "ex")
|
||||||
params.Add("r", strconv.FormatInt(time.Now().UnixNano() / 1e6, 10))
|
params.Add("r", strconv.FormatInt(time.Now().UnixNano()/1e6, 10))
|
||||||
path.RawQuery = params.Encode()
|
path.RawQuery = params.Encode()
|
||||||
list := NewUserDetailItemList(members)
|
list := NewUserDetailItemList(members)
|
||||||
content := map[string]interface{}{
|
content := map[string]interface{}{
|
||||||
@ -511,7 +491,7 @@ func (c *Client) WebWxVerifyUser(storage *Storage, info RecommendInfo, verifyCon
|
|||||||
loginInfo := storage.LoginInfo
|
loginInfo := storage.LoginInfo
|
||||||
path, _ := url.Parse(c.Domain.BaseHost() + webwxverifyuser)
|
path, _ := url.Parse(c.Domain.BaseHost() + webwxverifyuser)
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("r", strconv.FormatInt(time.Now().UnixNano() / 1e6, 10))
|
params.Add("r", strconv.FormatInt(time.Now().UnixNano()/1e6, 10))
|
||||||
params.Add("lang", "zh_CN")
|
params.Add("lang", "zh_CN")
|
||||||
params.Add("pass_ticket", loginInfo.PassTicket)
|
params.Add("pass_ticket", loginInfo.PassTicket)
|
||||||
path.RawQuery = params.Encode()
|
path.RawQuery = params.Encode()
|
||||||
|
66
mode.go
Normal file
66
mode.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
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)
|
||||||
|
}
|
16
url.go
16
url.go
@ -1,13 +1,13 @@
|
|||||||
package openwechat
|
package openwechat
|
||||||
|
|
||||||
// mode 类型限制
|
//// mode 类型限制
|
||||||
type mode string
|
//type mode string
|
||||||
|
//
|
||||||
// 向外暴露2种模式
|
//// 向外暴露2种模式
|
||||||
const (
|
//const (
|
||||||
Normal mode = "normal"
|
// Normal mode = "normal"
|
||||||
Desktop mode = "desktop" // 突破网页版登录限制
|
// Desktop mode = "desktop" // 突破网页版登录限制
|
||||||
)
|
//)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
webwxinit = "/cgi-bin/mmwebwx-bin/webwxinit"
|
webwxinit = "/cgi-bin/mmwebwx-bin/webwxinit"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user