增加免扫码登录接口

This commit is contained in:
eatMoreApple 2021-08-04 15:58:30 +08:00
parent 3e14a0d5ed
commit 07b32939c9
4 changed files with 967 additions and 932 deletions

View File

@ -2,6 +2,7 @@ package openwechat
import ( import (
"bytes" "bytes"
"encoding/json"
"errors" "errors"
"net/http" "net/http"
"net/url" "net/url"
@ -345,6 +346,20 @@ func (c *Caller) WebWxRelationPin(request *BaseRequest, user *User, op uint8) er
return parseBaseResponseError(resp) return parseBaseResponseError(resp)
} }
// WebWxPushLogin 免扫码登陆接口
func (c *Caller) WebWxPushLogin(uin int) (*PushLoginResponse, error) {
resp, err := c.Client.WebWxPushLogin(uin)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var item PushLoginResponse
if err := json.NewDecoder(resp.Body).Decode(&item); err != nil {
return nil, err
}
return &item, nil
}
// 处理响应返回的结果是否正常 // 处理响应返回的结果是否正常
func parseBaseResponseError(resp *http.Response) error { func parseBaseResponseError(resp *http.Response) error {
defer resp.Body.Close() defer resp.Body.Close()

View File

@ -690,3 +690,12 @@ func (c *Client) WebWxRelationPin(request *BaseRequest, op uint8, user *User) (*
req.Header.Add("Content-Type", jsonContentType) req.Header.Add("Content-Type", jsonContentType)
return c.Do(req) return c.Do(req)
} }
// WebWxPushLogin 免扫码登陆接口
func (c *Client) WebWxPushLogin(uin int) (*http.Response, error) {
path, _ := url.Parse(c.Domain.BaseHost() + webwxpushloginurl)
params := url.Values{"uin": {strconv.Itoa(uin)}}
path.RawQuery = params.Encode()
req, _ := http.NewRequest(http.MethodGet, path.String(), nil)
return c.Do(req)
}

View File

@ -230,3 +230,13 @@ type UploadResponse struct {
BaseResponse BaseResponse BaseResponse BaseResponse
MediaId string MediaId string
} }
type PushLoginResponse struct {
Ret string `json:"ret"`
Msg string `json:"msg"`
UUID string `json:"uuid"`
}
func (p PushLoginResponse) Ok() bool {
return p.Ret == "0" && p.UUID != ""
}

1
url.go
View File

@ -30,6 +30,7 @@ const (
webwxupdatechatroom = "/cgi-bin/mmwebwx-bin/webwxupdatechatroom" webwxupdatechatroom = "/cgi-bin/mmwebwx-bin/webwxupdatechatroom"
webwxrevokemsg = "/cgi-bin/mmwebwx-bin/webwxrevokemsg" webwxrevokemsg = "/cgi-bin/mmwebwx-bin/webwxrevokemsg"
webwxcheckupload = "/cgi-bin/mmwebwx-bin/webwxcheckupload" webwxcheckupload = "/cgi-bin/mmwebwx-bin/webwxcheckupload"
webwxpushloginurl = "/cgi-bin/mmwebwx-bin/webwxpushloginurl"
webwxnewloginpage = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage" webwxnewloginpage = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage"
jslogin = "https://login.wx.qq.com/jslogin" jslogin = "https://login.wx.qq.com/jslogin"