Skip to content

Commit

Permalink
兼容高版本cryptography库
Browse files Browse the repository at this point in the history
  • Loading branch information
minibear2021 committed Feb 5, 2024
1 parent 9504197 commit 90b2c99
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.2.44] - 2024-02-05

### Fixed

- 兼容高版本cryptography库

## [1.2.43] - 2023-12-13

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="wechatpayv3",
version="1.2.43",
version="1.2.44",
author="minibear",
description="微信支付 API v3 Python SDK(python sdk for wechatpay v3)",
long_description=long_description,
Expand Down
13 changes: 9 additions & 4 deletions wechatpayv3/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .type import RequestType, SignType
from .utils import (aes_decrypt, build_authorization, hmac_sign,
load_certificate, load_private_key, rsa_decrypt,
rsa_encrypt, rsa_sign, rsa_verify)
rsa_encrypt, rsa_sign, rsa_verify, cryptography_version)


class Core():
Expand Down Expand Up @@ -199,9 +199,14 @@ def _init_certificates(self):
continue
with open(self._cert_dir + file_name, encoding="utf-8") as f:
certificate = load_certificate(f.read())
now = datetime.now(timezone.utc)
if certificate and now >= certificate.not_valid_before_utc and now <= certificate.not_valid_after_utc:
self._certificates.append(certificate)
if (int(cryptography_version.split(".")[0]) < 42):
now = datetime.utcnow()
if certificate and now >= certificate.not_valid_before and now <= certificate.not_valid_after:
self._certificates.append(certificate)
else:
now = datetime.now(timezone.utc)
if certificate and now >= certificate.not_valid_before_utc and now <= certificate.not_valid_after_utc:
self._certificates.append(certificate)
if not self._certificates:
self._update_certificates()
if not self._certificates:
Expand Down
1 change: 1 addition & 0 deletions wechatpayv3/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from cryptography.hazmat.primitives.hmac import HMAC
from cryptography.hazmat.primitives.serialization import load_pem_private_key
from cryptography.x509 import load_pem_x509_certificate
from cryptography import __version__ as cryptography_version


def build_authorization(path,
Expand Down

0 comments on commit 90b2c99

Please sign in to comment.