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

微信v3验签的一些疑问 #267

Open
Rebellioncry opened this issue Aug 27, 2022 · 6 comments
Open

微信v3验签的一些疑问 #267

Rebellioncry opened this issue Aug 27, 2022 · 6 comments
Labels
good first issue Good for newcomers

Comments

@Rebellioncry
Copy link

1.自动验签开启后,支付异步回调里还需要验签吗?
// wxPublicKey 通过 client.WxPublicKey() 获取 err = notifyReq.VerifySignByPK(wxPublicKey) if err != nil { xlog.Error(err) return }
这个手动验签是异步回调里必须的吗?

@iGoogle-ink
Copy link
Member

需要的,异步回调里的验签,是微信通知你支付结果的,为了安全起见,防止假通知,还是需要的

@Rebellioncry
Copy link
Author

@iGoogle-ink 那手动验签的前提是//client.SetPlatformCert([]byte(""), "")这个吗?
我现在的场景是后端一个接受来自对应多个不同client的支付回调结果,那我每次都得先new一个client才能验签吗?

@Rebellioncry
Copy link
Author

不知道我理解的对不对,自动验签开启好像client.WxPublicKey()就会有值,而不需要手动client.SetPlatformCert([]byte(""), ""),我理解的对吗?

@iGoogle-ink
Copy link
Member

不知道我理解的对不对,自动验签开启好像client.WxPublicKey()就会有值,而不需要手动client.SetPlatformCert([]byte(""), ""),我理解的对吗?

对的,你可以看看源码内容,开启自动验签,会自动定期获取微信公钥证书并自动赋值,所以就不用手动设置了

@Rebellioncry
Copy link
Author

我在微信支付成功异步回调里这样用对吗?
clientV3, err := wechat.NewClientV3(paySetting.MchId, paySetting.MchSerialNo, paySetting.MchKey, paySetting.CertPem) if err != nil { return err } err = clientV3.AutoVerifySign() if err != nil { return err } err = notifyReq.VerifySignByPK(clientV3.WxPublicKey()) if err != nil { return err }

还是说不能开启自动验签?你自动验签内部写了定时任务吗?
由于我的业务逻辑导致client每次都是变化的,都是要new一个使用,没有保存下来,我可能只用这一次client可能就废弃了,这样有效吗?
是否要用GetPlatformCertsWithoutClient获取了再set进来手动验签?
@iGoogle-ink 谢谢解答

@iGoogle-ink iGoogle-ink added the good first issue Good for newcomers label Jun 14, 2023
@luoqeng
Copy link

luoqeng commented Jul 21, 2023

我在微信支付成功异步回调里这样用对吗? clientV3, err := wechat.NewClientV3(paySetting.MchId, paySetting.MchSerialNo, paySetting.MchKey, paySetting.CertPem) if err != nil { return err } err = clientV3.AutoVerifySign() if err != nil { return err } err = notifyReq.VerifySignByPK(clientV3.WxPublicKey()) if err != nil { return err }

还是说不能开启自动验签?你自动验签内部写了定时任务吗? 由于我的业务逻辑导致client每次都是变化的,都是要new一个使用,没有保存下来,我可能只用这一次client可能就废弃了,这样有效吗? 是否要用GetPlatformCertsWithoutClient获取了再set进来手动验签? @iGoogle-ink 谢谢解答

全局初始化一个client就行了,每次new开销太大,多个goroutine并发使用client 是安全的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants