feat(tenpaybusiness): 导入项目

This commit is contained in:
RHQYZ
2022-05-09 19:28:47 +08:00
committed by GitHub
parent 26b9c17a7d
commit a0a90f4851
102 changed files with 4606 additions and 95 deletions

View File

@@ -0,0 +1 @@
appsettings.local.json

View File

@@ -0,0 +1,18 @@
{
"api_version": "",
"event_id": "",
"event_type": "pay.succeeded",
"live_mode": false,
"pending_webhooks": 0,
"create_time": "2020-01-01T01:02:03+08:00",
"event_content": {
"payment_id": "",
"purchaser_id": "",
"out_payment_id": "",
"bargainor_ent_id": "",
"amount": 0,
"status": "",
"pay_succ_time": "2020-01-01T01:02:03+08:00",
"failed_reason": ""
}
}

View File

@@ -0,0 +1,25 @@
{
"api_version": "",
"event_id": "",
"event_type": "product.application.finish",
"live_mode": false,
"pending_webhooks": 0,
"create_time": "2020-01-01T01:02:03+08:00",
"event_content": {
"request_no": "",
"out_request_no": "",
"ent_id": "",
"status": "",
"product_details": [
{
"product_name": "",
"status": "",
"accounts": [
{
"ent_acct_id": ""
}
]
}
]
}
}

View File

@@ -0,0 +1,5 @@
{
"download_url": "",
"expire_time": "2021-06-08T10:34:56+08:00",
"bill_status": ""
}

View File

@@ -0,0 +1,6 @@
{
"payment_id": "",
"out_payment_id": "",
"status": "",
"close_time": "2021-06-08T10:34:56+08:00"
}

View File

@@ -0,0 +1,33 @@
{
"purchaser_type": "",
"out_payment_id": "",
"amount": 0,
"currency": "",
"expire_time": "2021-06-08T10:34:56+08:00",
"payee": {
"ent_id": "",
"ent_name": "",
"ent_acct_id": "",
"bank_account_number_last4": ""
},
"memo": "",
"goods": [
{
"good_name": "",
"good_number": "0",
"good_amount": "0"
}
],
"attachment": "",
"risk_control": {
"device_id": "",
"payer_client_ip": "",
"payer_ua": "",
"create_time": "2021-06-08T10:34:56+08:00",
"pick_type": "",
"pick_description": ""
},
"notify_url": {
"server_notify_url": ""
}
}

View File

@@ -0,0 +1,14 @@
{
"payment_id": "",
"out_payment_id": "",
"amount": 0,
"currency": "",
"payee": {
"ent_id": "",
"ent_name": "",
"ent_acct_id": "",
"bank_account_number_last4": ""
},
"pay_status": "",
"memo": ""
}

View File

@@ -0,0 +1,20 @@
{
"payment_id": "",
"out_payment_id": "",
"user_openid": "",
"amount": 0,
"currency": "",
"payee": {
"ent_id": "",
"ent_name": "",
"ent_acct_id": "",
"bank_account_number_last4": ""
},
"pay_status": "",
"memo": "",
"failed_reason": {
"failed_type": "",
"failed_detail": ""
},
"attachment": ""
}

View File

@@ -0,0 +1,6 @@
{
"pc_web": {
"url": "",
"expire_time": "2020-01-01T01:02:03+08:00"
}
}

View File

@@ -0,0 +1,42 @@
{
"out_request_no": "",
"business_license": {
"business_register_type": "",
"unified_social_credit_code": "",
"merchant_name": "",
"merchant_short_name": "",
"legal_person_name": "",
"validity_period": [ "2024-01-01", "长期" ],
"photocopy_file_id": ""
},
"legal_person_id_card": {
"name": "",
"number": "",
"validity_period": [ "2024-01-01", "长期" ],
"front_photocopy_file_id": "",
"back_photocopy_file_id": ""
},
"contact_info": {
"mobile_number": ""
},
"payee_accounts": [
{
"account_type": "",
"bank_account_name": "",
"bank_account_number": "",
"bank_name": "",
"bank_branch_id": "",
"bank_branch_name": ""
}
],
"products": [
{
"product_name": ""
}
],
"notify_url": {
"server_notify_url": "",
"web_success_url": "",
"web_refresh_url": ""
}
}

View File

@@ -0,0 +1,17 @@
{
"request_no": "",
"out_request_no": "",
"ent_id": "",
"status": "",
"product_details": [
{
"product_name": "",
"status": "",
"accounts": [
{
"ent_acct_id": ""
}
]
}
]
}

View File

@@ -0,0 +1,19 @@
{
"pc_web": {
"url": "",
"expire_time": "2020-01-01T01:02:03+08:00"
},
"pc_plugin": {
"key": "",
"expire_time": "2020-01-01T01:02:03+08:00"
},
"wx_qrcode": {
"url": ""
},
"miniprogram": {
"mp_path": "",
"mp_appid": "",
"mp_username": "",
"expire_time": "2020-01-01T01:02:03+08:00"
}
}

View File

@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472; net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<NullableReferenceTypes>true</NullableReferenceTypes>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<None Remove=".gitignore" />
<None Remove="appsettings.local.json" />
<Content Include="appsettings.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
<Content Include="appsettings.*.json" Condition="'$(Configuration)' == 'Debug'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="ModelSamples/**/*.json" />
<Content Include="EventSamples/**/*.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="SKIT.FlurlHttpClient.Tools.CodeAnalyzer" Version="0.1.0-alpha.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SKIT.FlurlHttpClient.Wechat.TenpayBusiness\SKIT.FlurlHttpClient.Wechat.TenpayBusiness.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,26 @@
using SKIT.FlurlHttpClient.Tools.CodeAnalyzer;
using Xunit;
namespace SKIT.FlurlHttpClient.Wechat.TenpayBusiness.UnitTests
{
public class TestCase_CodeReview
{
[Fact(DisplayName = "测试用例:代码质量分析")]
public void TestCodeAnalyzer()
{
Assert.Null(Record.Exception(() =>
{
CodeAnalyzerOptions options = new CodeAnalyzerOptions()
{
AssemblyName = "SKIT.FlurlHttpClient.Wechat.TenpayBusiness",
WorkDirectoryForSourceCode = TestConfigs.WorkDirectoryForSdk,
WorkDirectoryForTestSample = TestConfigs.WorkDirectoryForTest
};
CodeAnalyzer analyzer = new CodeAnalyzer(options);
analyzer.Start();
analyzer.Assert();
analyzer.Flush();
}));
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using Xunit;
namespace SKIT.FlurlHttpClient.Wechat.TenpayBusiness.UnitTests
{
public class TestCase_SM3UtilityTests
{
[Fact(DisplayName = "测试用例:计算 SM3 哈希值")]
public void TestSM3Hash()
{
byte[] msgBytes = Convert.FromBase64String("QXdlc29tZSBTS0lULkZsdXJsSHR0cENsaWVudC5XZWNoYXQuVGVucGF5QnVzaW5lc3Mh");
string expectedHashText = "A7A58FCEDDDEE4BD2E05887E5F4D8B7D662357BE474F3821CA858EE1CFFB4B83";
string actualHashText = BitConverter.ToString(Utilities.SM3Utility.Hash(msgBytes)).Replace("-", "");
Assert.Equal(actualHashText, expectedHashText, ignoreCase: true);
}
}
}

View File

@@ -0,0 +1,33 @@
using Xunit;
namespace SKIT.FlurlHttpClient.Wechat.TenpayBusiness.UnitTests
{
public class TestCase_SM4UtilityTests
{
[Fact(DisplayName = "测试用例SM4 加密")]
public void TestSM4Encrypt()
{
string key = "MDAwMDAwMDAwMDAwMDAwMA==";
string iv = "OGE2YzRkZGQ4YTZjNGRkZA==";
string plainText = "Awesome SKIT.FlurlHttpClient.Wechat.TenpayBusiness!";
string actualCipher = Utilities.SM4Utility.EncryptWithCBC(key: key, iv: iv, plainText: plainText);
string expectedCipher = "Fm3z4Ipjuaj4oQLfxpTrvoZm5JdbjvjrJo3PRhvSsOppk8/PN+izH3Wo9Rz6V85mpq6X1cGul8U7jjaAl1PWpg==";
Assert.Equal(expectedCipher, actualCipher);
}
[Fact(DisplayName = "测试用例SM4 解密")]
public void TestSM4Decrypt()
{
string key = "MDAwMDAwMDAwMDAwMDAwMA==";
string iv = "OGE2YzRkZGQ4YTZjNGRkZA==";
string cipherText = "Fm3z4Ipjuaj4oQLfxpTrvoZm5JdbjvjrJo3PRhvSsOppk8/PN+izH3Wo9Rz6V85mpq6X1cGul8U7jjaAl1PWpg==";
string actualPlain = Utilities.SM4Utility.DecryptWithCBC(key: key, iv: iv, cipherText: cipherText);
string expectedPlain = "Awesome SKIT.FlurlHttpClient.Wechat.TenpayBusiness!";
Assert.Equal(expectedPlain, actualPlain);
}
}
}

View File

@@ -0,0 +1,19 @@
namespace SKIT.FlurlHttpClient.Wechat.TenpayBusiness.UnitTests
{
internal class TestClients
{
static TestClients()
{
Instance = new WechatTenpayBusinessClient(new WechatTenpayBusinessClientOptions()
{
PlatformId = TestConfigs.WechatPlatformId,
PlatformCertificateSerialNumber = TestConfigs.WechatPlatformCertSerialNumber,
PlatformCertificatePrivateKey = TestConfigs.WechatPlatformCertPrivateKey,
TBEPCertificateSerialNumber = TestConfigs.WechatTBEPCertSerialNumber,
TBEPCertificatePublicKey = TestConfigs.WechatTBEPCertPrivateKey
});
}
public static readonly WechatTenpayBusinessClient Instance;
}
}

View File

@@ -0,0 +1,44 @@
using System;
using System.IO;
using System.Text.Json;
namespace SKIT.FlurlHttpClient.Wechat.TenpayBusiness.UnitTests
{
internal class TestConfigs
{
static TestConfigs()
{
// NOTICE: 请在项目根目录下按照 appsettings.json 的格式新建 appsettings.local.json 填入测试参数。
// WARN: 敏感信息请不要提交到 git
try
{
using var stream = File.OpenRead("appsettings.local.json");
using var jdoc = JsonDocument.Parse(stream);
var config = jdoc.RootElement.GetProperty("TestConfig");
WechatPlatformId = config.GetProperty("PlatformId").GetString()!;
WechatPlatformCertSerialNumber = config.GetProperty("PlatformCertSerialNumber").GetString()!;
WechatPlatformCertPrivateKey = config.GetProperty("PlatformCertPrivateKey").GetString()!;
WechatTBEPCertSerialNumber = config.GetProperty("TBEPCertSerialNumber").GetString()!;
WechatTBEPCertPrivateKey = config.GetProperty("TBEPCertPrivateKey").GetString()!;
WorkDirectoryForSdk = jdoc.RootElement.GetProperty("WorkDirectoryForSdk").GetString()!;
WorkDirectoryForTest = jdoc.RootElement.GetProperty("WorkDirectoryForTest").GetString()!;
}
catch (Exception ex)
{
throw new Exception("加载配置文件 appsettings.local.json 失败,请查看 `InnerException` 了解具体失败原因", ex);
}
}
public static readonly string WechatPlatformId;
public static readonly string WechatPlatformCertSerialNumber;
public static readonly string WechatPlatformCertPrivateKey;
public static readonly string WechatTBEPCertSerialNumber;
public static readonly string WechatTBEPCertPrivateKey;
public static readonly string WorkDirectoryForSdk;
public static readonly string WorkDirectoryForTest;
}
}

View File

@@ -0,0 +1,11 @@
{
"TestConfig": {
"PlatformId": "请在此填写用于测试的微信商户号",
"PlatformCertSerialNumber": "请在此填写用于测试的微企付平台 API 证书序列号",
"PlatformCertPrivateKey": "请在此填写用于测试的微企付平台 API 证书私钥(字符串格式)",
"TBEPCertSerialNumber": "请在此填写用于测试的微企付证书序列号",
"TBEPCertPrivateKey": "请在此填写用于测试的微企付证书私钥(字符串格式)"
},
"WorkDirectoryForSdk": "请输入当前 SDK 项目所在的目录完整路径,如 C:\\Project\\src\\SKIT.FlurlHttpClient.Wechat.TenpayBusiness\\",
"WorkDirectoryForTest": "请输入当前测试项目所在的目录完整路径,如 C:\\Project\\test\\SKIT.FlurlHttpClient.Wechat.TenpayBusiness.UnitTests\\"
}