Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

常见问题解答: #111

Open
WalleV opened this issue Jun 17, 2022 · 1 comment
Open

常见问题解答: #111

WalleV opened this issue Jun 17, 2022 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@WalleV
Copy link
Contributor

WalleV commented Jun 17, 2022

V3支持“超时请求取消机制”

V3增加了context,可以通过context来控制timeout超时请求后,强制取消该词业务请求

// ------ 比如 强制取消获取部门列表接口 ------
ctx,cancel := context.WithTimeout(context.Background(), 1*time.Second)
dept,err := wechatWork.Department.List(ctx, id)



// ------ PowerLib中的单元测试 ------
func TestDataflow_WithContext(t *testing.T) {
	df := InitBaseDataflow()

	ctx, cancel := context.WithCancel(context.Background())

	done := make(chan struct{}, 1)

	go func() {
		time.Sleep(time.Second * 1)
		_, err := df.WithContext(ctx).Request()
		if !errors.Is(err, context.Canceled) {
			t.Error("cancel failed")
		}
		done <- struct{}{}
	}()

	cancel()
	select {
	case <-done:
	}
}

初始化报错 illegal base64 data at input byte 0

这个是由于Token和AESKey没有配置导致的,这个在公众号、企业微信配置里面都有这个参数,用来消息回调解密用。如果暂时不用消息解密,随便设置一个字符串进去即可。

例如:

officialAccount.NewOfficialAccount(&officialAccount.UserConfig{
	AppID:  conf.OffiAccount.AppID,     // 小程序、公众号或者企业微信的appid
	Secret: conf.OffiAccount.AppSecret, // 商户号 appID

	Token:  "xxx",
	AESKey: "xxx",

	ResponseType: os.Getenv("response_type"),
	Log: officialAccount.Log{
		Level: "debug",
		File:  "./wechat.log",
	},
	Cache:     cache,
	HttpDebug: true,
	Debug:     false,
	//"sandbox": true,
})
@WalleV WalleV added the documentation Improvements or additions to documentation label Jun 17, 2022
@WalleV WalleV pinned this issue Jun 17, 2022
@kakaisaname
Copy link

不能随便设置AESKey和Token,随便设置会报错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants