@@ -25,13 +25,11 @@ def __init__(self, mchid, cert_serial_no, private_key, apiv3_key, cert_dir=None,
25
25
self ._logger = logger
26
26
self ._timeout = timeout
27
27
if public_key :
28
- self ._pubkey_mode = True
29
28
self ._public_key = load_public_key (public_key )
30
29
if not public_key_id :
31
30
raise Exception ('public_key_serial_no is not assigned.' )
32
31
self ._public_key_id = public_key_id
33
32
else :
34
- self ._pubkey_mode = False
35
33
self ._init_certificates ()
36
34
37
35
def _update_certificates (self ):
@@ -104,9 +102,7 @@ def _verify_signature(self, headers, body):
104
102
signature_type = headers .get (signature_type_mark )
105
103
if signature_type != 'WECHATPAY2-SHA256-RSA2048' :
106
104
raise Exception ('wechatpayv3 does not support this algorithm: ' + signature_type )
107
- if self ._pubkey_mode :
108
- if serial_no != self ._public_key_id :
109
- return False
105
+ if serial_no == self ._public_key_id :
110
106
public_key = self ._public_key
111
107
else :
112
108
cert_found = False
@@ -137,7 +133,7 @@ def request(self, path, method=RequestType.GET, data=None, skip_verify=False, si
137
133
headers .update ({'Accept' : 'application/json' })
138
134
headers .update ({'User-Agent' : 'wechatpay v3 api python sdk(https://github.com/minibear2021/wechatpayv3)' })
139
135
if cipher_data :
140
- wechatpay_serial = self ._public_key_id if self ._pubkey_mode else hex (self ._last_certificate ().serial_number )[2 :].upper ()
136
+ wechatpay_serial = self ._public_key_id if self ._public_key_id else hex (self ._last_certificate ().serial_number )[2 :].upper ()
141
137
headers .update ({'Wechatpay-Serial' : wechatpay_serial })
142
138
authorization = build_authorization (
143
139
path ,
@@ -261,7 +257,7 @@ def decrypt(self, ciphtext):
261
257
return rsa_decrypt (ciphertext = ciphtext , private_key = self ._private_key )
262
258
263
259
def encrypt (self , text ):
264
- if self ._pubkey_mode :
260
+ if self ._public_key_id :
265
261
public_key = self ._public_key
266
262
else :
267
263
public_key = self ._last_certificate ().public_key ()
0 commit comments