Comments (17)
你好,方便发一下你是如何初始化 notify.Handler
的吗?(贴代码的时候注意不要把商户私钥和 APIv3key的贴出来)
from wechatpay-go.
我也碰到同样的问题,网上看需要自己去实现这块业务,持续观望,希望官方跟进
from wechatpay-go.
certVisitor, err := payutils.LoadCertificateWithPath(config.GetConfig().WxPayCertificatePath)
if err != nil {
logger.Error(err.Error())
return nil, err
}
handler := notify.NewNotifyHandler(config.GetConfig().WxPayMchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(core.NewCertificateMapWithList([]*x509.Certificate{certVisitor})))
from wechatpay-go.
certVisitor, err := payutils.LoadCertificateWithPath(config.GetConfig().WxPayCertificatePath)
WxPayCertificatePath
是通过 API 下载得到的微信支付平台证书,还是商户的证书?
商户平台证书是指由微信支付 负责申请的,包含微信支付平台标识、公钥信息的证书。商户可以使用平台证书中的公钥进行验签。微信支付平台证书请调用“获取平台证书接口” 获取。
from wechatpay-go.
certVisitor, err := payutils.LoadCertificateWithPath(config.GetConfig().WxPayCertificatePath)
if err != nil {
logger.Error(err.Error())
return nil, err
}
handler := notify.NewNotifyHandler(config.GetConfig().WxPayMchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(core.NewCertificateMapWithList([]*x509.Certificate{certVisitor})))
这个初始化过程看起来没有问题,我再问个问题:接收到的回调通知http.Request
在传入 ParseNotifyRequest
方法之前,有做过其他操作吗?比如读取 req.Body
?
from wechatpay-go.
我找到问题 了,使用证书下载 这个函数 就可以了
certVisitor := downloader.MgrInstance().GetCertificateVisitor(config.GetConfig().WxPayMchID)
handler := notify.NewNotifyHandler(config.GetConfig().WxPayMchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(certVisitor))
我这没问题了,
from wechatpay-go.
certVisitor, err := payutils.LoadCertificateWithPath(config.GetConfig().WxPayCertificatePath)
if err != nil {
logger.Error(err.Error())
return nil, err
}
handler := notify.NewNotifyHandler(config.GetConfig().WxPayMchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(core.NewCertificateMapWithList([]*x509.Certificate{certVisitor})))这个初始化过程看起来没有问题,我再问个问题:接收到的回调通知
http.Request
在传入ParseNotifyRequest
方法之前,有做过其他操作吗?比如读取req.Body
?
我有将body转成map打印过
from wechatpay-go.
我将所有验签和解密代码提取出来,使用本地证书,自己重新组合实现了一下就没问题,用该go库自动下载证书的功能就报错
from wechatpay-go.
用该go库的本地证书验签解密也报错,反正搞不通。只能自己重写一下
from wechatpay-go.
certVisitor, err := payutils.LoadCertificateWithPath(config.GetConfig().WxPayCertificatePath)
if err != nil {
logger.Error(err.Error())
return nil, err
}
handler := notify.NewNotifyHandler(config.GetConfig().WxPayMchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(core.NewCertificateMapWithList([]*x509.Certificate{certVisitor})))这个初始化过程看起来没有问题,我再问个问题:接收到的回调通知
http.Request
在传入ParseNotifyRequest
方法之前,有做过其他操作吗?比如读取req.Body
?我有将body转成map打印过
有没有可能是你的前置逻辑把 http.Request
的 body 耗尽了,导致 notify.Handler
读到的 body 是空的,所以才验签失败了?
from wechatpay-go.
certVisitor, err := payutils.LoadCertificateWithPath(config.GetConfig().WxPayCertificatePath)
if err != nil {
logger.Error(err.Error())
return nil, err
}
handler := notify.NewNotifyHandler(config.GetConfig().WxPayMchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(core.NewCertificateMapWithList([]*x509.Certificate{certVisitor})))这个初始化过程看起来没有问题,我再问个问题:接收到的回调通知
http.Request
在传入ParseNotifyRequest
方法之前,有做过其他操作吗?比如读取req.Body
?我有将body转成map打印过
有没有可能是你的前置逻辑把
http.Request
的 body 耗尽了,导致notify.Handler
读到的 body 是空的,所以才验签失败了?
应该是证书问题,我换了gopay另一个库里的验签算法,也一样报错,这里验签证书能问一下要用哪里的证书吗?从商户网站下载证书有3个apiclient_cert.p12、apiclient_cert.pem、apiclient_key.pem我应该用哪个,我都试了都不行,如果不是这3个,那我要从哪里弄证书
from wechatpay-go.
certVisitor, err := payutils.LoadCertificateWithPath(config.GetConfig().WxPayCertificatePath)
if err != nil {
logger.Error(err.Error())
return nil, err
}
handler := notify.NewNotifyHandler(config.GetConfig().WxPayMchAPIv3Key, verifiers.NewSHA256WithRSAVerifier(core.NewCertificateMapWithList([]*x509.Certificate{certVisitor})))这个初始化过程看起来没有问题,我再问个问题:接收到的回调通知
http.Request
在传入ParseNotifyRequest
方法之前,有做过其他操作吗?比如读取req.Body
?我有将body转成map打印过
有没有可能是你的前置逻辑把
http.Request
的 body 耗尽了,导致notify.Handler
读到的 body 是空的,所以才验签失败了?应该是证书问题,我换了gopay另一个库里的验签算法,也一样报错,这里验签证书能问一下要用哪里的证书吗?从商户网站下载证书有3个apiclient_cert.p12、apiclient_cert.pem、apiclient_key.pem我应该用哪个,我都试了都不行,如果不是这3个,那我要从哪里弄证书
验签需要使用微信支付平台证书,平台证书需要通过通过平台证书下载接口进行下载。
本SDK中提供了平台证书下载工具将平台证书下载到本地。
你也可以参考使用平台证书下载管理器初始化 notify.Handler
,这样可以在运行时自动下载平台证书,无需手动下载。
from wechatpay-go.
报错:stdout: not valid wechatpay notify request: validate verify fail serial=[33AC6BABEBEE5B9F83D36C06BECBF24B20CE99CC] request-id=[] err=verifty signature with public key err:crypto/rsa: verification error
每次都要支付一下,调试很麻烦,试了很多
但是一般情况下如果证书不正确,错误提示会直接提示证书找不到才对。但是你的提示时验签失败,这里就比较奇怪了。
方便把你的代码(脱敏后)发给我看看怎么回事吗?
from wechatpay-go.
报错:stdout: not valid wechatpay notify request: validate verify fail serial=[33AC6BABEBEE5B9F83D36C06BECBF24B20CE99CC] request-id=[] err=verifty signature with public key err:crypto/rsa: verification error
每次都要支付一下,调试很麻烦,试了很多但是一般情况下如果证书不正确,错误提示会直接提示证书找不到才对。但是你的提示时验签失败,这里就比较奇怪了。
方便把你的代码(脱敏后)发给我看看怎么回事吗?
有没有可能是你的前置逻辑把 http.Request 的 body 耗尽了,导致 notify.Handler 读到的 body 是空的,所以才验签失败了?
确实是这个原因,我去掉了对body的打印就可以了
from wechatpay-go.
可以了,已解决
from wechatpay-go.
建议做个错误提示,提示一下body为空,免得后面有人又来踩坑
from wechatpay-go.
好的,谢谢提议。
from wechatpay-go.
Related Issues (20)
- Feature Request:为什么结构体不将数据类型结构化 HOT 1
- 为什么取字符串地址判断,不使用空字符串判断
- 到底怎么对字段加密解密,能不能说清楚,直接告诉我调用哪个函数就完了? HOT 2
- 在证书序列号部分增加格式
- 小程序下单仅提示参数错误,不返回错误的参数与原因
- 小程序下单仅提示参数错误,不返回错误的参数与原因
- 支持 Server Mock HOT 3
- Go SDK 下载不到core/notify
- /v3/ecommerce/account/cancel-applications/media 图片Content-Type非法 HOT 2
- > > 大佬怎么解决的呀
- 商家转账到零钱接口缺少文档中描述的 NotifyUrl 字段 HOT 1
- 希望后续可以打一个 release tag~ HOT 3
- WithWechatPayAutoAuthCipher报错Authorization不合法 HOT 1
- 支付分接口未实现吗? HOT 1
- 微信支付回调,验签失败 HOT 2
- 发起商家转账:未支持支付结果通知回调
- 希望改进下目录结构
- 【无效问题】回调解析payments.Transaction失败 HOT 1
- 支付回调,ParseNotifyRequest返回验证器中找不到证书
- 商家转账到零钱,报签名错误 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wechatpay-go.