@@ -3,8 +3,11 @@ package main
3
3
import (
4
4
"fmt"
5
5
"log"
6
+ "net/url"
7
+ "os"
6
8
"time"
7
9
10
+ "github.com/mdp/qrterminal/v3"
8
11
"github.com/wechaty/go-wechaty/wechaty"
9
12
wp "github.com/wechaty/go-wechaty/wechaty-puppet"
10
13
"github.com/wechaty/go-wechaty/wechaty-puppet/filebox"
@@ -17,9 +20,7 @@ func main() {
17
20
Token : "" ,
18
21
}))
19
22
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 ) {
23
24
fmt .Printf ("User %s logined\n " , user .Name ())
24
25
}).OnMessage (onMessage ).OnLogout (func (ctx * wechaty.Context , user * user.ContactSelf , reason string ) {
25
26
fmt .Printf ("User %s logouted: %s\n " , user , reason )
@@ -78,3 +79,14 @@ func onMessage(ctx *wechaty.Context, message *user.Message) {
78
79
}
79
80
log .Printf ("REPLY with urlLink: %s\n " , urlLink )
80
81
}
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