Example #1
0
        /// <summary>
        /// 用户名或者密码错误会直接抛错
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="type"></param>
        /// <param name="accountName"></param>
        /// <returns></returns>
        public async Task <UserAccount> GenerateAccountAsync(string username, string password, CAType type, string accountName)
        {
            var accountType = "0";

            if (type == CAType.Peer)
            {
                accountType = "0";
            }
            else if (type == CAType.Admin)
            {
                accountType = "1";
            }
            else if (type == CAType.User)
            {
                accountType = "2";
            }
            else if (type == CAType.Reader)
            {
                accountType = "3";
            }

            var request = new QMBlockClientSDK.Client.AccountRequest()
            {
                Username    = username,
                Password    = password,
                AccountType = accountType,
                AccountName = accountName
            };
            var rs = await AuthClient.GenerateAccountAsync(request);

            if (rs.Status)
            {
                return(new UserAccount
                {
                    PrivateKey = rs.PravateKey,
                    Certificate = Newtonsoft.Json.JsonConvert.DeserializeObject <Certificate>(rs.Certificate)
                });
            }
            else
            {
                //如果发生错误 这里的privateKey是错误消息
                throw new Exception(rs.PravateKey);
            }
        }