feat(tenpayv3): 独立化境外支付 API

This commit is contained in:
Fu Diwei
2024-05-06 20:50:58 +08:00
parent 2e19fc8aa1
commit 9b18df8f2e
850 changed files with 2016 additions and 1088 deletions

View File

@@ -399,62 +399,6 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
}
}
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /customs/verify-certificate")]
public async Task TestEncryptRequestSensitiveProperty_VerifyHKCustomsCertificateRequest()
{
static Models.VerifyHKCustomsCertificateRequest GenerateMockRequestModel()
{
return new Models.VerifyHKCustomsCertificateRequest()
{
CertificateId = MOCK_PLAIN_STR,
CertificateName = MOCK_PLAIN_STR
};
}
static void AssertMockRequestModel(Models.VerifyHKCustomsCertificateRequest request, Func<string, string> decryptor)
{
Assert.NotEqual(MOCK_PLAIN_STR, request.CertificateId!);
Assert.NotEqual(MOCK_PLAIN_STR, request.CertificateName!);
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.CertificateId!));
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.CertificateName!));
Assert.Equal(MOCK_CERT_SN, request.WechatpayCertificateSerialNumber!, ignoreCase: true);
}
if (!string.IsNullOrEmpty(TestConfigs.WechatMerchantRSACertificatePrivateKey))
{
using (var client = CreateMockClientUseRSA(autoEncrypt: false))
{
var request = GenerateMockRequestModel();
client.EncryptRequestSensitiveProperty(request);
AssertMockRequestModel(request, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, (EncodedString)cipher, Utilities.RSAUtility.PADDING_MODE_PKCS1)!);
}
using (var client = CreateMockClientUseRSA(autoEncrypt: true))
{
var request = GenerateMockRequestModel();
await client.ExecuteVerifyHKCustomsCertificateAsync(request);
AssertMockRequestModel(request, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, (EncodedString)cipher, Utilities.RSAUtility.PADDING_MODE_PKCS1)!);
}
}
if (!string.IsNullOrEmpty(TestConfigs.WechatMerchantSM2CertificatePrivateKey))
{
using (var client = CreateMockClientUseSM2(autoEncrypt: false))
{
var request = GenerateMockRequestModel();
client.EncryptRequestSensitiveProperty(request);
AssertMockRequestModel(request, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
}
using (var client = CreateMockClientUseSM2(autoEncrypt: true))
{
var request = GenerateMockRequestModel();
await client.ExecuteVerifyHKCustomsCertificateAsync(request);
AssertMockRequestModel(request, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
}
}
}
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /ecommerce/applyments")]
public async Task TestEncryptRequestSensitiveProperty_CreateEcommerceApplymentRequest()
{
@@ -985,68 +929,6 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
}
}
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /merchants")]
public async Task TestEncryptRequestSensitiveProperty_AddHKSubMerchantRequest()
{
static Models.AddHKSubMerchantRequest GenerateMockRequestModel()
{
return new Models.AddHKSubMerchantRequest()
{
Contact = new Models.AddHKSubMerchantRequest.Types.Contact()
{
ContactName = MOCK_PLAIN_STR,
MobileNumber = MOCK_PLAIN_STR,
Email = MOCK_PLAIN_STR
}
};
}
static void AssertMockRequestModel(Models.AddHKSubMerchantRequest request, Func<string, string> decryptor)
{
Assert.NotEqual(MOCK_PLAIN_STR, request.Contact!.ContactName!);
Assert.NotEqual(MOCK_PLAIN_STR, request.Contact!.MobileNumber!);
Assert.NotEqual(MOCK_PLAIN_STR, request.Contact!.Email!);
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.Contact!.ContactName!));
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.Contact!.MobileNumber!));
Assert.Equal(MOCK_PLAIN_STR, decryptor.Invoke(request.Contact!.Email!));
Assert.Equal(MOCK_CERT_SN, request.WechatpayCertificateSerialNumber!, ignoreCase: true);
}
if (!string.IsNullOrEmpty(TestConfigs.WechatMerchantRSACertificatePrivateKey))
{
using (var client = CreateMockClientUseRSA(autoEncrypt: false))
{
var request = GenerateMockRequestModel();
client.EncryptRequestSensitiveProperty(request);
AssertMockRequestModel(request, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, (EncodedString)cipher, Utilities.RSAUtility.PADDING_MODE_PKCS1)!);
}
using (var client = CreateMockClientUseRSA(autoEncrypt: true))
{
var request = GenerateMockRequestModel();
await client.ExecuteAddHKSubMerchantAsync(request);
AssertMockRequestModel(request, (cipher) => Utilities.RSAUtility.DecryptWithECB(RSA_PEM_PRIVATE_KEY, (EncodedString)cipher, Utilities.RSAUtility.PADDING_MODE_PKCS1)!);
}
}
if (!string.IsNullOrEmpty(TestConfigs.WechatMerchantSM2CertificatePrivateKey))
{
using (var client = CreateMockClientUseSM2(autoEncrypt: false))
{
var request = GenerateMockRequestModel();
client.EncryptRequestSensitiveProperty(request);
AssertMockRequestModel(request, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
}
using (var client = CreateMockClientUseSM2(autoEncrypt: true))
{
var request = GenerateMockRequestModel();
await client.ExecuteAddHKSubMerchantAsync(request);
AssertMockRequestModel(request, (cipher) => Utilities.SM2Utility.Decrypt(SM2_PEM_PRIVATE_KEY, (EncodedString)cipher)!);
}
}
}
[Fact(DisplayName = "测试用例:加密请求中的敏感数据([POST] /new-tax-control-fapiao/fapiao-applications")]
public async Task TestEncryptRequestSensitiveProperty_CreateNewTaxControlFapiaoApplicationRequest()
{