添加公众号发消息功能
This commit is contained in:
parent
93564fabb5
commit
76eeb065e4
25
relations.go
25
relations.go
@ -441,3 +441,28 @@ func (m Mps) Search(limit int, condFuncList ...func(group *Mp) bool) (results Mp
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// SearchByUserName 根据用户名查找
|
||||
func (m Mps) SearchByUserName(limit int, userName string) (results Mps) {
|
||||
return m.Search(limit, func(group *Mp) bool { return group.UserName == userName })
|
||||
}
|
||||
|
||||
// SearchByNickName 根据昵称查找
|
||||
func (m Mps) SearchByNickName(limit int, nickName string) (results Mps) {
|
||||
return m.Search(limit, func(group *Mp) bool { return group.NickName == nickName })
|
||||
}
|
||||
|
||||
// SendText 发送文本消息给公众号
|
||||
func (m *Mp) SendText(content string) (*SentMessage, error) {
|
||||
return m.Self.SendTextToMp(m, content)
|
||||
}
|
||||
|
||||
// SendImage 发送图片消息给公众号
|
||||
func (m *Mp) SendImage(file *os.File) (*SentMessage, error) {
|
||||
return m.Self.SendImageToMp(m, file)
|
||||
}
|
||||
|
||||
// SendFile 发送文件消息给公众号
|
||||
func (m *Mp) SendFile(file *os.File) (*SentMessage, error) {
|
||||
return m.Self.SendFileToMp(m, file)
|
||||
}
|
||||
|
25
user.go
25
user.go
@ -625,3 +625,28 @@ func (m Members) init(self *Self) {
|
||||
func NewFriendHelper(self *Self) *Friend {
|
||||
return &Friend{&User{UserName: "filehelper", Self: self}}
|
||||
}
|
||||
|
||||
// SendMessageToMp 发送消息给公众号
|
||||
func (s *Self) SendMessageToMp(mp *Mp, msg *SendMessage) (*SentMessage, error) {
|
||||
return s.sendMessageToUser(mp.User, msg)
|
||||
}
|
||||
|
||||
// SendTextToMp 发送文本消息给公众号
|
||||
func (s *Self) SendTextToMp(mp *Mp, text string) (*SentMessage, error) {
|
||||
msg := NewTextSendMessage(text, s.UserName, mp.UserName)
|
||||
return s.SendMessageToMp(mp, msg)
|
||||
}
|
||||
|
||||
// SendImageToMp 发送图片消息给公众号
|
||||
func (s *Self) SendImageToMp(mp *Mp, file *os.File) (*SentMessage, error) {
|
||||
req := s.Bot.Storage.Request
|
||||
info := s.Bot.Storage.LoginInfo
|
||||
return s.Bot.Caller.WebWxSendImageMsg(file, req, info, s.UserName, mp.UserName)
|
||||
}
|
||||
|
||||
// SendFileToMp 发送文件给公众号
|
||||
func (s *Self) SendFileToMp(mp *Mp, 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, mp.UserName)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user