- use
openwechat.Desktop
to 突破部分用户的登录限制 - from https://github.com/eatMoreApple/openwechat#快速开始 as-is
Last active
May 8, 2021 01:51
-
-
Save suntong/ee4f4000ea7fd94819c894fc3f88a4ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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