完善发送文件接口
This commit is contained in:
parent
2b313fe3d8
commit
17eeea93a9
1
2.json
Executable file
1
2.json
Executable file
@ -0,0 +1 @@
|
|||||||
|
{"Cookie":{"https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login?_=1619753139\u0026loginicon=true\u0026r=1025809\u0026tip=0\u0026uuid=gYZs5buMyQ%3D%3D":[],"https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login?_=1619753149\u0026loginicon=true\u0026r=1025809\u0026tip=0\u0026uuid=gYZs5buMyQ%3D%3D":[],"https://login.wx.qq.com/jslogin?_=1619753139\u0026appid=wx782c26e4c19acffb\u0026fun=new\u0026lang=zh_CN\u0026redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage%3Fmod%3Ddesktop":[],"https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage?ticket=ARAycLZsFpdoTlhU3tN5XVLN@qrticket_0\u0026uuid=gYZs5buMyQ==\u0026lang=zh_CN\u0026scan=1619753075":[{"Name":"wxuin","Value":"1708795586","Path":"/","Domain":"wx.qq.com","Expires":"2021-04-30T15:24:37Z","RawExpires":"Fri, 30-Apr-2021 15:24:37 GMT","MaxAge":0,"Secure":true,"HttpOnly":false,"SameSite":0,"Raw":"wxuin=1708795586; Domain=wx.qq.com; Path=/; Expires=Fri, 30-Apr-2021 15:24:37 GMT; Secure","Unparsed":null},{"Name":"wxsid","Value":"VZXeFoWYP7GCaAIq","Path":"/","Domain":"wx.qq.com","Expires":"2021-04-30T15:24:37Z","RawExpires":"Fri, 30-Apr-2021 15:24:37 GMT","MaxAge":0,"Secure":true,"HttpOnly":false,"SameSite":0,"Raw":"wxsid=VZXeFoWYP7GCaAIq; Domain=wx.qq.com; Path=/; Expires=Fri, 30-Apr-2021 15:24:37 GMT; Secure","Unparsed":null},{"Name":"wxloadtime","Value":"1619753077","Path":"/","Domain":"wx.qq.com","Expires":"2021-04-30T15:24:37Z","RawExpires":"Fri, 30-Apr-2021 15:24:37 GMT","MaxAge":0,"Secure":true,"HttpOnly":false,"SameSite":0,"Raw":"wxloadtime=1619753077; Domain=wx.qq.com; Path=/; Expires=Fri, 30-Apr-2021 15:24:37 GMT; Secure","Unparsed":null},{"Name":"mm_lang","Value":"zh_CN","Path":"/","Domain":"wx.qq.com","Expires":"2021-04-30T15:24:37Z","RawExpires":"Fri, 30-Apr-2021 15:24:37 GMT","MaxAge":0,"Secure":true,"HttpOnly":false,"SameSite":0,"Raw":"mm_lang=zh_CN; Domain=wx.qq.com; Path=/; Expires=Fri, 30-Apr-2021 15:24:37 GMT; Secure","Unparsed":null},{"Name":"webwx_data_ticket","Value":"gSfhlzZhJxwsKqOCSn0LU+PF","Path":"/","Domain":".qq.com","Expires":"2021-04-30T15:24:37Z","RawExpires":"Fri, 30-Apr-2021 15:24:37 GMT","MaxAge":0,"Secure":true,"HttpOnly":false,"SameSite":0,"Raw":"webwx_data_ticket=gSfhlzZhJxwsKqOCSn0LU+PF; Domain=.qq.com; Path=/; Expires=Fri, 30-Apr-2021 15:24:37 GMT; Secure","Unparsed":null},{"Name":"webwxuvid","Value":"e17d2b8599a5bfaff2286973a25242e25f0eb06badd866a87869372f4d33f13b2615dae18ba2e5757d246fba3023f0b4","Path":"/","Domain":"wx.qq.com","Expires":"2031-04-28T03:24:37Z","RawExpires":"Mon, 28-Apr-2031 03:24:37 GMT","MaxAge":0,"Secure":true,"HttpOnly":false,"SameSite":0,"Raw":"webwxuvid=e17d2b8599a5bfaff2286973a25242e25f0eb06badd866a87869372f4d33f13b2615dae18ba2e5757d246fba3023f0b4; Domain=wx.qq.com; Path=/; Expires=Mon, 28-Apr-2031 03:24:37 GMT; Secure","Unparsed":null},{"Name":"webwx_auth_ticket","Value":"CIsBELDQxc8MGoABhFi8lbeoxYn56VO3NskD7ei0hTFQ7yVTBm1VuwCE5mTQF0cRl3LOrIe3S7E5N0z1l7TITU1DUnirItDTYKppbK7PlSGspP2384nK48mQOVw7HQuP+/fFq3scSXqxCs0bQtDmJrZXulySMAudgNvN11KWu589QaYKarR9KuwmEAk=","Path":"/","Domain":"wx.qq.com","Expires":"2031-04-28T03:24:37Z","RawExpires":"Mon, 28-Apr-2031 03:24:37 GMT","MaxAge":0,"Secure":true,"HttpOnly":false,"SameSite":0,"Raw":"webwx_auth_ticket=CIsBELDQxc8MGoABhFi8lbeoxYn56VO3NskD7ei0hTFQ7yVTBm1VuwCE5mTQF0cRl3LOrIe3S7E5N0z1l7TITU1DUnirItDTYKppbK7PlSGspP2384nK48mQOVw7HQuP+/fFq3scSXqxCs0bQtDmJrZXulySMAudgNvN11KWu589QaYKarR9KuwmEAk=; Domain=wx.qq.com; Path=/; Expires=Mon, 28-Apr-2031 03:24:37 GMT; Secure","Unparsed":null}]},"Req":{"Uin":1708795586,"Sid":"VZXeFoWYP7GCaAIq","Skey":"@crypt_b8947f4b_bca6295f7539ee2d5656703e1136ce2b","DeviceID":"e624831403780183"},"Info":{"Ret":0,"WxUin":1708795586,"IsGrayScale":1,"Message":"","SKey":"@crypt_b8947f4b_bca6295f7539ee2d5656703e1136ce2b","WxSid":"VZXeFoWYP7GCaAIq","PassTicket":"7oehPxVcZlQmxgWmYmVU0YTBh3uz97QtXc3Ia9rhx%2Bpa%2B5VV4%2BdWMrX8glP4m5qN"}}
|
@ -308,9 +308,9 @@ func TestSendFile(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
f, _ := os.Open("Taylor+Swift+-+Red")
|
f, _ := os.Open("README.md")
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
msg, err := self.SendFileToFriend(fh, f)
|
msg, err := fh.SendFile(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
340
relations.go
340
relations.go
@ -1,289 +1,299 @@
|
|||||||
package openwechat
|
package openwechat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Friend struct{ *User }
|
type Friend struct{ *User }
|
||||||
|
|
||||||
// implement fmt.Stringer
|
// implement fmt.Stringer
|
||||||
func (f Friend) String() string {
|
func (f Friend) String() string {
|
||||||
return fmt.Sprintf("<Friend:%s>", f.NickName)
|
return fmt.Sprintf("<Friend:%s>", f.NickName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重命名当前好友
|
// 重命名当前好友
|
||||||
func (f *Friend) SetRemarkName(name string) error {
|
func (f *Friend) SetRemarkName(name string) error {
|
||||||
return f.Self.SetRemarkNameToFriend(f, name)
|
return f.Self.SetRemarkNameToFriend(f, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送自定义消息
|
// 发送自定义消息
|
||||||
func (f *Friend) SendMsg(msg *SendMessage) (*SentMessage, error) {
|
func (f *Friend) SendMsg(msg *SendMessage) (*SentMessage, error) {
|
||||||
return f.Self.SendMessageToFriend(f, msg)
|
return f.Self.SendMessageToFriend(f, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送文本消息
|
// 发送文本消息
|
||||||
func (f *Friend) SendText(content string) (*SentMessage, error) {
|
func (f *Friend) SendText(content string) (*SentMessage, error) {
|
||||||
return f.Self.SendTextToFriend(f, content)
|
return f.Self.SendTextToFriend(f, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送图片消息
|
// 发送图片消息
|
||||||
func (f *Friend) SendImage(file *os.File) (*SentMessage, error) {
|
func (f *Friend) SendImage(file *os.File) (*SentMessage, error) {
|
||||||
return f.Self.SendImageToFriend(f, file)
|
return f.Self.SendImageToFriend(f, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送文件消息
|
||||||
|
func (f *Friend) SendFile(file *os.File) (*SentMessage, error) {
|
||||||
|
return f.Self.SendFileToFriend(f, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拉该好友入群
|
// 拉该好友入群
|
||||||
func (f *Friend) AddIntoGroup(groups ...*Group) error {
|
func (f *Friend) AddIntoGroup(groups ...*Group) error {
|
||||||
return f.Self.AddFriendIntoManyGroups(f, groups...)
|
return f.Self.AddFriendIntoManyGroups(f, groups...)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Friends []*Friend
|
type Friends []*Friend
|
||||||
|
|
||||||
// 获取好友的数量
|
// 获取好友的数量
|
||||||
func (f Friends) Count() int {
|
func (f Friends) Count() int {
|
||||||
return len(f)
|
return len(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取第一个好友
|
// 获取第一个好友
|
||||||
func (f Friends) First() *Friend {
|
func (f Friends) First() *Friend {
|
||||||
if f.Count() > 0 {
|
if f.Count() > 0 {
|
||||||
return f[0]
|
return f[0]
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取最后一个好友
|
// 获取最后一个好友
|
||||||
func (f Friends) Last() *Friend {
|
func (f Friends) Last() *Friend {
|
||||||
if f.Count() > 0 {
|
if f.Count() > 0 {
|
||||||
return f[f.Count()-1]
|
return f[f.Count()-1]
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据用户名查找好友
|
// 根据用户名查找好友
|
||||||
func (f Friends) SearchByUserName(limit int, username string) (results Friends) {
|
func (f Friends) SearchByUserName(limit int, username string) (results Friends) {
|
||||||
return f.Search(limit, func(friend *Friend) bool { return friend.User.UserName == username })
|
return f.Search(limit, func(friend *Friend) bool { return friend.User.UserName == username })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据昵称查找好友
|
// 根据昵称查找好友
|
||||||
func (f Friends) SearchByNickName(limit int, nickName string) (results Friends) {
|
func (f Friends) SearchByNickName(limit int, nickName string) (results Friends) {
|
||||||
return f.Search(limit, func(friend *Friend) bool { return friend.User.NickName == nickName })
|
return f.Search(limit, func(friend *Friend) bool { return friend.User.NickName == nickName })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据备注查找好友
|
// 根据备注查找好友
|
||||||
func (f Friends) SearchByRemarkName(limit int, remarkName string) (results Friends) {
|
func (f Friends) SearchByRemarkName(limit int, remarkName string) (results Friends) {
|
||||||
return f.Search(limit, func(friend *Friend) bool { return friend.User.RemarkName == remarkName })
|
return f.Search(limit, func(friend *Friend) bool { return friend.User.RemarkName == remarkName })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据自定义条件查找好友
|
// 根据自定义条件查找好友
|
||||||
func (f Friends) Search(limit int, condFuncList ...func(friend *Friend) bool) (results Friends) {
|
func (f Friends) Search(limit int, condFuncList ...func(friend *Friend) bool) (results Friends) {
|
||||||
if condFuncList == nil {
|
if condFuncList == nil {
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
if limit <= 0 {
|
if limit <= 0 {
|
||||||
limit = f.Count()
|
limit = f.Count()
|
||||||
}
|
}
|
||||||
for _, member := range f {
|
for _, member := range f {
|
||||||
if results.Count() == limit {
|
if results.Count() == limit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
var passCount int
|
var passCount int
|
||||||
for _, condFunc := range condFuncList {
|
for _, condFunc := range condFuncList {
|
||||||
if condFunc(member) {
|
if condFunc(member) {
|
||||||
passCount++
|
passCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if passCount == len(condFuncList) {
|
if passCount == len(condFuncList) {
|
||||||
results = append(results, member)
|
results = append(results, member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向slice的好友依次发送消息
|
// 向slice的好友依次发送消息
|
||||||
func (f Friends) SendMsg(msg *SendMessage, delay ...time.Duration) error {
|
func (f Friends) SendMsg(msg *SendMessage, delay ...time.Duration) error {
|
||||||
total := getTotalDuration(delay...)
|
total := getTotalDuration(delay...)
|
||||||
for _, friend := range f {
|
for _, friend := range f {
|
||||||
time.Sleep(total)
|
time.Sleep(total)
|
||||||
if _, err := friend.SendMsg(msg); err != nil {
|
if _, err := friend.SendMsg(msg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向slice的好友依次发送文本消息
|
// 向slice的好友依次发送文本消息
|
||||||
func (f Friends) SendText(text string, delay ...time.Duration) error {
|
func (f Friends) SendText(text string, delay ...time.Duration) error {
|
||||||
total := getTotalDuration(delay...)
|
total := getTotalDuration(delay...)
|
||||||
for _, friend := range f {
|
for _, friend := range f {
|
||||||
time.Sleep(total)
|
time.Sleep(total)
|
||||||
if _, err := friend.SendText(text); err != nil {
|
if _, err := friend.SendText(text); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向slice的好友依次发送图片消息
|
// 向slice的好友依次发送图片消息
|
||||||
func (f Friends) SendImage(file *os.File, delay ...time.Duration) error {
|
func (f Friends) SendImage(file *os.File, delay ...time.Duration) error {
|
||||||
total := getTotalDuration(delay...)
|
total := getTotalDuration(delay...)
|
||||||
for _, friend := range f {
|
for _, friend := range f {
|
||||||
time.Sleep(total)
|
time.Sleep(total)
|
||||||
if _, err := friend.SendImage(file); err != nil {
|
if _, err := friend.SendImage(file); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Group struct{ *User }
|
type Group struct{ *User }
|
||||||
|
|
||||||
// implement fmt.Stringer
|
// implement fmt.Stringer
|
||||||
func (g Group) String() string {
|
func (g Group) String() string {
|
||||||
return fmt.Sprintf("<Group:%s>", g.NickName)
|
return fmt.Sprintf("<Group:%s>", g.NickName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发行消息给当前的群组
|
// 发行消息给当前的群组
|
||||||
func (g *Group) SendMsg(msg *SendMessage) (*SentMessage, error) {
|
func (g *Group) SendMsg(msg *SendMessage) (*SentMessage, error) {
|
||||||
return g.Self.SendMessageToGroup(g, msg)
|
return g.Self.SendMessageToGroup(g, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发行文本消息给当前的群组
|
// 发行文本消息给当前的群组
|
||||||
func (g *Group) SendText(content string) (*SentMessage, error) {
|
func (g *Group) SendText(content string) (*SentMessage, error) {
|
||||||
return g.Self.SendTextToGroup(g, content)
|
return g.Self.SendTextToGroup(g, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发行图片消息给当前的群组
|
// 发行图片消息给当前的群组
|
||||||
func (g *Group) SendImage(file *os.File) (*SentMessage, error) {
|
func (g *Group) SendImage(file *os.File) (*SentMessage, error) {
|
||||||
return g.Self.SendImageToGroup(g, file)
|
return g.Self.SendImageToGroup(g, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送文件给当前的群组
|
||||||
|
func (g *Group) SendFile(file *os.File) (*SentMessage, error) {
|
||||||
|
return g.Self.SendFileToGroup(g, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有的群成员
|
// 获取所有的群成员
|
||||||
func (g *Group) Members() (Members, error) {
|
func (g *Group) Members() (Members, error) {
|
||||||
group, err := g.Detail()
|
group, err := g.Detail()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return group.MemberList, nil
|
return group.MemberList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 拉好友入群
|
// 拉好友入群
|
||||||
func (g *Group) AddFriendsIn(friends ...*Friend) error {
|
func (g *Group) AddFriendsIn(friends ...*Friend) error {
|
||||||
return g.Self.AddFriendsIntoGroup(g, friends...)
|
return g.Self.AddFriendsIntoGroup(g, friends...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从群聊中移除用户
|
// 从群聊中移除用户
|
||||||
// Deprecated
|
// Deprecated
|
||||||
// 无论是网页版,还是程序上都不起作用
|
// 无论是网页版,还是程序上都不起作用
|
||||||
func (g *Group) RemoveMembers(members Members) error {
|
func (g *Group) RemoveMembers(members Members) error {
|
||||||
return g.Self.RemoveMemberFromGroup(g, members)
|
return g.Self.RemoveMemberFromGroup(g, members)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Groups []*Group
|
type Groups []*Group
|
||||||
|
|
||||||
// 获取群组数量
|
// 获取群组数量
|
||||||
func (g Groups) Count() int {
|
func (g Groups) Count() int {
|
||||||
return len(g)
|
return len(g)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取第一个群组
|
// 获取第一个群组
|
||||||
func (g Groups) First() *Group {
|
func (g Groups) First() *Group {
|
||||||
if g.Count() > 0 {
|
if g.Count() > 0 {
|
||||||
return g[0]
|
return g[0]
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取最后一个群组
|
// 获取最后一个群组
|
||||||
func (g Groups) Last() *Group {
|
func (g Groups) Last() *Group {
|
||||||
if g.Count() > 0 {
|
if g.Count() > 0 {
|
||||||
return g[g.Count()-1]
|
return g[g.Count()-1]
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向群组依次发送消息, 支持发送延迟
|
// 向群组依次发送消息, 支持发送延迟
|
||||||
func (g Groups) SendMsg(msg *SendMessage, delay ...time.Duration) error {
|
func (g Groups) SendMsg(msg *SendMessage, delay ...time.Duration) error {
|
||||||
total := getTotalDuration(delay...)
|
total := getTotalDuration(delay...)
|
||||||
for _, group := range g {
|
for _, group := range g {
|
||||||
time.Sleep(total)
|
time.Sleep(total)
|
||||||
if _, err := group.SendMsg(msg); err != nil {
|
if _, err := group.SendMsg(msg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向群组依次发送文本消息, 支持发送延迟
|
// 向群组依次发送文本消息, 支持发送延迟
|
||||||
func (g Groups) SendText(text string, delay ...time.Duration) error {
|
func (g Groups) SendText(text string, delay ...time.Duration) error {
|
||||||
total := getTotalDuration(delay...)
|
total := getTotalDuration(delay...)
|
||||||
for _, group := range g {
|
for _, group := range g {
|
||||||
time.Sleep(total)
|
time.Sleep(total)
|
||||||
if _, err := group.SendText(text); err != nil {
|
if _, err := group.SendText(text); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向群组依次发送图片消息, 支持发送延迟
|
// 向群组依次发送图片消息, 支持发送延迟
|
||||||
func (g Groups) SendImage(file *os.File, delay ...time.Duration) error {
|
func (g Groups) SendImage(file *os.File, delay ...time.Duration) error {
|
||||||
total := getTotalDuration(delay...)
|
total := getTotalDuration(delay...)
|
||||||
for _, group := range g {
|
for _, group := range g {
|
||||||
time.Sleep(total)
|
time.Sleep(total)
|
||||||
if _, err := group.SendImage(file); err != nil {
|
if _, err := group.SendImage(file); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据用户名查找群组
|
// 根据用户名查找群组
|
||||||
func (g Groups) SearchByUserName(limit int, username string) (results Groups) {
|
func (g Groups) SearchByUserName(limit int, username string) (results Groups) {
|
||||||
return g.Search(limit, func(group *Group) bool { return group.UserName == username })
|
return g.Search(limit, func(group *Group) bool { return group.UserName == username })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据昵称查找群组
|
// 根据昵称查找群组
|
||||||
func (g Groups) SearchByNickName(limit int, nickName string) (results Groups) {
|
func (g Groups) SearchByNickName(limit int, nickName string) (results Groups) {
|
||||||
return g.Search(limit, func(group *Group) bool { return group.NickName == nickName })
|
return g.Search(limit, func(group *Group) bool { return group.NickName == nickName })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据备注查找群组
|
// 根据备注查找群组
|
||||||
func (g Groups) SearchByRemarkName(limit int, remarkName string) (results Groups) {
|
func (g Groups) SearchByRemarkName(limit int, remarkName string) (results Groups) {
|
||||||
return g.Search(limit, func(group *Group) bool { return group.RemarkName == remarkName })
|
return g.Search(limit, func(group *Group) bool { return group.RemarkName == remarkName })
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据自定义条件查找群组
|
// 根据自定义条件查找群组
|
||||||
func (g Groups) Search(limit int, condFuncList ...func(group *Group) bool) (results Groups) {
|
func (g Groups) Search(limit int, condFuncList ...func(group *Group) bool) (results Groups) {
|
||||||
if condFuncList == nil {
|
if condFuncList == nil {
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
if limit <= 0 {
|
if limit <= 0 {
|
||||||
limit = g.Count()
|
limit = g.Count()
|
||||||
}
|
}
|
||||||
for _, member := range g {
|
for _, member := range g {
|
||||||
if results.Count() == limit {
|
if results.Count() == limit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
var passCount int
|
var passCount int
|
||||||
for _, condFunc := range condFuncList {
|
for _, condFunc := range condFuncList {
|
||||||
if condFunc(member) {
|
if condFunc(member) {
|
||||||
passCount++
|
passCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if passCount == len(condFuncList) {
|
if passCount == len(condFuncList) {
|
||||||
results = append(results, member)
|
results = append(results, member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 公众号对象
|
// 公众号对象
|
||||||
type Mp struct{ *User }
|
type Mp struct{ *User }
|
||||||
|
|
||||||
func (m Mp) String() string {
|
func (m Mp) String() string {
|
||||||
return fmt.Sprintf("<Mp:%s>", m.NickName)
|
return fmt.Sprintf("<Mp:%s>", m.NickName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 公众号组对象
|
// 公众号组对象
|
||||||
@ -291,46 +301,46 @@ type Mps []*Mp
|
|||||||
|
|
||||||
// 数量统计
|
// 数量统计
|
||||||
func (m Mps) Count() int {
|
func (m Mps) Count() int {
|
||||||
return len(m)
|
return len(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取第一个
|
// 获取第一个
|
||||||
func (m Mps) First() *Mp {
|
func (m Mps) First() *Mp {
|
||||||
if m.Count() > 0 {
|
if m.Count() > 0 {
|
||||||
return m[0]
|
return m[0]
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取最后一个
|
// 获取最后一个
|
||||||
func (m Mps) Last() *Mp {
|
func (m Mps) Last() *Mp {
|
||||||
if m.Count() > 0 {
|
if m.Count() > 0 {
|
||||||
return m[m.Count()-1]
|
return m[m.Count()-1]
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据自定义条件查找
|
// 根据自定义条件查找
|
||||||
func (m Mps) Search(limit int, condFuncList ...func(group *Mp) bool) (results Mps) {
|
func (m Mps) Search(limit int, condFuncList ...func(group *Mp) bool) (results Mps) {
|
||||||
if condFuncList == nil {
|
if condFuncList == nil {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
if limit <= 0 {
|
if limit <= 0 {
|
||||||
limit = m.Count()
|
limit = m.Count()
|
||||||
}
|
}
|
||||||
for _, member := range m {
|
for _, member := range m {
|
||||||
if results.Count() == limit {
|
if results.Count() == limit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
var passCount int
|
var passCount int
|
||||||
for _, condFunc := range condFuncList {
|
for _, condFunc := range condFuncList {
|
||||||
if condFunc(member) {
|
if condFunc(member) {
|
||||||
passCount++
|
passCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if passCount == len(condFuncList) {
|
if passCount == len(condFuncList) {
|
||||||
results = append(results, member)
|
results = append(results, member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
8
user.go
8
user.go
@ -242,6 +242,7 @@ func (s *Self) SendImageToFriend(friend *Friend, file *os.File) (*SentMessage, e
|
|||||||
return s.Bot.Caller.WebWxSendImageMsg(file, req, info, s.UserName, friend.UserName)
|
return s.Bot.Caller.WebWxSendImageMsg(file, req, info, s.UserName, friend.UserName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发送文件给好友
|
||||||
func (s *Self) SendFileToFriend(friend *Friend, file *os.File) (*SentMessage, error) {
|
func (s *Self) SendFileToFriend(friend *Friend, file *os.File) (*SentMessage, error) {
|
||||||
req := s.Bot.storage.Request
|
req := s.Bot.storage.Request
|
||||||
info := s.Bot.storage.LoginInfo
|
info := s.Bot.storage.LoginInfo
|
||||||
@ -339,6 +340,13 @@ func (s *Self) SendImageToGroup(group *Group, file *os.File) (*SentMessage, erro
|
|||||||
return s.Bot.Caller.WebWxSendImageMsg(file, req, info, s.UserName, group.UserName)
|
return s.Bot.Caller.WebWxSendImageMsg(file, req, info, s.UserName, group.UserName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发送文件给群组
|
||||||
|
func (s *Self) SendFileToGroup(group *Group, file *os.File) (*SentMessage, error) {
|
||||||
|
req := s.Bot.storage.Request
|
||||||
|
info := s.Bot.storage.LoginInfo
|
||||||
|
return s.Bot.Caller.WebWxSendFile(file, req, info, s.UserName, group.UserName)
|
||||||
|
}
|
||||||
|
|
||||||
// 撤回消息
|
// 撤回消息
|
||||||
// sentMessage, err := friend.SendText("message")
|
// sentMessage, err := friend.SendText("message")
|
||||||
// if err == nil {
|
// if err == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user