From 44780174fbe2d591cd050ffddc3cea168ebd8ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Thu, 12 Sep 2024 09:30:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=A1=E5=AF=86=E7=B1=BB=E5=9E=8B=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/zltx/internal/po/notify.go | 1 - plugins/zltx/internal/util.go | 33 +++--------------------------- plugins/zltx/internal/zltx_test.go | 2 +- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/plugins/zltx/internal/po/notify.go b/plugins/zltx/internal/po/notify.go index 7a4b2d3..7a66ade 100644 --- a/plugins/zltx/internal/po/notify.go +++ b/plugins/zltx/internal/po/notify.go @@ -7,6 +7,5 @@ type Notify struct { OutTradeNo string `json:"outTradeNo"` RechargeAccount string `json:"rechargeAccount"` Status vo.OrderStatus `json:"status"` - CardCode string `json:"cardCode"` // 卡密才可能会有 Sign string `json:"sign" validate:"required"` } diff --git a/plugins/zltx/internal/util.go b/plugins/zltx/internal/util.go index f27e113..dafce62 100644 --- a/plugins/zltx/internal/util.go +++ b/plugins/zltx/internal/util.go @@ -1,12 +1,8 @@ package internal import ( - "crypto/aes" - "crypto/cipher" "crypto/md5" - "encoding/base64" "encoding/hex" - "fmt" "gitea.cdlsxd.cn/sdk/plugin/utils" "net/url" "plugins/zltx/internal/po" @@ -50,36 +46,13 @@ func verify(notify *po.Notify, appKey string) bool { var kvStr []string for _, kv := range kvRows { - if kv.Key != "sign" && kv.Key != "version" { - kvStr = append(kvStr, kv.Key+"="+kv.Value) + if kv.Key == "sign" || kv.Key == "version" { + continue } + kvStr = append(kvStr, kv.Key+"="+kv.Value) } kvStr = append(kvStr, "key="+appKey) signStr := strings.Join(kvStr, "&") return sign([]byte(signStr)) == notify.Sign } - -func cardCodeDecode(code string, key []byte) (string, error) { - decoded, err := base64.StdEncoding.DecodeString(code) - if err != nil { - return "", fmt.Errorf("base64 decode error: %v", err) - } - block, err := aes.NewCipher(key) - if err != nil { - return "", fmt.Errorf("aes new cipher error: %v", err) - } - - if len(decoded) < aes.BlockSize { - return "", fmt.Errorf("ciphertext too short") - } - - decrypted := make([]byte, len(decoded)) - mode := cipher.NewCBCDecrypter(block, make([]byte, aes.BlockSize)) - mode.CryptBlocks(decrypted, decoded) - - padding := decrypted[len(decrypted)-1] - decrypted = decrypted[:len(decrypted)-int(padding)] - - return string(decrypted), nil -} diff --git a/plugins/zltx/internal/zltx_test.go b/plugins/zltx/internal/zltx_test.go index b411bd6..1ba3126 100644 --- a/plugins/zltx/internal/zltx_test.go +++ b/plugins/zltx/internal/zltx_test.go @@ -80,7 +80,7 @@ func TestNotify(t *testing.T) { Config: config(), Queries: nil, Headers: nil, - Body: []byte(`{"merchantId":10, "outTradeNo":"123", "rechargeAccount":"1866666666", "status":"01", "sign":"sign"}`), + Body: []byte(`{"merchantId":23329,"outTradeNo":"202409111714224026320002","rechargeAccount":"18512869479","sign":"474ACB521DEE99551153B6CE108FD06D","status":"01"}`), } t.Run("TestNotify", func(t *testing.T) { got, err := zltx.Notify(context.Background(), in)