wechatpay-apiv3 / wechatpay-go

微信支付 APIv3 的官方 Go Library
https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/index.shtml
Apache License 2.0
1.03k stars 141 forks source link

支持公钥验签 #226

Closed xy-peng closed 1 month ago

xy-peng commented 4 months ago

如何使用

var (
    wechatpayPublicKeyID       string = "00000000000000000000000000000000"          // 微信支付公钥ID
)

wechatpayPublicKey, err = utils.LoadPublicKeyWithPath("/path/to/wechatpay/pub_key.pem")
if err != nil {
    panic(fmt.Errorf("load wechatpay public key err:%s", err.Error()))
}

// 初始化 Client
opts := []core.ClientOption{
    option.WithWechatPayPublicKeyAuthCipher(
        mchID,
        mchCertificateSerialNumber, mchPrivateKey,
        wechatpayPublicKeyID, wechatpayPublicKey),
}
client, err := core.NewClient(ctx, opts...)

// 新商户,初始化 notify.Handler
handler := notify.NewNotifyHandler(
    mchAPIv3Key, 
    verifiers.NewSHA256WithRSAPubkeyVerifier(wechatpayPublicKeyID, *wechatPayPublicKey))

// 存量商户,初始化 notify.Handler
handler := notify.NewNotifyHandler(
    mchAPIv3Key,
    verifiers.NewSHA256WithRSACombinedVerifier(certificateVisitor, wechatpayPublicKeyID, *wechatPayPublicKey))
sonarcloud[bot] commented 4 months ago

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud