示例#1
0
        /// <summary>
        /// 检测设备是否已创建过客户端,如果不存在,则创建
        /// </summary>
        /// <param name="input">开通客户端输入参数</param>
        /// <param name="npsAppSecret">NpsAppSecret</param>
        /// <returns>返回NpsAppSecret</returns>
        private async Task <NpsAppSecret> CreateNpsClientIfCheckNullAsync(NpsClientOpenInput input, NpsAppSecret npsAppSecret)
        {
            Check.NotNull(npsAppSecret, nameof(npsAppSecret));

            _logger.LogInformation($"检测设备是否已创建过客户端,设备唯一识别编码:{npsAppSecret.DeviceUniqueId}");
            if (npsAppSecret.NpsClient == null)
            {
                //调用远程Api执行添加客户端
                var baseAuthInput = await BeforeRequestNpsApiAsync();

                var remoteApiResult = await _npsApi.AddClientAsync(new ClientAddInput
                {
                    AuthKey              = baseAuthInput.AuthKey,
                    Timestamp            = baseAuthInput.Timestamp,
                    AppSecret            = npsAppSecret.AppSecret,
                    IsConfigConnectAllow = input.IsConfigConnectAllow.ToInt32OrDefault(1),
                    IsCompress           = input.IsCompress.ToInt32OrDefault(0),
                    IsCrypt              = input.IsCrypt.ToInt32OrDefault(1),
                    Remark = input.Remark
                });

                if (remoteApiResult.Status == 1)
                {//远程添加成功后,将数据写入本地Nps客户端表中
                    npsAppSecret.NpsClient = await _npsClientRepository.InsertAsync(new NpsClient
                    {
                        Id = npsAppSecret.Id,
                        IsConfigConnectAllow = input.IsConfigConnectAllow,
                        IsCompress           = input.IsCompress,
                        IsCrypt = input.IsCrypt,
                        Remark  = input.Remark
                    });
                }
                else
                {
                    throw new NpsException(remoteApiResult.Message, StatusCode.Error);
                }
            }

            return(npsAppSecret);
        }
示例#2
0
        public async Task NpsClientTest()
        {
            var authCpryKey = await _npsApi.AuthKeyAsync();

            var serverTime = await _npsApi.ServerTimeAsync();

            var authKey = Infrastructure.Helpers.EncryptHelper.Md5By32($"jyioself2020{serverTime.Timestamp}").ToLower();

            var clients = await _npsApi.ClientListAsync(new Application.NpsApi.Dtos.ClientListInput
            {
                AuthKey   = authKey,
                Timestamp = serverTime.Timestamp,
                KeyWords  = "",//ux5zk6i9jbguetvc可根据唯一验证密钥查询
                OrderType = "asc",
                Offset    = "0",
                Limit     = "10"
            });

            serverTime = await _npsApi.ServerTimeAsync();

            authKey = Infrastructure.Helpers.EncryptHelper.Md5By32($"jyioself2020{serverTime.Timestamp}").ToLower();
            var client = await _npsApi.ClientAsync(new Application.NpsApi.Dtos.ClientIdInput
            {
                Id        = 2,
                AuthKey   = authKey,
                Timestamp = serverTime.Timestamp
            });

            serverTime = await _npsApi.ServerTimeAsync();

            authKey = Infrastructure.Helpers.EncryptHelper.Md5By32($"jyioself2020{serverTime.Timestamp}").ToLower();
            var appSecret = _guidGenerator.Create().ToString("N");

            var addClient = await _npsApi.AddClientAsync(new Application.NpsApi.Dtos.ClientAddInput
            {
                AuthKey   = authKey,
                Timestamp = serverTime.Timestamp,
                Remark    = $"测试添加客户端_{appSecret.Substring(0, 8)}",
                AppSecret = appSecret
            });

            serverTime = await _npsApi.ServerTimeAsync();

            authKey   = Infrastructure.Helpers.EncryptHelper.Md5By32($"jyioself2020{serverTime.Timestamp}").ToLower();
            appSecret = _guidGenerator.Create().ToString("N");

            var editClient = await _npsApi.EditClientAsync(new Application.NpsApi.Dtos.ClientEditInput
            {
                AuthKey   = authKey,
                Timestamp = serverTime.Timestamp,
                Id        = 7,
                Remark    = $"测试编辑客户端_{appSecret.Substring(0, 8)}",
                AppSecret = appSecret
            });

            serverTime = await _npsApi.ServerTimeAsync();

            authKey = Infrastructure.Helpers.EncryptHelper.Md5By32($"jyioself2020{serverTime.Timestamp}").ToLower();
            var deleteClient = await _npsApi.DeleteClientAsync(new Application.NpsApi.Dtos.ClientIdInput
            {
                AuthKey   = authKey,
                Timestamp = serverTime.Timestamp,
                Id        = 7
            });

            Assert.True(addClient.Status == 1);
            Assert.True(editClient.Status == 1);
            Assert.True(deleteClient.Status == 1);
        }