From 6cd4fccba0b0c07c4a1b3cbeba105210df4f0246 Mon Sep 17 00:00:00 2001 From: eatmoreapple <15055461510@163.com> Date: Wed, 29 Sep 2021 11:19:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AEbot=E7=9A=84=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/bot.go b/bot.go index 9e084c5..c1f34e9 100644 --- a/bot.go +++ b/bot.go @@ -10,13 +10,14 @@ import ( ) type Bot struct { - ScanCallBack func(body []byte) // 扫码回调,可获取扫码用户的头像 - LoginCallBack func(body []byte) // 登陆回调 - LogoutCallBack func(bot *Bot) // 退出回调 - UUIDCallback func(uuid string) // 获取UUID的回调函数 - MessageHandler MessageHandler // 获取消息成功的handle - GetMessageErrorHandler func(err error) // 获取消息发生错误的handle - IsHot bool // 是否为热登录模式 + ScanCallBack func(body []byte) // 扫码回调,可获取扫码用户的头像 + LoginCallBack func(body []byte) // 登陆回调 + LogoutCallBack func(bot *Bot) // 退出回调 + UUIDCallback func(uuid string) // 获取UUID的回调函数 + SyncCheckCallback func(resp SyncCheckResponse) // 心跳回调 + MessageHandler MessageHandler // 获取消息成功的handle + GetMessageErrorHandler func(err error) // 获取消息发生错误的handle + IsHot bool // 是否为热登录模式 once sync.Once err error context context.Context @@ -234,6 +235,10 @@ func (b *Bot) asyncCall() error { if err != nil { return err } + // 执行心跳回调 + if b.SyncCheckCallback != nil { + b.SyncCheckCallback(*resp) + } // 如果不是正常的状态码返回,发生了错误,直接退出 if !resp.Success() { return resp @@ -357,6 +362,15 @@ func DefaultBot(modes ...mode) *Bot { caller.Client.mode = m bot := NewBot(caller) bot.UUIDCallback = PrintlnQrcodeUrl + bot.ScanCallBack = func(body []byte) { + log.Println("扫码成功,请在手机上确认登录") + } + bot.LoginCallBack = func(body []byte) { + log.Println("登录成功") + } + bot.SyncCheckCallback = func(resp SyncCheckResponse) { + log.Printf("RetCode:%s Selector:%s", resp.RetCode, resp.Selector) + } return bot }