feat(tenpayv3): 重命名部分参数名

This commit is contained in:
Fu Diwei
2022-01-21 14:41:40 +08:00
parent 215aea8fb8
commit 25bffda684
15 changed files with 93 additions and 56 deletions

View File

@@ -60,11 +60,11 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (callbackSignature == null) throw new ArgumentNullException(nameof(callbackSignature));
if (callbackSerialNumber == null) throw new ArgumentNullException(nameof(callbackSerialNumber));
if (client.CertificateManager != null)
if (client.PlatformCertificateManager != null)
{
try
{
var cert = client.CertificateManager.GetEntry(callbackSerialNumber);
var cert = client.PlatformCertificateManager.GetEntry(callbackSerialNumber);
if (!cert.HasValue)
{
error = new Exceptions.WechatTenpayEventVerificationException("Verify signature of event failed, because there is no platform certificate matched the serial number.");

View File

@@ -36,7 +36,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
string nonce = Guid.NewGuid().ToString("N");
string package = $"prepay_id={prepayId}";
string sign = Utilities.RSAUtility.SignWithSHA256(
privateKey: client.Credentials.MerchantCertPrivateKey,
privateKey: client.Credentials.MerchantCertificatePrivateKey,
plainText: $"{appId}\n{timestamp}\n{nonce}\n{package}\n"
);
@@ -91,7 +91,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
string timestamp = DateTimeOffset.Now.ToLocalTime().ToUnixTimeSeconds().ToString();
string nonce = Guid.NewGuid().ToString("N");
string sign = Utilities.RSAUtility.SignWithSHA256(
privateKey: client.Credentials.MerchantCertPrivateKey,
privateKey: client.Credentials.MerchantCertificatePrivateKey,
plainText: $"{appId}\n{timestamp}\n{nonce}\n{prepayId}\n"
);

View File

@@ -35,15 +35,15 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (Constants.EncryptionAlgorithms.RSA_2048_PKCS8_ECB.Equals(attr.Algorithm))
{
if (client.CertificateManager == null)
if (client.PlatformCertificateManager == null)
throw new Exceptions.WechatTenpayRequestEncryptionException("Encrypt request failed, because there is no platform certificate in the manager.");
string certificate;
if (!string.IsNullOrEmpty(request.WechatpayCertSerialNumber))
if (!string.IsNullOrEmpty(request.WechatpayCertificateSerialNumber))
{
// 如果已在请求中指定特定的平台证书序列号,直接从管理器中取值
var cert = client.CertificateManager.GetEntry(request.WechatpayCertSerialNumber!);
var cert = client.PlatformCertificateManager.GetEntry(request.WechatpayCertificateSerialNumber!);
if (!cert.HasValue)
{
throw new Exceptions.WechatTenpayEventVerificationException("Encrypt request failed, because there is no platform certificate matched the serial number.");
@@ -54,7 +54,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
else
{
// 如果未在请求中指定特定的平台证书序列号,从管理器中取过期时间最远的
var certs = client.CertificateManager.AllEntries().OrderByDescending(e => e.ExpireTime);
var certs = client.PlatformCertificateManager.AllEntries().OrderByDescending(e => e.ExpireTime);
if (!certs.Any())
{
throw new Exceptions.WechatTenpayEventVerificationException("Encrypt request failed, because there is no platform certificate in the manager.");
@@ -62,7 +62,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
var cert = certs.First();
certificate = cert.Certificate;
request.WechatpayCertSerialNumber = cert.SerialNumber;
request.WechatpayCertificateSerialNumber = cert.SerialNumber;
}
string newValue = Utilities.RSAUtility.EncryptWithECBByCertificate(

View File

@@ -36,7 +36,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
{
if (Constants.EncryptionAlgorithms.AEAD_AES_256_GCM.Equals(certificateModel.EncryptCertificate?.Algorithm))
{
if (string.IsNullOrEmpty(client.Credentials.MerchantCertPrivateKey))
if (string.IsNullOrEmpty(client.Credentials.MerchantCertificatePrivateKey))
throw new Exceptions.WechatTenpayResponseDecryptionException("Decrypt response failed, because there is no merchant private key.");
certificateModel.EncryptCertificate.CipherText = Utilities.AESUtility.DecryptWithGCM(
@@ -68,7 +68,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (Constants.EncryptionAlgorithms.RSA_2048_PKCS8_ECB.Equals(attr.Algorithm))
{
string newValue = Utilities.RSAUtility.DecryptWithECB(
privateKey: client.Credentials.MerchantCertPrivateKey,
privateKey: client.Credentials.MerchantCertificatePrivateKey,
cipherText: oldValue
);
return (true, newValue);

View File

@@ -40,11 +40,11 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (client == null) throw new ArgumentNullException(nameof(client));
if (response == null) throw new ArgumentNullException(nameof(response));
if (client.CertificateManager != null)
if (client.PlatformCertificateManager != null)
{
try
{
var cert = client.CertificateManager.GetEntry(response.WechatpayCertSerialNumber)!;
var cert = client.PlatformCertificateManager.GetEntry(response.WechatpayCertificateSerialNumber)!;
if (!cert.HasValue)
{
error = new Exceptions.WechatTenpayResponseVerificationException("Verify signature of response failed, because there is no platform certificate matched the serial number.");