添加拉好友加群支持
This commit is contained in:
parent
5e109f21c2
commit
f089588ad2
26
bot_test.go
26
bot_test.go
@ -59,3 +59,29 @@ func TestMps(t *testing.T) {
|
||||
}
|
||||
t.Log(mps)
|
||||
}
|
||||
|
||||
func TestAddFriendIntoChatRoom(t *testing.T) {
|
||||
self, err := getSelf(Desktop)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
groups, err := self.Groups()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
friends, err := self.Friends()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
searchGroups := groups.SearchByNickName(1, "厉害了")
|
||||
if searchGroups != nil {
|
||||
g := searchGroups.First()
|
||||
addFriends := friends.SearchByRemarkName(1, "1")
|
||||
if err := g.AddFriendsIn(addFriends...); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -227,6 +227,15 @@ func (c *Caller) Logout(info *LoginInfo) error {
|
||||
return parseBaseResponseError(resp)
|
||||
}
|
||||
|
||||
// 拉好友入群
|
||||
func (c *Caller) AddFriendIntoChatRoom(req *BaseRequest, group *Group, friends ...*Friend) error {
|
||||
if len(friends) == 0 {
|
||||
return errors.New("no friends found")
|
||||
}
|
||||
resp := NewReturnResponse(c.Client.AddMemberIntoChatRoom(req, group, friends...))
|
||||
return parseBaseResponseError(resp)
|
||||
}
|
||||
|
||||
// 处理响应返回的结果是否正常
|
||||
func parseBaseResponseError(resp *ReturnResponse) error {
|
||||
if resp.Err() != nil {
|
||||
|
19
client.go
19
client.go
@ -411,3 +411,22 @@ func (c *Client) Logout(info *LoginInfo) (*http.Response, error) {
|
||||
path.RawQuery = params.Encode()
|
||||
return c.Get(path.String())
|
||||
}
|
||||
|
||||
// 添加用户进群聊
|
||||
func (c *Client) AddMemberIntoChatRoom(req *BaseRequest, group *Group, friends ...*Friend) (*http.Response, error) {
|
||||
path, _ := url.Parse(c.webWxUpdateChatRoomUrl)
|
||||
params := url.Values{}
|
||||
params.Add("fun", "addmember")
|
||||
path.RawQuery = params.Encode()
|
||||
addMemberList := make([]string, 0)
|
||||
for _, friend := range friends {
|
||||
addMemberList = append(addMemberList, friend.UserName)
|
||||
}
|
||||
content := map[string]interface{}{
|
||||
"ChatRoomName": group.UserName,
|
||||
"BaseRequest": req,
|
||||
"AddMemberList": strings.Join(addMemberList, ","),
|
||||
}
|
||||
buffer, _ := ToBuffer(content)
|
||||
return c.Post(path.String(), jsonContentType, buffer)
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ const (
|
||||
webWxGetVideoNormalUrl = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetvideo"
|
||||
webWxLogoutNormalUrl = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxlogout"
|
||||
webWxGetMediaNormalUrl = "https://file.wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetmedia"
|
||||
webWxUpdateChatRoomNormalUrl = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxupdatechatroom"
|
||||
|
||||
// Desktop urls
|
||||
|
||||
@ -61,6 +62,7 @@ const (
|
||||
webWxGetVideoDesktopUrl = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetvideo"
|
||||
webWxLogoutDesktopUrl = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxlogout"
|
||||
webWxGetMediaDesktopUrl = "https://file.wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetmedia"
|
||||
webWxUpdateChatRoomDesktopUrl = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxupdatechatroom"
|
||||
|
||||
jsonContentType = "application/json; charset=utf-8"
|
||||
uosPatchClientVersion = "2.0.0"
|
||||
|
@ -144,6 +144,11 @@ func (g *Group) Members() (Members, error) {
|
||||
return group.MemberList, nil
|
||||
}
|
||||
|
||||
// 拉好友入群
|
||||
func (g *Group) AddFriendsIn(friends ...*Friend) error {
|
||||
return g.Self.Bot.Caller.AddFriendIntoChatRoom(g.Self.Bot.storage.Request, g, friends...)
|
||||
}
|
||||
|
||||
type Groups []*Group
|
||||
|
||||
func (g Groups) Count() int {
|
||||
|
3
url.go
3
url.go
@ -21,6 +21,7 @@ type UrlManager struct {
|
||||
webWxGetVideoUrl string
|
||||
webWxLogoutUrl string
|
||||
webWxGetMediaUrl string
|
||||
webWxUpdateChatRoomUrl string
|
||||
}
|
||||
|
||||
var (
|
||||
@ -45,6 +46,7 @@ var (
|
||||
webWxGetVideoUrl: webWxGetVideoDesktopUrl,
|
||||
webWxLogoutUrl: webWxLogoutDesktopUrl,
|
||||
webWxGetMediaUrl: webWxGetMediaDesktopUrl,
|
||||
webWxUpdateChatRoomUrl: webWxUpdateChatRoomDesktopUrl,
|
||||
}
|
||||
|
||||
// 网页版
|
||||
@ -68,6 +70,7 @@ var (
|
||||
webWxGetVideoUrl: webWxGetVideoNormalUrl,
|
||||
webWxLogoutUrl: webWxLogoutNormalUrl,
|
||||
webWxGetMediaUrl: webWxGetMediaNormalUrl,
|
||||
webWxUpdateChatRoomUrl: webWxUpdateChatRoomNormalUrl,
|
||||
}
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user