Skip to content

Commit 3349384

Browse files
committed
兼容平台证书向公钥模式过渡
1 parent 2013b5a commit 3349384

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

docs/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [1.3.4] - 2024-11-05
4+
5+
### Added
6+
7+
- 兼容平台证书向公钥模式过渡
8+
39
## [1.3.3] - 2024-10-23
410

511
### Added

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="wechatpayv3",
9-
version="1.3.3",
9+
version="1.3.4",
1010
author="minibear",
1111
description="微信支付 API v3 Python SDK(python sdk for wechatpay v3)",
1212
long_description=long_description,

wechatpayv3/core.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ def __init__(self, mchid, cert_serial_no, private_key, apiv3_key, cert_dir=None,
2525
self._logger = logger
2626
self._timeout = timeout
2727
if public_key:
28-
self._pubkey_mode = True
2928
self._public_key = load_public_key(public_key)
3029
if not public_key_id:
3130
raise Exception('public_key_serial_no is not assigned.')
3231
self._public_key_id = public_key_id
3332
else:
34-
self._pubkey_mode = False
3533
self._init_certificates()
3634

3735
def _update_certificates(self):
@@ -104,9 +102,7 @@ def _verify_signature(self, headers, body):
104102
signature_type = headers.get(signature_type_mark)
105103
if signature_type != 'WECHATPAY2-SHA256-RSA2048':
106104
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:
110106
public_key = self._public_key
111107
else:
112108
cert_found = False
@@ -137,7 +133,7 @@ def request(self, path, method=RequestType.GET, data=None, skip_verify=False, si
137133
headers.update({'Accept': 'application/json'})
138134
headers.update({'User-Agent': 'wechatpay v3 api python sdk(https://github.com/minibear2021/wechatpayv3)'})
139135
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()
141137
headers.update({'Wechatpay-Serial': wechatpay_serial})
142138
authorization = build_authorization(
143139
path,
@@ -261,7 +257,7 @@ def decrypt(self, ciphtext):
261257
return rsa_decrypt(ciphertext=ciphtext, private_key=self._private_key)
262258

263259
def encrypt(self, text):
264-
if self._pubkey_mode:
260+
if self._public_key_id:
265261
public_key = self._public_key
266262
else:
267263
public_key = self._last_certificate().public_key()

0 commit comments

Comments
 (0)