esap/wechat

远程获取accesstoken这样写有问题吗,会报错,多谢了

Closed this issue · 1 comments

cfg := &wechat.WxConfig{
		Token:          "",
		AppId:          "",
		Secret:         "",
		EncodingAESKey: "",
		ExternalTokenHandler: func(appId string, appName ...string) *wechat.AccessToken {
			fmt.Println("运行getAccessToken")
                        // TODO fetch远程数据,暂时写死
			var accessToken *wechat.AccessToken
			accessToken.AccessToken = "44_eqMb2oNPeuiwS0LKsA42UXRKpuHVbutgLaENZY1j27Mp4_d1Ao64AbnkmMjD4wKKT-ktN17rUddK_sd10RXk7YmstjboRZ84qHIdUnD30_nUg_FDuWoiwswz7RuRUHqccFap8zNLM_rl987dZBJbAIAHJR"
			accessToken.ExpiresIn = 1619153293
			return accessToken
		},
	}
运行getAccessToken
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x12a2a1b]

goroutine 1 [running]:
main.main.func1(0x13344f4, 0x12, 0xc000098db0, 0x1, 0x1, 0x1ed)
	/Users/zyk/go/src/waimai-mp/main.go:44 +0x7b
github.com/esap/wechat.(*Server).getAccessToken(0xc00009e9c0, 0xc00009e9c0, 0x14f1760)
	/Users/zyk/go/pkg/mod/github.com/esap/wechat@v1.1.0/accesstoken.go:54 +0x19c
github.com/esap/wechat.New(0xc0000b5f00, 0x1041a0a)
	/Users/zyk/go/pkg/mod/github.com/esap/wechat@v1.1.0/server.go:121 +0x1aa
main.main()
	/Users/zyk/go/src/waimai-mp/main.go:50 +0xcf
exit status 2

指针问题,已解决