ZY.HTTP.Core 1.0.2.10

dotnet add package ZY.HTTP.Core --version 1.0.2.10
NuGet\Install-Package ZY.HTTP.Core -Version 1.0.2.10
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.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ZY.HTTP.Core --version 1.0.2.10
#r "nuget: ZY.HTTP.Core, 1.0.2.10"
#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.
// Install ZY.HTTP.Core as a Cake Addin
#addin nuget:?package=ZY.HTTP.Core&version=1.0.2.10

// Install ZY.HTTP.Core as a Cake Tool
#tool nuget:?package=ZY.HTTP.Core&version=1.0.2.10

签名验证

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();
            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. 
.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.10 141 2/19/2024
1.0.2.9 132 12/18/2023
1.0.2.8 77 12/18/2023
1.0.2.7 93 12/18/2023
1.0.2.6 317 4/20/2023
1.0.2.5 409 9/21/2022
1.0.2.4 376 9/21/2022
1.0.2.3 402 7/25/2022
1.0.2.2 453 4/14/2022
1.0.2.1 540 11/4/2021
1.0.1.1 419 8/17/2021
1.0.0.9 395 12/17/2020
1.0.0.8 388 12/11/2020
1.0.0.7 473 11/28/2020
1.0.0.6 507 11/28/2020
1.0.0.5 403 11/27/2020
1.0.0.4 406 11/27/2020
1.0.0.3 397 11/27/2020
1.0.0.2 418 11/27/2020
1.0.0.1 366 11/27/2020