Skip to content

Demo code not working when qq.com is blocked #9

Closed
@suntong

Description

@suntong
$ cat /tmp/main.go 
package main

import (
	"fmt"
	"github.com/eatMoreApple/openwechat"
)

func main() {
	bot := openwechat.DefaultBot()

	// 注册消息处理函数
	bot.MessageHandler = func(msg *openwechat.Message) {
		if msg.IsText() {
			fmt.Println("你收到了一条新的文本消息")
		}
	}
	// 注册登陆二维码回调
	bot.UUIDCallback = openwechat.PrintlnQrcodeUrl

	// 登陆
	if err := bot.Login(); err != nil {
		fmt.Println(err)
		return
	}

	// 获取登陆的用户
	self, err := bot.GetCurrentUser()
	if err != nil {
		fmt.Println(err)
		return
	}

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

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

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

cd /tmp

go build main.go

$ main
Get "https://login.wx.qq.com/jslogin?_=1620437631&appid=wx782c26e4c19acffb&fun=new&lang=zh_CN&redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage": EOF

$ go version
go version go1.15.9 linux/amd64

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 10 (buster)
Release:	10
Codename:	buster

It wasn't like this before. What happened? Because this time I'm running under WSL? (was under Linux before)

如何搞定啊大佬?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions