Skip to content

Commit 810f4e2

Browse files
JerryJerry
Jerry
authored and
Jerry
committed
format
1 parent 8475a92 commit 810f4e2

File tree

3 files changed

+0
-85
lines changed

3 files changed

+0
-85
lines changed

alipay/v3/client.go

-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"crypto/rsa"
55
"fmt"
66
"strings"
7-
"time"
87

98
"github.com/go-pay/crypto/xpem"
109
"github.com/go-pay/crypto/xrsa"
@@ -29,7 +28,6 @@ type ClientV3 struct {
2928
DebugSwitch gopay.DebugSwitch
3029
logger xlog.XLogger
3130
requestIdFunc xhttp.RequestIdHandler
32-
location *time.Location
3331
hc *xhttp.Client
3432
}
3533

alipay/v3/sign.go

-81
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ import (
99
"errors"
1010
"fmt"
1111
"net/http"
12-
"os"
13-
"strings"
1412
"time"
1513

16-
"github.com/go-pay/crypto/xpem"
1714
"github.com/go-pay/gopay"
1815
"github.com/go-pay/util"
1916
"github.com/go-pay/util/convert"
@@ -89,39 +86,6 @@ func (a *ClientV3) rsaSign(str string) (string, error) {
8986
return base64.StdEncoding.EncodeToString(result), nil
9087
}
9188

92-
// =============================== 获取SignData ===============================
93-
94-
// 需注意的是,公钥签名模式和公钥证书签名模式的不同之处
95-
// 验签文档:https://opendocs.alipay.com/open/200/106120
96-
func (a *ClientV3) getSignData(bs []byte, alipayCertSN string) (signData string, err error) {
97-
var (
98-
str = string(bs)
99-
indexStart = strings.Index(str, `_response":`)
100-
indexEnd int
101-
)
102-
indexStart = indexStart + 11
103-
bsLen := len(str)
104-
if alipayCertSN != "" {
105-
// 公钥证书模式
106-
if alipayCertSN != a.AliPayPublicCertSN {
107-
return gopay.NULL, fmt.Errorf("[%w], 当前使用的支付宝公钥证书SN[%s]与网关响应报文中的SN[%s]不匹配", gopay.CertNotMatchErr, a.AliPayPublicCertSN, alipayCertSN)
108-
}
109-
indexEnd = strings.Index(str, `,"alipay_cert_sn":`)
110-
if indexEnd > indexStart && bsLen > indexStart {
111-
signData = str[indexStart:indexEnd]
112-
return
113-
}
114-
return gopay.NULL, fmt.Errorf("[%w], value: %s", gopay.GetSignDataErr, str)
115-
}
116-
// 普通公钥模式
117-
indexEnd = strings.Index(str, `,"sign":`)
118-
if indexEnd > indexStart && bsLen > indexStart {
119-
signData = str[indexStart:indexEnd]
120-
return
121-
}
122-
return gopay.NULL, fmt.Errorf("[%w], value: %s", gopay.GetSignDataErr, str)
123-
}
124-
12589
// =============================== 同步验签 ===============================
12690

12791
func (a *ClientV3) autoVerifySignByCert(res *http.Response, body []byte) (err error) {
@@ -142,48 +106,3 @@ func (a *ClientV3) autoVerifySignByCert(res *http.Response, body []byte) (err er
142106
}
143107
return nil
144108
}
145-
146-
// =============================== 通用底层验签方法 ===============================
147-
148-
func verifySign(signData, sign, alipayPublicKey string) (err error) {
149-
publicKey, err := xpem.DecodePublicKey([]byte(alipayPublicKey))
150-
if err != nil {
151-
return err
152-
}
153-
signBytes, _ := base64.StdEncoding.DecodeString(sign)
154-
155-
h := sha256.New()
156-
h.Write([]byte(signData))
157-
if err = rsa.VerifyPKCS1v15(publicKey, crypto.SHA256, h.Sum(nil), signBytes); err != nil {
158-
return fmt.Errorf("[%w]: %v", gopay.VerifySignatureErr, err)
159-
}
160-
return nil
161-
}
162-
163-
func verifySignCert(signData, sign string, alipayPublicKeyCert any) (err error) {
164-
var (
165-
bytes []byte
166-
)
167-
if v, ok := alipayPublicKeyCert.(string); ok {
168-
if bytes, err = os.ReadFile(v); err != nil {
169-
return fmt.Errorf("支付宝公钥文件读取失败: %w", err)
170-
}
171-
} else {
172-
bytes, ok = alipayPublicKeyCert.([]byte)
173-
if !ok {
174-
return fmt.Errorf("支付宝公钥读取失败: %w", err)
175-
}
176-
}
177-
publicKey, err := xpem.DecodePublicKey(bytes)
178-
if err != nil {
179-
return err
180-
}
181-
signBytes, _ := base64.StdEncoding.DecodeString(sign)
182-
183-
h := sha256.New()
184-
h.Write([]byte(signData))
185-
if err = rsa.VerifyPKCS1v15(publicKey, crypto.SHA256, h.Sum(nil), signBytes); err != nil {
186-
return fmt.Errorf("[%w]: %v", gopay.VerifySignatureErr, err)
187-
}
188-
return nil
189-
}

wechat/v3/client.go

-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"crypto/rsa"
66
"errors"
77
"strings"
8-
"sync"
98

109
"github.com/go-pay/crypto/xpem"
1110
"github.com/go-pay/gopay"
@@ -22,7 +21,6 @@ type ClientV3 struct {
2221
WxSerialNo string
2322
proxyHost string // 代理host地址
2423
autoSign bool
25-
rwMu sync.RWMutex
2624
hc *xhttp.Client
2725
privateKey *rsa.PrivateKey
2826
wxPublicKey *rsa.PublicKey

0 commit comments

Comments
 (0)