mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2026-02-17 05:48:09 +08:00
refactor: 优化代码
This commit is contained in:
@@ -17,7 +17,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
|
||||
CertificateEntry? entry = client.PlatformCertificateManager.GetEntry(strSerialNumber);
|
||||
if (!entry.HasValue)
|
||||
{
|
||||
return ErroredResult.Fail(new Exception($"The platform certificate manager does not contain a certificate with serial number \"{strSerialNumber}\"."));
|
||||
return ErroredResult.Fail(new Exception($"The platform certificate manager does not contain a certificate matched the serial number \"{strSerialNumber}\"."));
|
||||
}
|
||||
|
||||
return GenerateSignatureResultByCertificate(
|
||||
@@ -41,7 +41,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
|
||||
CertificateEntry? entry = await ((ICertificateManagerAsync)client.PlatformCertificateManager).GetEntryAsync(strSerialNumber, cancellationToken).ConfigureAwait(false);
|
||||
if (!entry.HasValue)
|
||||
{
|
||||
return ErroredResult.Fail(new Exception($"The platform certificate manager does not contain a certificate with serial number \"{strSerialNumber}\"."));
|
||||
return ErroredResult.Fail(new Exception($"The platform certificate manager does not contain a certificate matched the serial number \"{strSerialNumber}\"."));
|
||||
}
|
||||
|
||||
return GenerateSignatureResultByCertificate(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net462; netstandard2.0; net6.0</TargetFrameworks>
|
||||
<TargetFrameworks>net462; netstandard2.0; net6.0; net8.0</TargetFrameworks>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<NullableReferenceTypes>true</NullableReferenceTypes>
|
||||
|
||||
@@ -55,6 +55,8 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings
|
||||
[System.Text.Json.Serialization.JsonConstructor]
|
||||
public CertificateEntry(string algorithmType, string serialNumber, string certificate, DateTimeOffset effectiveTime, DateTimeOffset expireTime)
|
||||
{
|
||||
certificate = certificate?.Trim()!;
|
||||
|
||||
if (string.IsNullOrEmpty(algorithmType))
|
||||
throw new ArgumentException("The value of `algorithmType` can not be empty.", nameof(algorithmType));
|
||||
if (string.IsNullOrEmpty(certificate))
|
||||
@@ -63,8 +65,8 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings
|
||||
throw new ArgumentException("The value of `serialNumber` can not be empty.", nameof(serialNumber));
|
||||
if (!ALGORITHM_TYPE_RSA.Equals(algorithmType) && !ALGORITHM_TYPE_SM2.Equals(algorithmType))
|
||||
throw new ArgumentException("The value of `algorithmType` an invalid value.", nameof(algorithmType));
|
||||
if (!certificate.Trim().StartsWith("-----BEGIN CERTIFICATE-----") || !certificate.Trim().EndsWith("-----END CERTIFICATE-----"))
|
||||
throw new ArgumentException("The value of `certificate` is an invalid certificate file content.", nameof(certificate));
|
||||
if (!(certificate.StartsWith("-----BEGIN CERTIFICATE-----") && certificate.EndsWith("-----END CERTIFICATE-----")))
|
||||
throw new ArgumentException("The value of `certificate` is an invalid certificate file content. Maybe you forgot to decrypt?", nameof(certificate));
|
||||
|
||||
AlgorithmType = algorithmType;
|
||||
SerialNumber = serialNumber.ToUpper();
|
||||
@@ -80,12 +82,14 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings
|
||||
/// <param name="certificate"></param>
|
||||
public CertificateEntry(string algorithmType, string certificate)
|
||||
{
|
||||
certificate = certificate?.Trim()!;
|
||||
|
||||
if (string.IsNullOrEmpty(algorithmType))
|
||||
throw new ArgumentException("The value of `algorithmType` can not be empty.", nameof(algorithmType));
|
||||
if (string.IsNullOrEmpty(certificate))
|
||||
throw new ArgumentException("The value of `certificate` can not be empty.", nameof(certificate));
|
||||
if (!certificate.Trim().StartsWith("-----BEGIN CERTIFICATE-----") || !certificate.Trim().EndsWith("-----END CERTIFICATE-----"))
|
||||
throw new ArgumentException("The value of `certificate` is an invalid certificate file content.", nameof(certificate));
|
||||
if (!(certificate.StartsWith("-----BEGIN CERTIFICATE-----") && certificate.EndsWith("-----END CERTIFICATE-----")))
|
||||
throw new ArgumentException("The value of `certificate` is an invalid certificate file content. Maybe you forgot to decrypt?", nameof(certificate));
|
||||
|
||||
AlgorithmType = algorithmType;
|
||||
Certificate = certificate;
|
||||
|
||||
@@ -45,8 +45,12 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.Utilities
|
||||
{
|
||||
if (!string.Equals(paddingMode, PADDING_MODE_NOPADDING, StringComparison.OrdinalIgnoreCase))
|
||||
throw new NotSupportedException();
|
||||
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
using (AesGcm aes = new AesGcm(keyBytes, TAG_LENGTH_BYTE))
|
||||
#else
|
||||
using (AesGcm aes = new AesGcm(keyBytes))
|
||||
#endif
|
||||
{
|
||||
byte[] cipherWithoutTagBytes = new byte[cipherBytes.Length - TAG_LENGTH_BYTE];
|
||||
byte[] tagBytes = new byte[TAG_LENGTH_BYTE];
|
||||
|
||||
Reference in New Issue
Block a user