TrustyPay.Crypto.Banks.CMB 0.0.8

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

// Install TrustyPay.Crypto.Banks.CMB as a Cake Tool
#tool nuget:?package=TrustyPay.Crypto.Banks.CMB&version=0.0.8

招行免前置机接口客户端类

  1. 使用KeyGenerator类生成招行需要的密钥信息:

    using TrustyPay.Crypto.Banks.CMB;
    
    var generator = new KeyGenerator("<银行公钥>");
    Console.WriteLine("招行密钥设置信息 => 用户公钥:{0}, 加密后对称密钥:{1} ",
         generator.SM2PublicKey, generator.SM4KeyEncrypted);
    Console.WriteLine("招行接口调用信息 => 用户私钥:{0}, 对称密钥:{1} ",
         generator.SM2PrivateKey, generator.SM4Key);
    
  2. 妥善保管好生成的银行公钥/用户公钥/用户私钥/用户对称密钥;

  3. 将上述的用户公钥和加密版对称密钥保存到招商银行银企直联->设置与授权->密钥设置;

  4. CmbHttpClient类的使用示例:

        using TrustyPay.Crypto;
        using TrustyPay.Crypto.Http;
        using TrustyPay.Crypto.Banks.CMB;
    
        var config = new Config(
            "<用户私钥>",
            "<银行公钥>",
            "<用户对称密钥>",
            "用户编号" // 用户编号来自招行企业网银后台设置的用户[U盾编号],此用户需要有相应的接口调用权限。
        );
    
        var client = new CmbHttpClient(
            "https://招商银行接口生产地址/测试接口地址",
            config);
    
        SubaccountBalanceResult result;
        try
        {
            result = await client.PostAsync<SubaccountBalanceResult>(
                string.Empty,
                new SubaccountBalanceQuery("用户招行账号", "记账子单元编号", "续传字段"),
                System.Threading.CancellationToken.None);
        }
        catch (InvalidSignatureException se)
        {
            Console.WriteLine("signature is incorrect!!!");
            return;
        }
        catch (HttpResponseException re)
        {
            Console.WriteLine(re.Message);
            return;
        }
    
  5. SubaccountBalanceQuery类定义:

        using Newtonsoft.Json;
        using TrustyPay.Crypto.Banks.CMB;
    
        public class SubaccountBalanceQuery : IFunctionCode
        {
            [JsonProperty("ntdmabalx")]
            public AccountInfo[] Account { get; set; }
    
            public string FuncCode => "NTDMABAL";
    
            public SubaccountBalanceQuery(
                string account,
                string subaccount,
                string nextLink)
            {
                Account = new[]{
                    new AccountInfo
                    {
                        Account = account,
                        Subaccount = subaccount,
                        NextLink = nextLink
                    }
                };
            }
    
            public class AccountInfo
            {
                [JsonProperty("accnbr")]
                public string Account { get; set; }
    
                [JsonProperty("dmanbr")]
                public string Subaccount { get; set; }
    
                [JsonProperty("ctnkey")]
                public string NextLink { get; set; }
            }
        }
    
  6. SubaccountBalanceResult类定义:

        using Newtonsoft.Json;
    
        public class SubaccountBalanceResult
        {
            [JsonProperty("ntdmabalx")]
            public AccountInfo[] Account { get; set; }
    
            [JsonProperty("ntdmabalz")]
            public BalanceItem[] Balances { get; set; }
    
            public class AccountInfo
            {
                [JsonProperty("accnbr")]
                public string Account { get; set; }
                [JsonProperty("dmanbr")]
                public string Subaccount { get; set; }
                [JsonProperty("rsv50z")]
                public string NextLink { get; set; }
            }
    
            public class BalanceItem
            {
                [JsonProperty("accnbr")]
                public string Account { get; set; }
    
                [JsonProperty("dmanbr")]
                public string Subaccount { get; set; }
    
                [JsonProperty("dmanam")]
                public string SubaccountName { get; set; }
    
                [JsonProperty("dmaccy")]
                public string Currency { get; set; }
    
                [JsonProperty("eftdat")]
                public string EffectDate { get; set; }
    
                [JsonProperty("actbal")]
                public decimal Balance { get; set; }
    
                [JsonProperty("stscod")]
                public string Status { get; set; }
    
                [JsonProperty("mthaub")]
                public string Points { get; set; }
            }
        }
    
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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 netcoreapp3.1 is compatible. 
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
0.0.8 501 7/21/2022
0.0.7 389 7/20/2022
0.0.6 379 7/15/2022
0.0.4 414 6/25/2022
0.0.3 386 6/10/2022
0.0.2 378 6/6/2022
0.0.1 384 6/1/2022