示例程序
This commit is contained in:
5
go.mod
Normal file
5
go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module go-bot/bot
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/eatmoreapple/openwechat v1.1.11 // indirect
|
||||
2
go.sum
Normal file
2
go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/eatmoreapple/openwechat v1.1.11 h1:YJL8tUenK1NTflNPt5lWOl0KWcP0CTGjWNYAvN0dGFk=
|
||||
github.com/eatmoreapple/openwechat v1.1.11/go.mod h1:61HOzTyvLobGdgWhL68jfGNwTJEv0mhQ1miCXQrvWU8=
|
||||
44
main.go
Normal file
44
main.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/eatmoreapple/openwechat"
|
||||
)
|
||||
|
||||
func main() {
|
||||
bot := openwechat.DefaultBot()
|
||||
// bot := openwechat.DefaultBot(openwechat.Desktop) // 桌面模式,上面登录不上的可以尝试切换这种模式
|
||||
|
||||
// 注册消息处理函数
|
||||
bot.MessageHandler = func(msg *openwechat.Message) {
|
||||
if msg.IsText() && msg.Content == "ping" {
|
||||
msg.ReplyText("pong")
|
||||
}
|
||||
}
|
||||
// 注册登陆二维码回调
|
||||
bot.UUIDCallback = openwechat.PrintlnQrcodeUrl
|
||||
|
||||
// 登陆
|
||||
if err := bot.Login(); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取登陆的用户
|
||||
self, err := bot.GetCurrentUser()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取所有的好友
|
||||
friends, err := self.Friends()
|
||||
fmt.Println(friends, err)
|
||||
|
||||
// 获取所有的群组
|
||||
groups, err := self.Groups()
|
||||
fmt.Println(groups, err)
|
||||
|
||||
// 阻塞主goroutine, 直到发生异常或者用户主动退出
|
||||
bot.Block()
|
||||
}
|
||||
Reference in New Issue
Block a user