Skip to content

Instantly share code, notes, and snippets.

@suntong
Last active May 8, 2021 01:51
Show Gist options
  • Save suntong/ee4f4000ea7fd94819c894fc3f88a4ac to your computer and use it in GitHub Desktop.
Save suntong/ee4f4000ea7fd94819c894fc3f88a4ac to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/eatMoreApple/openwechat"
)
func main() {
bot := openwechat.DefaultBot(openwechat.Desktop)
// 注册消息处理函数
bot.MessageHandler = func(msg *openwechat.Message) {
if msg.IsText() {
fmt.Println("你收到了一条新的文本消息")
}
}
// 注册登陆二维码回调
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()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment