9
9
"github.com/go-pay/crypto/xpem"
10
10
"github.com/go-pay/gopay"
11
11
"github.com/go-pay/gopay/pkg/xhttp"
12
+ "github.com/go-pay/smap"
12
13
"github.com/go-pay/xlog"
13
14
)
14
15
@@ -27,7 +28,7 @@ type ClientV3 struct {
27
28
DebugSwitch gopay.DebugSwitch
28
29
requestIdFunc xhttp.RequestIdHandler
29
30
logger xlog.XLogger
30
- SnCertMap map [string ] * rsa.PublicKey // key: serial_no
31
+ SnCertMap smap. Map [string , * rsa.PublicKey ] // key: serial_no
31
32
}
32
33
33
34
// NewClientV3 初始化微信客户端 V3
@@ -72,19 +73,18 @@ func (c *ClientV3) AutoVerifySign(autoRefresh ...bool) (err error) {
72
73
if err != nil {
73
74
return err
74
75
}
75
- if len (c .SnCertMap ) <= 0 {
76
- c .SnCertMap = make (map [string ]* rsa.PublicKey )
77
- }
78
76
for sn , cert := range certMap {
79
77
// decode cert
80
78
pubKey , err := xpem .DecodePublicKey ([]byte (cert ))
81
79
if err != nil {
82
80
return err
83
81
}
84
- c .SnCertMap [sn ] = pubKey
82
+ c .SnCertMap .Store (sn , pubKey )
83
+ if sn == wxSerialNo {
84
+ c .wxPublicKey = pubKey
85
+ }
85
86
}
86
87
c .WxSerialNo = wxSerialNo
87
- c .wxPublicKey = c .SnCertMap [wxSerialNo ]
88
88
if len (autoRefresh ) == 1 && ! autoRefresh [0 ] {
89
89
return nil
90
90
}
@@ -103,10 +103,7 @@ func (c *ClientV3) AutoVerifySignByCert(wxPublicKeyContent []byte, wxPublicKeyID
103
103
if pubKey == nil {
104
104
return errors .New ("xpem.DecodePublicKey() failed, pubKey is nil" )
105
105
}
106
- if len (c .SnCertMap ) <= 0 {
107
- c .SnCertMap = make (map [string ]* rsa.PublicKey )
108
- }
109
- c .SnCertMap [wxPublicKeyID ] = pubKey
106
+ c .SnCertMap .Store (wxPublicKeyID , pubKey )
110
107
c .wxPublicKey = pubKey
111
108
c .WxSerialNo = wxPublicKeyID
112
109
c .autoSign = true
0 commit comments