Merge pull request #87 from ZhangIvan/master

扫码登入时自动打开默认浏览器访问二维码
This commit is contained in:
聂青 2021-10-20 13:07:36 +08:00 committed by GitHub
commit 58fd3a752c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

28
bot.go
View File

@ -6,6 +6,8 @@ import (
"errors"
"log"
"net/url"
"os/exec"
"runtime"
"sync"
)
@ -384,7 +386,31 @@ func GetQrcodeUrl(uuid string) string {
// PrintlnQrcodeUrl 打印登录二维码
func PrintlnQrcodeUrl(uuid string) {
println("访问下面网址扫描二维码登录")
println(GetQrcodeUrl(uuid))
qrcodeUrl := GetQrcodeUrl(uuid)
println(qrcodeUrl)
// browser open the login url
_ = open(qrcodeUrl)
}
// open opens the specified URL in the default browser of the user.
func open(url string) error {
var (
cmd string
args []string
)
switch runtime.GOOS {
case "windows":
cmd, args = "cmd", []string{"/c", "start"}
case "darwin":
cmd = "open"
default:
// "linux", "freebsd", "openbsd", "netbsd"
cmd = "xdg-open"
}
args = append(args, url)
return exec.Command(cmd, args...).Start()
}
func (b *Bot) handleMessage(messageList []*Message) {

View File

@ -33,7 +33,7 @@ func (f *Friend) SendImage(file *os.File) (*SentMessage, error) {
return f.Self.SendImageToFriend(f, file)
}
// SendVideo 发送图片消息
// SendVideo 发送视频消息
func (f *Friend) SendVideo(file *os.File) (*SentMessage, error) {
return f.Self.SendVideoToFriend(f, file)
}