Skip to content

Commit 90b2c99

Browse files
committed
兼容高版本cryptography库
1 parent 9504197 commit 90b2c99

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
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.2.44] - 2024-02-05
4+
5+
### Fixed
6+
7+
- 兼容高版本cryptography库
8+
39
## [1.2.43] - 2023-12-13
410

511
### Fixed

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.2.43",
9+
version="1.2.44",
1010
author="minibear",
1111
description="微信支付 API v3 Python SDK(python sdk for wechatpay v3)",
1212
long_description=long_description,

wechatpayv3/core.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .type import RequestType, SignType
1010
from .utils import (aes_decrypt, build_authorization, hmac_sign,
1111
load_certificate, load_private_key, rsa_decrypt,
12-
rsa_encrypt, rsa_sign, rsa_verify)
12+
rsa_encrypt, rsa_sign, rsa_verify, cryptography_version)
1313

1414

1515
class Core():
@@ -199,9 +199,14 @@ def _init_certificates(self):
199199
continue
200200
with open(self._cert_dir + file_name, encoding="utf-8") as f:
201201
certificate = load_certificate(f.read())
202-
now = datetime.now(timezone.utc)
203-
if certificate and now >= certificate.not_valid_before_utc and now <= certificate.not_valid_after_utc:
204-
self._certificates.append(certificate)
202+
if (int(cryptography_version.split(".")[0]) < 42):
203+
now = datetime.utcnow()
204+
if certificate and now >= certificate.not_valid_before and now <= certificate.not_valid_after:
205+
self._certificates.append(certificate)
206+
else:
207+
now = datetime.now(timezone.utc)
208+
if certificate and now >= certificate.not_valid_before_utc and now <= certificate.not_valid_after_utc:
209+
self._certificates.append(certificate)
205210
if not self._certificates:
206211
self._update_certificates()
207212
if not self._certificates:

wechatpayv3/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from cryptography.hazmat.primitives.hmac import HMAC
1414
from cryptography.hazmat.primitives.serialization import load_pem_private_key
1515
from cryptography.x509 import load_pem_x509_certificate
16+
from cryptography import __version__ as cryptography_version
1617

1718

1819
def build_authorization(path,

0 commit comments

Comments
 (0)