openwechat icon indicating copy to clipboard operation
openwechat copied to clipboard

DefaultBot()创建的非桌面模式,Demo程序bot.Login()返回非nil

Open blueicesir opened this issue 3 years ago • 2 comments

package main

import ( "fmt" "syscall" "os/exec" "github.com/blueicesir/openwechat" )

func FirefoxOpenQrcodeUrl(uuid string){ println("访问下面网址扫描二维码登录") qrcodeUrl := "https://login.weixin.qq.com/qrcode/"+uuid fmt.Printf("qrcodeUrl: %s\n",qrcodeUrl) cmd:=exec.Command("C:\Program Files\Mozilla Firefox\firefox.exe",qrcodeUrl) cmd.SysProcAttr=&syscall.SysProcAttr{HideWindow: false} cmd.Start() }

func main() { bot := openwechat.DefaultBot() // bot := openwechat.DefaultBot(openwechat.Desktop) // 桌面模式,上面登录不上的可以尝试切换这种模式

// 注册消息处理函数
bot.MessageHandler = func(msg *openwechat.Message) {
	if msg.IsText() && msg.Content == "ping" {
		msg.ReplyText("pong")
	}
}
// 注册登陆二维码回调
bot.UUIDCallback = FirefoxOpenQrcodeUrl

// 登陆
if err := bot.Login(); err != nil {
	fmt.Printf("Login() fail,%v\n",err)
	return
}

fmt.Println("GetCurrentUser()....")

// 获取登陆的用户
self, err := bot.GetCurrentUser()
if err != nil {
	fmt.Printf("GetCurrentUser() fail,%v\n",err)
	return
}



// 获取所有的好友
friends, err := self.Friends()
fmt.Println(friends, err)

// 获取所有的群组
groups, err := self.Groups()
fmt.Println(groups, err)


// 阻塞主goroutine, 直到发生异常或者用户主动退出
bot.Block()

}

结果错误 2022/09/22 14:20:50 扫码成功,请在手机上确认登录 2022/09/22 14:21:01 登录成功;-) Login() fail,XML syntax error on line 8: invalid UTF-8

似乎是返回的信息不是有效的XML或者字符集有问题,麻烦看看具体原因,桌面模式是正常的,不知道是否二维码扫描地址 https://login.weixin.qq.com/qrcode/ 这个前缀不正确还是其他,谢谢!

blueicesir avatar Sep 22 '22 06:09 blueicesir

返回的是一个网页

eatmoreapple avatar Sep 22 '22 15:09 eatmoreapple

我也遇到同样的问题, 桌面版的可以正常登录,但是会把电脑端的给踢下线, 不知道能不能出一个iPad 版的, 这样手机端的和电脑端的还可以正常使用, 平时iPad 端的用的比较少

ericuni avatar Sep 25 '22 10:09 ericuni

@ericuni 这个目前是不可以的。

eatmoreapple avatar Nov 27 '22 15:11 eatmoreapple