@@ -3,8 +3,11 @@ package main
33import (
44 "fmt"
55 "log"
6+ "net/url"
7+ "os"
68 "time"
79
10+ "github.com/mdp/qrterminal/v3"
811 "github.com/wechaty/go-wechaty/wechaty"
912 wp "github.com/wechaty/go-wechaty/wechaty-puppet"
1013 "github.com/wechaty/go-wechaty/wechaty-puppet/filebox"
@@ -17,9 +20,7 @@ func main() {
1720 Token : "" ,
1821 }))
1922
20- bot .OnScan (func (ctx * wechaty.Context , qrCode string , status schemas.ScanStatus , data string ) {
21- fmt .Printf ("Scan QR Code to login: %v\n https://wechaty.github.io/qrcode/%s\n " , status , qrCode )
22- }).OnLogin (func (ctx * wechaty.Context , user * user.ContactSelf ) {
23+ bot .OnScan (onScan ).OnLogin (func (ctx * wechaty.Context , user * user.ContactSelf ) {
2324 fmt .Printf ("User %s logined\n " , user .Name ())
2425 }).OnMessage (onMessage ).OnLogout (func (ctx * wechaty.Context , user * user.ContactSelf , reason string ) {
2526 fmt .Printf ("User %s logouted: %s\n " , user , reason )
@@ -78,3 +79,14 @@ func onMessage(ctx *wechaty.Context, message *user.Message) {
7879 }
7980 log .Printf ("REPLY with urlLink: %s\n " , urlLink )
8081}
82+
83+ func onScan (ctx * wechaty.Context , qrCode string , status schemas.ScanStatus , data string ) {
84+ if status == schemas .ScanStatusWaiting || status == schemas .ScanStatusTimeout {
85+ qrterminal .GenerateHalfBlock (qrCode , qrterminal .L , os .Stdout )
86+
87+ qrcodeImageUrl := fmt .Sprintf ("https://wechaty.js.org/qrcode/%s" ,url .QueryEscape (qrCode ))
88+ fmt .Printf ("onScan: %s - %s\n " , status , qrcodeImageUrl )
89+ return
90+ }
91+ fmt .Printf ("onScan: %s\n " , status )
92+ }
0 commit comments