ZY.HTTP.Core 1.0.2.12

dotnet add package ZY.HTTP.Core --version 1.0.2.12
                    
NuGet\Install-Package ZY.HTTP.Core -Version 1.0.2.12
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZY.HTTP.Core" Version="1.0.2.12" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZY.HTTP.Core" Version="1.0.2.12" />
                    
Directory.Packages.props
<PackageReference Include="ZY.HTTP.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZY.HTTP.Core --version 1.0.2.12
                    
#r "nuget: ZY.HTTP.Core, 1.0.2.12"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZY.HTTP.Core@1.0.2.12
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZY.HTTP.Core&version=1.0.2.12
                    
Install as a Cake Addin
#tool nuget:?package=ZY.HTTP.Core&version=1.0.2.12
                    
Install as a Cake Tool

签名验证

nuget引用组件 :ZY.HTTP.Core

SignValidate方式验证

添加Startup

1、在ConfigureServices 添加代码

	 services.AddFramework();
	 //cache缓存
	 services.AddSingleton<IMemoryCache, MemoryCache>();
	 services.AddSingleton<ICacheService, MemoryCacheProvider>(); //内存 缓存
	 //services.AddSingleton<ICacheService, RedisCacheProvider>();  //redis 缓存

2、在Configure添加代码

	 app.UseHTTP();
	 
	 //application
	 app.UseApplication();

添加Application

1、在AppService中添加TokenLoadAppService类

    public class TokenLoadAppService
    {
        private readonly IServiceScopeFactory _serviceProvider; //用IServiceProvider 可能出现被释放无法访问对象情况

        public TokenLoadAppService(IServiceScopeFactory serviceProvider)
        {
            _serviceProvider = serviceProvider; 
        }

        public void Init()
        {
            SignValidateAttribute.OnGetToken += GetToken;
        }
        public Token GetToken(string tenant)
        {
            try
            {
                //根据tenant 获取对应 Key
                //用停车场id 在parking表中 获取 key字段
               using (var scope = _serviceProvider.CreateScope()) //不加域 部分项目 可能报错 Cannot access a disposed context instance. 
                {
                    var service = scope.ServiceProvider.GetService<IRepository>();
                    var park = service.FirstOrDefault<Parking>(s => s.Id == tenant);
                    if (park == null) return null;

                    return new Token
                    {
                        ExpireTime = DateTime.Now.AddDays(1),
                        SignToken = park.Key,
                        TenantId = park.Id
                    };
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("获取停车场信息报错", ex);
                throw ex;
            }
        }
    }

2、在AppService下添加 ApplicationExtensions 类

    public static class ApplicationExtensions
    {
        public static IApplicationBuilder UseApplication(this IApplicationBuilder app)
        {
            app.ApplicationServices.GetService<ITokenLoadAppService>().Init();

            //或者
            SignValidateAttribute.OnGetToken += (s =>
            {
                var sub = app.ApplicationServices.CreateScope().ServiceProvider.GetService<IParkingService>().GetByIdAsync(s);
                return new Token { ExpireTime = DateTime.Now.AddDays(1), TenantId = s, SignToken = sub.Result.Data.Key };
            });
            return app;
        }
    }

调用

    [HttpPost]
    [SignValidate]
    public ApiResult CommitEntryRecord([FromBody] CarRecordDto value)
    {
        //接口处理
    }

FixedSignValidate 方式验证

添加Startup

1、在ConfigureServices 添加代码

	 services.AddFramework();

2、在Configure添加代码

	 app.UseHTTP();

使用

    [HttpPost]
    [FixedSignValidate("Signature", "TokenKey", true)]
    public ApiResult CommitEntryRecord([FromBody] CarRecordDto value)
    {
        //接口处理
    }

说明


//Signature 需要验证sign字段名
//TokenKey 密钥
[FixedSignValidate("Signature", "123456789012431243123")]

//Signature 需要验证sign字段名
//TokenKey 密钥 或配置密钥配置项名称
//true key将作为config配置名称,读取配置,false key直接作为密钥参数
[FixedSignValidate("Signature", "TokenKey", true)]

//多级密钥情况填写 
[FixedSignValidate("Signature", "Token:ArrearsTokenKey", true)]

配置


"TokenKey":  "123456789012431243123"

"Token":{
    "ArrearsTokenKey":  "123456789012431243123"
}

第三方调用

   var raw = KeyValueConverter.ToKeyValuePairString(input);
            var token = new Md5Validator(_option.Key).ComputeHashFromString(raw);
            _logger.LogInformation($"Token:{token},拼接结果:{raw}");
            input.Signature = token;

           return  await _http.PostAsync<ApiResult>("http://opentest.yun-kai.com/", "msparking/recovery/Arrears/Notification", input);

SingVerification 验证

添加Startup

1、在ConfigureServices 添加代码

	 services.AddHTTP();

2、在Configure添加代码

	 app.UseHTTP();

使用

    private readonly SingVerification _sign;

    public HttpTestController(SingVerification sign)
    {
        _sign = sign;
    }

    [HttpPost]
    public async Task<string> Pay()
    {
        var success= _sign.Verification("key密钥"); 
    }

第三方调用

    var raw = KeyValueConverter.ToKeyValuePairString(input);
    var token = new Md5Validator(_option.Key).ComputeHashFromString(raw);
    _logger.LogInformation($"Token:{token},拼接结果:{raw}");
    input.Signature = token;

    return  await _http.PostAsync<ApiResult>("http://opentest.yun-kai.com/", "msparking/recovery/Arrears/Notification", input);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2.12 740 8/1/2024
1.0.2.11 157 8/1/2024
1.0.2.10 311 2/19/2024
1.0.2.9 227 12/18/2023
1.0.2.8 174 12/18/2023
1.0.2.7 173 12/18/2023
1.0.2.6 518 4/20/2023
1.0.2.5 574 9/21/2022
1.0.2.4 549 9/21/2022
1.0.2.3 598 7/25/2022
1.0.2.2 641 4/14/2022
1.0.2.1 747 11/4/2021
1.0.1.1 634 8/17/2021
1.0.0.9 618 12/17/2020
1.0.0.8 594 12/11/2020
1.0.0.7 684 11/28/2020
1.0.0.6 703 11/28/2020
1.0.0.5 621 11/27/2020
1.0.0.4 611 11/27/2020
1.0.0.3 607 11/27/2020
Loading failed