Skip to content

Commit 335e823

Browse files
authored
fix: WECHATPAY2-SHA256-RSA2048 (#128)
1 parent de81100 commit 335e823

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

core/notify/notify.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import (
1818
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/validators"
1919
)
2020

21+
const rsaSignatureType = "WECHATPAY2-SHA256-RSA2048"
22+
const defaultSignatureType = rsaSignatureType
23+
const aeadAesGcmAlgorithm = "AEAD_AES_256_GCM"
24+
2125
// Handler 通知处理器,使用前先设置验签和解密的算法套件
2226
type Handler struct {
2327
cipherSuites map[string]CipherSuite
@@ -49,9 +53,9 @@ func (h *Handler) AddCipherSuite(cipherSuite CipherSuite) *Handler {
4953
// AddRSAWithAESGCM 添加一个 RSA + AES-GCM 的算法套件
5054
func (h *Handler) AddRSAWithAESGCM(verifier auth.Verifier, aesgcm cipher.AEAD) *Handler {
5155
v := CipherSuite{
52-
signatureType: "WECHATPAY2-RSA2048-SHA256",
56+
signatureType: rsaSignatureType,
5357
validator: *validators.NewWechatPayNotifyValidator(verifier),
54-
aeadAlgorithm: "AEAD_AES_256_GCM",
58+
aeadAlgorithm: aeadAesGcmAlgorithm,
5559
aead: aesgcm,
5660
}
5761
return h.AddCipherSuite(v)
@@ -65,7 +69,7 @@ func (h *Handler) ParseNotifyRequest(
6569
) (*Request, error) {
6670
signType := request.Header.Get("Wechatpay-Signature-Type")
6771
if signType == "" {
68-
signType = "WECHATPAY2-RSA2048-SHA256"
72+
signType = defaultSignatureType
6973
}
7074

7175
suite, ok := h.cipherSuites[signType]

core/notify/notify_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ func TestHandler_ParseNotifyRequest_UnmarshalContentError(t *testing.T) {
363363

364364
func TestHandler_processBody_InvalidAlgorithm(t *testing.T) {
365365
v := CipherSuite{
366-
signatureType: "WECHATPAY2-RSA2048-SHA256",
366+
signatureType: rsaSignatureType,
367367
validator: validators.WechatPayNotifyValidator{},
368-
aeadAlgorithm: "AEAD_AES_256_GCM",
368+
aeadAlgorithm: aeadAesGcmAlgorithm,
369369
aead: nil,
370370
}
371371

0 commit comments

Comments
 (0)